Example #1
1
 /**
  * {@inheritdoc}
  */
 public function execute(ContainerInterface $app)
 {
     foreach ($this->commands as $command) {
         $this->console->add($app->create($command));
     }
     $this->console->run();
 }
 /**
  * {@inheritdoc}
  */
 public function register(ContainerInterface $app)
 {
     $app->closure(ValidatorFactory::class, function () {
         return validator();
     });
     $app->alias('validator', ValidatorFactory::class);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function register(ContainerInterface $app)
 {
     $app->closure(Dispatcher::class, function ($container) {
         return new Dispatcher($container);
     });
     $app->alias(DispatcherInterface::class, Dispatcher::class);
     $app->alias('event', Dispatcher::class);
 }
 public function boot(ContainerInterface $app)
 {
     if ($app->has(KernelInterface::class)) {
         $kernel = $app->get(KernelInterface::class);
         $kernel['commands'] = (require __DIR__ . '/../app/commands.php');
         $kernel['routes'] = (require __DIR__ . '/../app/routes.php');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function boot(ContainerInterface $app)
 {
     if ($app->has(KernelInterface::class)) {
         /** @var \Wandu\Foundation\Contracts\KernelInterface $kernel */
         $kernel = $app->get(KernelInterface::class);
         $kernel['commands'] = ['psysh' => PsyshCommand::class, 'install' => InstallCommand::class];
     }
 }
 public function register(ContainerInterface $app)
 {
     $app->closure(PheanstalkInterface::class, function ($app) {
         return new Pheanstalk(config('queue.host', '127.0.0.1'), config('queue.port', Pheanstalk::DEFAULT_PORT), config('queue.timeout'), config('queue.connect_persistent', false));
     });
     $app->bind(SerializerInterface::class, PhpSerializer::class);
     $app->bind(AdapterInterface::class, BeanstalkdAdapter::class);
 }
Example #7
0
 public function up()
 {
     require $this->fileInfo->__toString();
     $migrationName = $this->getName();
     $this->container->create($migrationName)->up();
     $this->adapter->initialize();
     $this->adapter->up($this->getId(), file_get_contents($this->fileInfo));
 }
Example #8
0
 public function register(ContainerInterface $app)
 {
     $app->bind(ClassLoaderInterface::class, WanduLoader::class);
     $app->closure(Dispatcher::class, function (ContainerInterface $app) {
         return new Dispatcher($app[ClassLoaderInterface::class], ['virtual_method_disabled' => false, 'cache_disabled' => $app['config']->get('router.cache_disabled', true), 'cache_file' => $app['config']->get('router.cache_file', null)]);
     });
     $app->alias('router', Dispatcher::class);
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function get(ContainerInterface $container)
 {
     $this->frozen = true;
     if ($this->factoryEnabled) {
         return $container->call($this->handler);
     }
     if (!isset($this->caching)) {
         $this->caching = $object = $container->call($this->handler);
     }
     return $this->caching;
 }
Example #10
0
 public function register(ContainerInterface $app)
 {
     $app->closure(Capsule::class, function (ContainerInterface $app) {
         $capsule = new Capsule();
         foreach ($app['config']->get('database.connections') as $name => $connection) {
             $capsule->addConnection($connection, $name);
         }
         return $capsule;
     });
     $app->alias('db', Capsule::class);
 }
Example #11
0
 public function register(ContainerInterface $app)
 {
     $app->closure(Logger::class, function (ContainerInterface $app) {
         $logger = new Logger('festiv');
         if ($app['config']->get('log.path')) {
             $logger->pushHandler(new StreamHandler($app['config']->get('log.path')));
         }
         return $logger;
     });
     $app->alias(LoggerInterface::class, Logger::class);
     $app->alias('log', Logger::class);
 }
 public function register(ContainerInterface $app)
 {
     $app->closure(Logger::class, function (ContainerInterface $app) {
         $logger = new Logger('wandu');
         if ($path = config('log.path')) {
             $logger->pushHandler(new StreamHandler(Foundation\path($path)));
         }
         return $logger;
     });
     $app->alias(LoggerInterface::class, Logger::class);
     $app->alias('log', Logger::class);
 }
Example #13
0
 /**
  * @param string $migrationId
  */
 public function down($migrationId)
 {
     if (!preg_match('/^\\d{6}_\\d{6}$/', $migrationId)) {
         throw new RuntimeException("invalid migration id. it must be like 000000_000000.");
     }
     $version = $this->adapter->version($migrationId);
     if (!$version) {
         throw new RuntimeException("this {$migrationId} is not already applied.");
     }
     $migrationName = $this->getMigrationClassFromSource($version['source']);
     $this->container->create($migrationName)->down();
     $this->adapter->down($migrationId);
 }
Example #14
0
 public function execute(ContainerInterface $app)
 {
     try {
         $app->inject($this->test);
     } catch (CannotInjectException $exception) {
         $propertyName = $exception->getProperty();
         $className = $exception->getClass();
         if (class_exists($className)) {
             $app->inject($this->test, [$propertyName => $app->create($className)]);
         } else {
             throw $exception;
         }
     }
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function register(ContainerInterface $app)
 {
     $app->closure(Engine::class, function () {
         $engine = new Engine();
         $engine->setLoader(new FileLoader());
         $cachePath = config('view.cache');
         if ($cachePath) {
             $engine->setTempDirectory(path($cachePath));
         }
         return $engine;
     });
     $app->closure(RenderInterface::class, function ($app) {
         return new LatteView($app[Engine::class], path(config('view.path')));
     });
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function register(ContainerInterface $app)
 {
     $app->closure(Twig_Environment::class, function () {
         $loader = new Twig_Loader_Filesystem(path(config('view.path')));
         $options = [];
         $cachePath = config('view.cache');
         if ($cachePath) {
             $options['cache'] = path($cachePath);
         }
         return new Twig_Environment($loader, $options);
     });
     $app->closure(RenderInterface::class, function ($app) {
         return new TwigView($app[Twig_Environment::class]);
     });
 }
Example #17
0
 public function register(ContainerInterface $app)
 {
     $app->bind(CookieJarFactory::class);
     $app->closure(SessionAdapterInterface::class, function (ContainerInterface $app) {
         switch ($app['config']->get('session.type')) {
             case "file":
                 return new FileAdapter($app['config']->get('session.path'), $app['config']->get('session.timeout', 7200));
             case "global":
                 return new GlobalAdapter();
             case "redis":
                 return new RedisAdapter(new Client($app['config']->get('session.path')), $app['config']->get('session.timeout', 7200));
         }
         throw new RuntimeException("unknown session type.");
     });
     $app->closure(SessionFactory::class, function (ContainerInterface $app) {
         return new SessionFactory($app[SessionAdapterInterface::class], ['timeout' => $app['config']->get('session.timeout', 7200), 'name' => $app['config']->get('session.name', "FestivSessId")]);
     });
 }
Example #18
0
 /**
  * {@inheritdoc}
  */
 public function register(ContainerInterface $app)
 {
     $app->closure(ResponseFactory::class, function () {
         return response();
         // singleton
     });
     $app->closure(SessionFactory::class, function ($app) {
         return new SessionFactory($app[SessionHandlerInterface::class], ['timeout' => config('session.timeout', 3600), 'name' => config('session.name', ini_get('session.name') ?: 'WdSessId'), 'gc_frequency' => config('session.gc_frequency', 100)]);
     });
     $app->closure(SessionHandlerInterface::class, function ($app) {
         switch (config('session.type')) {
             case 'file':
                 return new FileHandler(path(config('session.path', 'cache/sessions')));
             case 'redis':
                 return new RedisHandler($app[Client::class], config('session.timeout', 3600));
             default:
                 return new GlobalHandler();
         }
     });
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContainerInterface $app)
 {
     // @todo remove ErrorHandlerProvider
     // @todo add Error handler, and Whoops pretty when debug === true in Error Handler.
     $request = $app->get(ServerRequestFactory::class)->fromGlobals();
     try {
         $response = $this->dispatch($app->get('router'), $request);
         $app->get(ResponseSender::class)->sendToGlobal($response);
     } catch (Exception $exception) {
         if ($exception instanceof HttpException) {
             $httpException = $exception;
         } else {
             // if not HttpException and debug mode, exception will be prettify(by Whoops).
             if ($app['config']->get('debug', true)) {
                 throw $exception;
             }
             $httpException = new HttpException();
         }
         $handler = $app['config']->get('error.handler');
         if ($handler) {
             $response = $this->responsify($app->create($handler)->handle($request, $exception), $httpException);
         } else {
             $response = $httpException->toResponse();
         }
         // body is ''
         if (!$response->getBody()) {
             $body = $response->getReasonPhrase();
             $response = $response->withBody(new Stringstream($body));
         }
         $app->get(ResponseSender::class)->sendToGlobal($response);
     }
 }
Example #20
0
 public function register(ContainerInterface $app)
 {
     $app->bind(ServerRequestFactory::class);
     $app->bind(UploadedFileFactory::class);
     $app->bind(ResponseFactory::class);
     $app->bind(ResponseSender::class);
     $app->closure(Uploader::class, function (ContainerInterface $app) {
         return new Uploader($app['config']->get('file.upload'));
     });
 }
Example #21
0
 public function register(ContainerInterface $app)
 {
     $app->bind(ClassLoaderInterface::class, WanduLoader::class);
     $app->bind(ResponsifierInterface::class, WanduResponsifier::class);
     $app->closure(Configuration::class, function () {
         return new Configuration(['middleware' => config('router.middleware', [Parameterify::class, Sessionify::class]), 'virtual_method_enabled' => true, 'cache_disabled' => config('router.cache_disabled', true), 'cache_file' => path(config('router.cache_file', null))]);
     });
     $app->bind(Dispatcher::class);
     $app->alias('router', Dispatcher::class);
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function boot(ContainerInterface $app)
 {
     $app->instance(Config::class, new Config($this->definition->configs()));
     $app->alias(ConfigInterface::class, Config::class);
     $app->alias('config', Config::class);
     foreach ($this->definition->providers() as $provider) {
         $app->register($app->create($provider));
     }
     $this->app = $app;
 }
Example #23
0
 /**
  * @param \Wandu\DI\ContainerInterface $app
  * @return \Psr\Http\Message\ServerRequestInterface
  */
 protected function createRequest(ContainerInterface $app)
 {
     return $this->request = $app->get(ServerRequestFactory::class)->createFromGlobals();
 }
 /**
  * {@inheritdoc}
  */
 public function register(ContainerInterface $app)
 {
     $app->closure(Configuration::class, function () {
         return new Configuration(['connection' => config('database.migrator.connection'), 'table' => config('database.migrator.table'), 'path' => path(config('database.migrator.path'))]);
     });
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 public function register(ContainerInterface $app)
 {
     $app->closure(RenderInterface::class, function () {
         return new PhpView(path(config('view.path')));
     });
 }
Example #26
0
 public function equalSession(Session $session, SessionInterface $sessionInterface, ServerRequestInterface $request, ContainerInterface $container)
 {
     return $session === $sessionInterface && $session === $request->getAttribute('session') && $container->get('request') === $request && $container->get(ServerRequest::class) === $request && $container->get(ServerRequestInterface::class) === $request;
 }
Example #27
0
 public function register(ContainerInterface $app)
 {
     $app->closure(RenderInterface::class, function (ContainerInterface $app) {
         return new GreenTeaLatte($app['config']->get('view.path'), $app['config']->get('view.cache'));
     });
 }
Example #28
0
 public function register(ContainerInterface $app)
 {
     $app->bind('whoops', Run::class);
 }
 /**
  * {@inheritdoc}
  */
 public function boot(ContainerInterface $app)
 {
     $app->get(Manager::class)->setAsGlobal();
     $app->get(Manager::class)->bootEloquent();
 }
Example #30
0
 public function register(ContainerInterface $app)
 {
     $app->bind(CasterInterface::class, Caster::class);
 }