/**
  * Setup the IoC container instance.
  *
  * @param  \Illuminate\Container\Container|null  $container
  * @return void
  */
 protected function setupContainer($container)
 {
     $this->container = $container ?: new Container();
     if (!$this->container->bound('config')) {
         $this->container->instance('config', new Fluent());
     }
 }
Exemplo n.º 2
0
 /**
  * Call the given controller instance method.
  *
  * @param  \Illuminate\Routing\Controller  $instance
  * @param  \Illuminate\Routing\Route  $route
  * @param  \Illuminate\Http\Request  $request
  * @param  string  $method
  * @return mixed
  */
 protected function callWithinStack($instance, $route, $request, $method)
 {
     $middleware = $this->getMiddleware($instance, $method);
     $shouldSkipMiddleware = $this->container->bound('middleware.disable') && $this->container->make('middleware.disable') === true;
     return (new Pipeline($this->container))->send($request)->through($shouldSkipMiddleware ? [] : $middleware)->then(function ($request) use($instance, $route, $method) {
         return $this->router->prepareResponse($request, $this->call($instance, $route, $method));
     });
 }
Exemplo n.º 3
0
 /**
  * @param string $name
  * @param Router $router
  * @return mixed
  */
 public function getAdapter($name, Router $router)
 {
     $alias = static::CONTAINER_ADAPTER_PREFIX . $name;
     $this->validateAdapter($name);
     if (false === $this->container->bound($alias)) {
         $this->bindAdapter($name);
     }
     return $this->container->make($alias, [$router]);
 }
Exemplo n.º 4
0
 /**
  * Ensure the base event and file bindings are present. Required for binding anything else.
  *
  * @param  Container  $app
  * @return void
  */
 public function ensureIlluminateBase(Container $app = null)
 {
     if (!$app->bound('events')) {
         $app->singleton('events', $this->illuminateClasses['events']);
         $app['events']->fire('booting');
     }
     if (!$app->bound('files')) {
         $app->bindIf('files', $this->illuminateClasses['files']);
     }
 }
Exemplo n.º 5
0
 /**
  * Call the given controller instance method.
  *
  * @param  \Illuminate\Routing\Controller  $instance
  * @param  \Illuminate\Routing\Route  $route
  * @param  \Illuminate\Http\Request  $request
  * @param  string  $method
  * @return mixed
  */
 protected function callWithinStack($instance, $route, $request, $method)
 {
     $middleware = $this->getMiddleware($instance, $method);
     $shouldSkipMiddleware = $this->container->bound('middleware.disable') && $this->container->make('middleware.disable') === true;
     // Here we will make a stack onion instance to execute this request in, which gives
     // us the ability to define middlewares on controllers.
     return (new Pipeline($this->container))->send($request)->through($shouldSkipMiddleware ? [] : $middleware)->then(function ($request) use($instance, $route, $method) {
         return $this->router->prepareResponse($request, $this->call($instance, $route, $method));
     });
 }
 /**
  * @test
  */
 public function it_should_not_affect_parent_container()
 {
     $this->parent->instance('a', 1);
     $this->local->instance('a', 2);
     $this->local->instance('b', 3);
     $this->assertTrue($this->parent->bound('a'));
     $this->assertEquals(1, $this->parent->make('a'));
     $this->assertFalse($this->parent->bound('b'));
     $this->assertEquals(2, $this->local->make('a'));
     $this->assertEquals(3, $this->local->make('b'));
 }
Exemplo n.º 7
0
 /**
  * Store contents in the cache.
  *
  * @param string $content The content to store
  *
  * @return bool
  */
 public function storeCache($content)
 {
     if (!$content) {
         return false;
     }
     // Log caching
     if ($this->app->bound('log')) {
         $this->app['log']->info('Caching page ' . $this->hash);
     }
     // Add page to cached pages
     $cached = array_merge($this->getCachedPages(), [$this->hash]);
     $this->app['flatten.storage']->set('cached', $cached);
     return $this->app['cache']->put($this->hash, $this->formatContent($content), $this->getLifetime());
 }
Exemplo n.º 8
0
 /**
  * Store contents in the cache
  *
  * @param string $content The content to store
  *
  * @return boolean
  */
 public function storeCache($content)
 {
     if (!$content) {
         return false;
     }
     // Log caching
     if ($this->app->bound('log')) {
         $this->app['log']->info('Caching page ' . $this->hash);
     }
     // Add page to cached pages
     $cached = array_merge($this->getCachedPages(), array($this->hash));
     $this->app['flatten.storage']->set('cached', $cached);
     // Add timestamp to cache
     $content .= PHP_EOL . '<!-- cached on ' . date('Y-m-d H:i:s') . ' -->';
     return $this->app['cache']->put($this->hash, $content, $this->getLifetime());
 }
Exemplo n.º 9
0
 /**
  * Resolve the given type from the container.
  *
  * @param string $abstract
  * @param array  $parameters
  *
  * @throws NotFoundException
  * @return mixed
  */
 public function get($abstract, array $parameters = [])
 {
     if (!$this->delegate->bound($abstract)) {
         throw NotFoundException::notBound($abstract);
     }
     return $this->delegate->make($abstract, $parameters);
 }
Exemplo n.º 10
0
 /**
  * Find the method of a route by its _uses or name
  *
  * @param  string $name
  *
  * @return string
  */
 protected function findRouteMethod($name)
 {
     if (!$this->app->bound('router')) {
         return;
     }
     // Get string by name
     if (!Str::contains($name, '@')) {
         $routes = $this->app['router']->getRoutes();
         $route = method_exists($routes, 'getByName') ? $routes->getByName($name) : $routes->get($name);
         // Get string by uses
     } else {
         foreach ($this->app['router']->getRoutes() as $route) {
             $routeUses = method_exists($route, 'getOption') ? $route->getOption('_uses') : array_get($route->getAction(), 'controller');
             if ($action = $routeUses) {
                 if ($action == $name) {
                     break;
                 }
             }
         }
     }
     // Get method
     $methods = method_exists($route, 'getMethods') ? $route->getMethods() : $route->methods();
     $method = array_get($methods, 0);
     return $method;
 }
Exemplo n.º 11
0
 /**
  * Run the given route within a Stack "onion" instance.
  *
  * @param  \Illuminate\Routing\Route  $route
  * @param  \Illuminate\Http\Request  $request
  * @return mixed
  */
 protected function runRouteWithinStack(Route $route, Request $request)
 {
     $shouldSkipMiddleware = $this->container->bound('middleware.disable') && $this->container->make('middleware.disable') === true;
     $middleware = $shouldSkipMiddleware ? [] : $this->gatherRouteMiddleware($route);
     return (new Pipeline($this->container))->send($request)->through($middleware)->then(function ($request) use($route) {
         return $this->prepareResponse($request, $route->run($request));
     });
 }
Exemplo n.º 12
0
 /**
  * Resolve a controller from the container.
  *
  * @param string $class
  *
  * @return \Illuminate\Routing\Controller
  */
 protected function resolveController($class)
 {
     $controller = $this->container->make($class);
     if (!$this->container->bound($class)) {
         $this->container->instance($class, $controller);
     }
     return $controller;
 }
Exemplo n.º 13
0
Arquivo: Router.php Projeto: dingo/api
 /**
  * Register a resource controller.
  *
  * @param string $name
  * @param string $controller
  * @param array  $options
  *
  * @return void
  */
 public function resource($name, $controller, array $options = [])
 {
     if ($this->container->bound(ResourceRegistrar::class)) {
         $registrar = $this->container->make(ResourceRegistrar::class);
     } else {
         $registrar = new ResourceRegistrar($this);
     }
     $registrar->register($name, $controller, $options);
 }
Exemplo n.º 14
0
Arquivo: Router.php Projeto: jrean/api
 /**
  * Register a resource controller.
  *
  * @param string $name
  * @param string $controller
  * @param array  $options
  *
  * @return void
  */
 public function resource($name, $controller, array $options = [])
 {
     if ($this->container->bound('Dingo\\Api\\Routing\\ResourceRegistrar')) {
         $registrar = $this->container->make('Dingo\\Api\\Routing\\ResourceRegistrar');
     } else {
         $registrar = new ResourceRegistrar($this);
     }
     $registrar->register($name, $controller, $options);
 }
 /**
  * Route a resource to a controller.
  *
  * @param  string  $name
  * @param  string  $controller
  * @param  array   $options
  * @return void
  */
 public function resource($name, $controller, array $options = array())
 {
     if ($this->container && $this->container->bound('Illuminate\\Routing\\ResourceRegistrar')) {
         $registrar = $this->container->make('Illuminate\\Routing\\ResourceRegistrar');
     } else {
         $registrar = new ResourceRegistrar($this);
     }
     $registrar->register($name, $controller, $options);
 }
 /**
  * Resolve the given type from the container.
  *
  * @param  string $abstract
  * @param  array $parameters
  * @return mixed
  */
 public function make($abstract, array $parameters = [])
 {
     if (parent::bound($abstract)) {
         return parent::make($abstract, $parameters);
     } elseif ($this->parentContainer->bound($abstract)) {
         return $this->parentContainer->make($abstract, $parameters);
     } else {
         return parent::make($abstract, $parameters);
     }
 }
Exemplo n.º 17
0
 /**
  * Change the repository in use
  *
  * @param string $filename
  * @param string $storage
  */
 public function setRepository($filename, $storage = null)
 {
     // Create personal storage if necessary
     if (!$this->app->bound('path.storage')) {
         $storage = $this->app['rocketeer.rocketeer']->getRocketeerConfigFolder();
         $this->app['files']->makeDirectory($storage, 0755, false, true);
     }
     // Get path to storage
     $storage = $storage ?: $this->app['path.storage'] . DS . 'meta';
     $this->repository = $storage . DS . $filename . '.json';
 }
Exemplo n.º 18
0
 /**
  * Get path to the storage folder
  *
  * @return string
  */
 protected function getStoragePath()
 {
     // If no path is bound, default to the Rocketeer folder
     if (!$this->app->bound('path.storage')) {
         return '.rocketeer';
     }
     // Unify slashes
     $storage = $this->app['path.storage'];
     $storage = $this->unifySlashes($storage);
     $storage = str_replace($this->getBasePath(), null, $storage);
     return $storage;
 }
Exemplo n.º 19
0
 /**
  * Mock Request
  *
  * @return Mockery
  */
 protected function mockRequest($segment = 'fr')
 {
     $request = Mockery::mock('Illuminate\\Http\\Request');
     $request->shouldIgnoreMissing();
     $request->server = Mockery::mock('server')->shouldIgnoreMissing();
     $request->shouldReceive('getBaseUrl')->andReturn($segment . '/foobar');
     $request->shouldReceive('segment')->andReturn($segment);
     if ($this->app->bound('polyglot.url')) {
         $this->app['polyglot.url']->setRequest($request);
     }
     return $request;
 }
Exemplo n.º 20
0
 /**
  * Bind the core classes to the Container
  *
  * @param  Container $app
  *
  * @return Container
  */
 public function bindCoreClasses(Container $app)
 {
     // Cancel if in the scope of a Laravel application
     if ($app->bound('events')) {
         return $app;
     }
     // Core classes
     //////////////////////////////////////////////////////////////////
     $app->bindIf('files', 'Illuminate\\Filesystem\\Filesystem');
     $app->bindIf('url', 'Illuminate\\Routing\\UrlGenerator');
     // Session and request
     //////////////////////////////////////////////////////////////////
     $app->bindIf('session.manager', function ($app) {
         return new SessionManager($app);
     });
     $app->bindIf('session', function ($app) {
         return $app['session.manager']->driver('array');
     }, true);
     $app->bindIf('request', function ($app) {
         $request = Request::createFromGlobals();
         if (method_exists($request, 'setSessionStore')) {
             $request->setSessionStore($app['session']);
         } else {
             $request->setSession($app['session']);
         }
         return $request;
     }, true);
     // Config
     //////////////////////////////////////////////////////////////////
     $app->bindIf('path.config', function ($app) {
         dd(__DIR__ . '/../config/');
         return __DIR__ . '/../config/';
     }, true);
     $app->bindIf('config', function ($app) {
         $config = new Repository();
         $this->loadConfigurationFiles($app, $config);
         return $config;
     }, true);
     // Localization
     //////////////////////////////////////////////////////////////////
     $app->bindIf('translation.loader', function ($app) {
         return new FileLoader($app['files'], 'src/config');
     });
     $app->bindIf('translator', function ($app) {
         $loader = new FileLoader($app['files'], 'lang');
         return new Translator($loader, 'fr');
     });
     return $app;
 }
Exemplo n.º 21
0
 /**
  * Opens a group
  *
  * @return string Opening tag
  */
 public function open()
 {
     if ($this->getErrors()) {
         $this->state($this->app['former.framework']->errorState());
     }
     // Retrieve state and append it to classes
     if ($this->state) {
         $this->addClass($this->state);
     }
     // Required state
     if ($this->app->bound('former.field') and $this->app['former.field']->isRequired()) {
         $this->addClass($this->app['former']->getOption('required_class'));
     }
     return parent::open();
 }
Exemplo n.º 22
0
 /**
  * Set up a Field instance
  *
  * @param string $type A field type
  */
 public function __construct(Container $app, $type, $name, $label, $value, $attributes)
 {
     // Set base parameters
     $this->app = $app;
     $this->type = $type;
     $this->value = $value;
     $this->setAttributes($attributes);
     $this->form = $this->app->bound('former.form') ? $this->app['former.form'] : null;
     // Compute and translate label
     $this->automaticLabels($name, $label);
     // Repopulate field
     if ($type != 'password') {
         $this->value = $this->repopulate();
     }
     // Apply Live validation rules
     if ($this->app['former']->getOption('live_validation')) {
         $rules = new LiveValidation($this);
         $rules->apply($this->getRules());
     }
     // Bind the Group class
     $groupClass = $this->isCheckable() ? 'CheckableGroup' : 'Group';
     $groupClass = Former::FORMSPACE . $groupClass;
     $this->group = new $groupClass($this->app, $this->label);
 }
Exemplo n.º 23
0
 /**
  * Create a new connection instance.
  *
  * @param  string   $driver
  * @param  \PDO     $connection
  * @param  string   $database
  * @param  string   $prefix
  * @param  array    $config
  * @return \Illuminate\Database\Connection
  *
  * @throws \InvalidArgumentException
  */
 protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array())
 {
     if ($this->container->bound($key = "db.connection.{$driver}")) {
         return $this->container->make($key, array($connection, $database, $prefix, $config));
     }
     switch ($driver) {
         case 'mysql':
             return new MySqlConnection($connection, $database, $prefix, $config);
         case 'pgsql':
             return new PostgresConnection($connection, $database, $prefix, $config);
         case 'sqlite':
             return new SQLiteConnection($connection, $database, $prefix, $config);
         case 'sqlsrv':
             return new SqlServerConnection($connection, $database, $prefix, $config);
     }
     throw new \InvalidArgumentException("Unsupported driver [{$driver}]");
 }
Exemplo n.º 24
0
 /**
  * Closes a form
  *
  * @return string A form closing tag
  */
 public function close()
 {
     if ($this->app->bound('form.form')) {
         $closing = $this->app['form.form']->close();
     }
     // Destroy instances
     $instances = array('form.form', 'form.form.framework');
     foreach ($instances as $instance) {
         $this->app[$instance] = null;
         unset($this->app[$instance]);
     }
     // Reset populator
     $this->app['form.populator']->reset();
     // Reset all values
     $this->errors = null;
     $this->rules = array();
     return isset($closing) ? $closing : null;
 }
Exemplo n.º 25
0
 /**
  * Bind the core classes
  *
  * @param  Container $app
  *
  * @return Container
  */
 public function bindCoreClasses(Container $app)
 {
     if ($app->bound('events')) {
         return $app;
     }
     $app->bindIf('request', function ($app) {
         return Request::createFromGlobals();
     });
     $app->bindIf('url', function ($app) {
         $routes = new RouteCollection();
         return new UrlGenerator($routes, $app['request']);
     });
     $app->bindIf('html', function ($app) {
         return new HtmlBuilder($app['url']);
     });
     $app->bindIf('path.public', function () {
         return realpath(__DIR__ . '/../../');
     });
     return $app;
 }
 /**
  * Bind the core classes
  *
  * @param  Container $app
  *
  * @return Container
  */
 public function bindCoreClasses(Container $app)
 {
     if ($app->bound('events')) {
         return $app;
     }
     $app->bindIf('files', 'Illuminate\\Filesystem\\Filesystem');
     $app->bindIf('request', function () {
         return Request::createFromGlobals();
     });
     $app->bindIf('config', function ($app) {
         $fileloader = new FileLoader($app['files'], __DIR__ . '/../config');
         return new Repository($fileloader, 'config');
     }, true);
     $app->bindIf('cache', function ($app) {
         return new FileStore($app['Filesystem'], __DIR__ . '/../../public');
     });
     $app->bindIf('url', function ($app) {
         $routeCollection = new RouteCollection();
         return new UrlGenerator($routeCollection, $app['request']);
     });
     return $app;
 }
Exemplo n.º 27
0
 /**
  * Determine if the given abstract type has been bound.
  *
  * (Overriding Container::bound)
  *
  * @param  string  $abstract
  * @return bool
  */
 public function bound($abstract)
 {
     return isset($this->deferredServices[$abstract]) || parent::bound($abstract);
 }
Exemplo n.º 28
0
 /**
  * Determine if a custom route dispatcher is bound in the container.
  *
  * @return bool
  */
 protected function customDispatcherIsBound()
 {
     return $this->container->bound('illuminate.route.dispatcher');
 }
Exemplo n.º 29
0
 /**
  * Report whether an abstract exists in the container.
  *
  * @param string $abstract
  *
  * @return bool
  */
 public function has($abstract)
 {
     return static::$container->bound($abstract);
 }
Exemplo n.º 30
0
 /**
  * Get the current cache manager instance.
  *
  * @return \Illuminate\Cache\Manager
  */
 public function getCacheManager()
 {
     if ($this->container->bound('cache')) {
         return $this->container['cache'];
     }
 }