for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Controller\User;
use App\Controller\BaseController;
use App\Service\UserService;
use Slim\Container;
/**
* Base User Controller.
*/
abstract class BaseUser extends BaseController
{
* @var UserService
protected $userService;
* @param Container $container
public function __construct(Container $container)
$this->container = $container;
container
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;
$this->logger = $container->get('logger');
}
* @return UserService
protected function getUserService()
return $this->container->get('user_service');
* @return array
protected function getInput()
return $this->request->getParsedBody();
protected function getRedisClient()
return $this->container->get('redis');
protected function saveInCache($id, $result)
$redis = $this->getRedisClient();
$key = 'api-rest-slimphp:user:'.$id;
$redis->set($key, json_encode($result));
protected function deleteFromCache($id)
$redis->del($key);
protected function getFromCache($id)
$value = $redis->get($key);
return json_decode($value);
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: