bluzphp /
skeleton
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * CRUD controller for POST method |
||
| 4 | * |
||
| 5 | * @category Application |
||
| 6 | * |
||
| 7 | * @author Anton Shevchuk |
||
| 8 | * @created 19.02.15 16:27 |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Application; |
||
| 12 | |||
| 13 | use Bluz\Crud\Table; |
||
|
0 ignored issues
–
show
|
|||
| 14 | use Bluz\Db\Exception\TableNotFoundException; |
||
|
0 ignored issues
–
show
The type
Bluz\Db\Exception\TableNotFoundException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 15 | use Bluz\Http\Exception\NotFoundException; |
||
|
0 ignored issues
–
show
The type
Bluz\Http\Exception\NotFoundException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 16 | use Bluz\Http\RequestMethod; |
||
|
0 ignored issues
–
show
The type
Bluz\Http\RequestMethod was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 17 | use Bluz\Proxy\Messages; |
||
|
0 ignored issues
–
show
The type
Bluz\Proxy\Messages was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 18 | use Bluz\Proxy\Request; |
||
|
0 ignored issues
–
show
The type
Bluz\Proxy\Request was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 19 | use Bluz\Validator\Exception\ValidatorException; |
||
|
0 ignored issues
–
show
The type
Bluz\Validator\Exception\ValidatorException was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 20 | |||
| 21 | /** |
||
| 22 | * @accept HTML |
||
| 23 | * @accept JSON |
||
| 24 | * @method POST |
||
| 25 | * |
||
| 26 | * @param Table $crud |
||
| 27 | * @param mixed $primary |
||
| 28 | * @param array $data |
||
| 29 | * |
||
| 30 | * @return array |
||
| 31 | * @throws TableNotFoundException |
||
| 32 | * @throws NotFoundException |
||
| 33 | */ |
||
| 34 | return function (Table $crud, $primary, $data) { |
||
| 35 | try { |
||
| 36 | // Unset empty primary key(s) |
||
| 37 | foreach ($primary as $key => $value) { |
||
| 38 | if (empty($value)) { |
||
| 39 | unset($data[$key]); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | // Result is Primary Key(s) |
||
| 44 | $result = $crud->createOne($data); |
||
| 45 | |||
| 46 | Messages::addSuccess('The record was successfully created'); |
||
| 47 | |||
| 48 | return [ |
||
| 49 | 'row' => $crud->readOne($result), |
||
| 50 | 1 | 'method' => RequestMethod::PUT |
|
| 51 | ]; |
||
| 52 | } catch (ValidatorException $e) { |
||
| 53 | $row = $crud->readOne(null); |
||
| 54 | $row->setFromArray($data); |
||
| 55 | |||
| 56 | return [ |
||
| 57 | 'row' => $row, |
||
| 58 | 'errors' => $e->getErrors(), |
||
| 59 | 'method' => Request::getMethod() |
||
| 60 | ]; |
||
| 61 | } |
||
| 62 | }; |
||
| 63 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths