public function __construct(Container $c) { $this->view = $c->get('view'); $this->logger = $c->get('logger'); $this->flash = $c->get('flash'); $this->em = $c->get('em'); }
public function __construct(\Slim\Container $container) { $this->logger = $container->get('logger'); $this->view = $container->get('view'); $this->request = $container->request; $this->response = $container->response; }
/** * Test settings can be edited */ public function testSettingsCanBeEdited() { $c = new Container(); $this->assertSame('1.1', $c->get('settings')['httpVersion']); $c->get('settings')['httpVersion'] = '1.2'; $this->assertSame('1.2', $c->get('settings')['httpVersion']); }
/** * @param ServerRequestInterface $request * @param Response $response * @param callable $next * @return Response */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { $authContainer = $this->container->get('auth-container'); if ($authContainer->user == null) { $response = $response->withRedirect($this->container->router->pathFor('home')); } else { $response = $next($request, $response); } return $response; }
/** * Call \Slim\Container callable name * * @param string $method Container Name * @return mixed * @throws \BadMethodCallException */ public function __call($method, $params) { if ($this->container->has($method)) { $obj = $this->container->get($method); if (is_callable($obj)) { return call_user_func_array($obj, $params); } } throw new BadMethodCallException("Method {$method} is not a valid method"); }
public function __construct(Container $c) { $this->view = $c->get('view'); $this->logger = $c->get('logger'); $this->flash = $c->get('flash'); $this->validator = $c->get('validator'); $this->currentUser = $c->get('current_user'); $this->currentCompany = $c->get('current_company'); $this->userRepository = $c->get('user_repository'); $this->companyRepository = $c->get('company_repository'); $this->addressRepository = $c->get('address_repository'); }
/** * Create Controller\Base instance * * @param Container $container */ public function __construct(Container $container) { $this->container = $container; $this->setPageTitle(); $this->view->addData(['gcaptchaSitekey' => null, 'gcaptchaSecret' => null, 'gcaptchaEnable' => false], 'sections::captcha'); $this->view->addData(['session' => $container->get('session')->all()]); }
/** * @covers Jgut\Slim\Controller\Resolver::resolve */ public function testDefaultRegistration() { $controllers = ['Jgut\\Slim\\Controller\\Base']; $container = new Container(); foreach (Resolver::resolve($controllers) as $controller => $callback) { $container[$controller] = $callback; } $this->assertInstanceOf('Jgut\\Slim\\Controller\\Base', $container->get('Jgut\\Slim\\Controller\\Base')); }
/** * Renders the given template path, and returns the resultant HTTP response. * * @param string $path - The path to the template to be rendered. * @param array $data - The data to pass into the template. * * @return Response */ public function rendered($path, array $data) { // Format path. $path = $this->container->get('settings')['templatePath'] . DIRECTORY_SEPARATOR . $path; $path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); $path .= '.blade.php'; $response = $this->container['response']; /* @var Response $response */ $response->getBody()->write($this->factory->file($path, $data)->render()); return $response; }
public function __construct(Container $container) { $this->view = $container->get('view'); $this->logger = $container->get('logger'); $this->pdo = $container->get('pdo'); $this->flash = $container->get('flash'); $this->mailer = $container->get('mailer'); $this->router = $container->get('router'); $this->userManager = $container->get('userManager'); }
public function __construct(\Slim\Container $container) { $this->view = $container->get('view'); $this->router = $container->get('router'); $this->logger = $container->get('logger'); $this->settings = $container->get('settings'); $this->session = $container->get('session'); $this->facebook = $container->get('facebook'); $this->quiz = $container->get('quiz'); $this->viewData = array(); $this->viewData['permissions'] = json_encode($this->settings["facebook-permissions"]); $this->viewData['settings'] = $this->settings; $this->viewData['theme'] = 'starwars'; $this->viewData['version'] = 1; }
/** * Register Slim's default services. * * @param Container $container A DI container implementing ArrayAccess and container-interop. */ public function register($container) { if (!isset($container['environment'])) { /** * This service MUST return a shared instance * of \Slim\Interfaces\Http\EnvironmentInterface. * * @return EnvironmentInterface */ $container['environment'] = function () { return new Environment($_SERVER); }; } if (!isset($container['request'])) { /** * PSR-7 Request object * * @param Container $container * * @return ServerRequestInterface */ $container['request'] = function ($container) { return Request::createFromEnvironment($container->get('environment')); }; } if (!isset($container['response'])) { /** * PSR-7 Response object * * @param Container $container * * @return ResponseInterface */ $container['response'] = function ($container) { $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']); $response = new Response(200, $headers); return $response->withProtocolVersion($container->get('settings')['httpVersion']); }; } if (!isset($container['router'])) { /** * This service MUST return a SHARED instance * of \Slim\Interfaces\RouterInterface. * * @return RouterInterface */ $container['router'] = function () { return new Router(); }; } if (!isset($container['foundHandler'])) { /** * This service MUST return a SHARED instance * of \Slim\Interfaces\InvocationStrategyInterface. * * @return InvocationStrategyInterface */ $container['foundHandler'] = function () { return new RequestResponse(); }; } if (!isset($container['phpErrorHandler'])) { /** * This service MUST return a callable * that accepts three arguments: * * 1. Instance of \Psr\Http\Message\ServerRequestInterface * 2. Instance of \Psr\Http\Message\ResponseInterface * 3. Instance of \Error * * The callable MUST return an instance of * \Psr\Http\Message\ResponseInterface. * * @param Container $container * * @return callable */ $container['phpErrorHandler'] = function ($container) { return new PhpError($container->get('settings')['displayErrorDetails']); }; } if (!isset($container['errorHandler'])) { /** * This service MUST return a callable * that accepts three arguments: * * 1. Instance of \Psr\Http\Message\ServerRequestInterface * 2. Instance of \Psr\Http\Message\ResponseInterface * 3. Instance of \Exception * * The callable MUST return an instance of * \Psr\Http\Message\ResponseInterface. * * @param Container $container * * @return callable */ $container['errorHandler'] = function ($container) { return new Error($container->get('settings')['displayErrorDetails']); }; } if (!isset($container['notFoundHandler'])) { /** * This service MUST return a callable * that accepts two arguments: * * 1. Instance of \Psr\Http\Message\ServerRequestInterface * 2. Instance of \Psr\Http\Message\ResponseInterface * * The callable MUST return an instance of * \Psr\Http\Message\ResponseInterface. * * @return callable */ $container['notFoundHandler'] = function () { return new NotFound(); }; } if (!isset($container['notAllowedHandler'])) { /** * This service MUST return a callable * that accepts three arguments: * * 1. Instance of \Psr\Http\Message\ServerRequestInterface * 2. Instance of \Psr\Http\Message\ResponseInterface * 3. Array of allowed HTTP methods * * The callable MUST return an instance of * \Psr\Http\Message\ResponseInterface. * * @return callable */ $container['notAllowedHandler'] = function () { return new NotAllowed(); }; } if (!isset($container['callableResolver'])) { /** * Instance of \Slim\Interfaces\CallableResolverInterface * * @param Container $container * * @return CallableResolverInterface */ $container['callableResolver'] = function ($container) { return new CallableResolver($container); }; } }
public function __construct(Container $container) { $this->db = $container->get('pdo'); }
/** * @return mixed */ public function __get($var) { return $this->container->get($var); }
public function __construct(Container $container) { $this->app = $container; $this->DB = $container->get('capsule'); $this->logger = $container->get('logger'); }
public function __construct(Container $c) { $this->router = $c->get('router'); $this->view = $c->get('view'); }
public function __construct(Container $c) { $this->renderer = $c->get('renderer'); $this->logger = $c->get('logger'); $this->db = $c->get('db'); }
/** * Test `get()` throws error if item does not exist * * @expectedException \Slim\Exception\NotFoundException */ public function testGetWithError() { $c = new Container(); $c->get('foo'); }
use BB8\Emoji\Database\Connection; use BB8\Emoji\Database\Schema; use BB8\Emoji\Middleware; use BB8\Emoji\Models\User; //Create connection to database $connection = new Connection(); //Creaet database tables if table does not exist Schema::createSchema(); //Initialize a new dependency container $container = new Container(); //Add container to handle all exceptions/errors, fail safe and return json $container['errorHandler'] = function ($container) { return function ($request, $response, $exception) use($container) { //Format of exception to return $data = ['message' => $exception->getMessage()]; return $container->get('response')->withStatus(500)->withHeader('Content-Type', 'application/json')->write(json_encode($data)); }; }; //Register authentication container Dependency $container['auth'] = function ($container) { return new BB8\Emoji\Auth($container); }; //Initialize the slim app $app = new App($container); //Add middleware at app level $app->add('BB8\\Emoji\\Middleware:init'); //Index page $app->get('/', 'BB8\\Emoji\\Controllers\\UserController:index'); //Create new user $app->post('/signup', 'BB8\\Emoji\\Controllers\\UserController:create'); //Login Route
/** * Get \Slim\Container name * * @param string $name Container Name * @return mixed * @throws \Slim\Exception\ContainerValueNotFoundException */ public function __get($name) { return $this->container->get($name); }
/** * @param Container $container */ public function __construct(Container $container) { $this->view = $container->get('view'); }
public function __construct(Container $container) { $this->container = $container; $this->db = $container->get('db'); }
* * @return \SLim\Interfaces\CollectionInterface */ $container['session'] = function ($container) { if (!isset($_SESSION['MembershipAuth'])) { $_SESSION['MembershipAuth'] = []; } return new Collection($_SESSION['MembershipAuth']); }; /** * Setup database container * * @return \Slim\PDO\Database */ $container['db'] = function ($container) { $db = $container->get('settings')['db']; if (!isset($db['dsn'])) { $db['dsn'] = sprintf('%s:host=%s;dbname=%s', $db['driver'], $db['host'], $db['dbname']); } return new Database($db['dsn'], $db['username'], $db['password']); }; /** * Setup data model container * * @return callable */ $container['data'] = function ($container) { $db = $container->get('db'); $session = $container->get('session'); return function ($class) use($db, $session) { if (!class_exists($class)) {
public function __construct(Container $container) { $this->view = $container->get('view'); $this->logger = $container->get('logger'); $this->dm = $container->get('dm'); }