Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
geggleto committed Sep 13, 2016
1 parent a92d5c4 commit 8d7b620
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
composer.lock
.idea/
.idea/
tests/form.php
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ $container['loginForm'] = function ($c) {
], 'Sign In');
};

//Build Dynamic Form
$app->get('/login', function ($req, $res, $args) {
return $res->write($this->loginForm->render());
});

```


Expand Down Expand Up @@ -245,8 +250,20 @@ $form2 = $generator->generate([
```


### Write forms to Local files
`composer persist <input form array> <output file>`

Example:
`composer persist ./tests/array.php ./tests/form.php`

the composer command is an alias for:
`php src/command/persistForm.php`




## Todo

### v1 goals
- [X] Figure out a way to populate select options for the generator

- [X] Add command line composer command to render an array to a file
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"test": [
"@phpunit"
],
"phpunit": "phpunit --bootstrap tests/bootstrap.php tests"
"phpunit": "phpunit --bootstrap tests/bootstrap.php tests",
"persist" : "php src/command/persistForm.php"
}
}
25 changes: 25 additions & 0 deletions src/Command/persistForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: Glenn
* Date: 2016-09-13
* Time: 11:15 AM
*/
use Geggleto\Forms\Generator\Generator;
use Geggleto\Forms\Factory\Bootstrap\Factory;

include_once __DIR__ . "/../../vendor/autoload.php";

if ($argc != 3) {
print "Usage : composer persist path/To/Form/Array.php path/to/output.php";
}

$formArray = include $argv[1];

$generator = new Generator(new Factory());

$form2 = $generator->generate($formArray, 'Sign In');

$fh = fopen($argv[2], "w");
fwrite($fh, $form2->render());
fclose($fh);
38 changes: 38 additions & 0 deletions tests/array.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Created by PhpStorm.
* User: Glenn
* Date: 2016-09-13
* Time: 11:21 AM
*/

return [
[
'label' => 'Email',
'type' => 'email',
'id' => 'inputEmail3',
'placeholder' => 'Email'
],
[
'label' => 'Password',
'type' => 'password',
'id' => 'inputPassword3',
'placeholder' => 'Password'
],
[
'label' => 'testSelect',
'type' => 'select',
'id' => 'select4',
'placeholder' => '',
'options' => [
[
'name' => 'one',
'value' => 1
],
[
'name' => 'two',
'value' => 2
],
]
]
];

0 comments on commit 8d7b620

Please sign in to comment.