for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Admin\Action;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as RequestInterface;
use Zend\Http\PhpEnvironment\Request;
use Zend\Diactoros\Response\JsonResponse;
use UploadHelper\Upload;
/**
* Class ImageUploadAction.
*/
final class ImageUploadAction
{
* IndexAction constructor.
*
* @param Upload $upload template engine
public function __construct(Upload $upload)
$this->upload = $upload;
upload
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
* Executed when action is called.
* @param RequestInterface $request request
* @param Response $response response
* @param callable|null $next next middleware
* @return JsonResponse
public function __invoke(RequestInterface $request, Response $response, callable $next = null)
$data = $request->getParsedBody();
$data += (new Request())->getFiles()->toArray();
$imagePath = $this->upload->uploadImage($data, 'file');
return new JsonResponse(['location' => $imagePath]);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: