Example #1
1
 /**
  * Prepare the database connection instance.
  *
  * @param  \Illuminate\Database\Connection  $connection
  * @return \Illuminate\Database\Connection
  */
 protected function prepare(Connection $connection)
 {
     $connection->setFetchMode($this->app['config']['database.fetch']);
     if ($this->app->bound('events')) {
         $connection->setEventDispatcher($this->app['events']);
     }
     // The database connection can also utilize a cache manager instance when cache
     // functionality is used on queries, which provides an expressive interface
     // to caching both fluent queries and Eloquent queries that are executed.
     $app = $this->app;
     $connection->setCacheManager(function () use($app) {
         return $app['cache'];
     });
     // We will setup a Closure to resolve the paginator instance on the connection
     // since the Paginator isn't used on every request and needs quite a few of
     // our dependencies. It'll be more efficient to lazily resolve instances.
     $connection->setPaginator(function () use($app) {
         return $app['paginator'];
     });
     // Here we'll set a reconnector callback. This reconnector can be any callable
     // so we will set a Closure to reconnect from this manager with the name of
     // the connection, which will allow us to reconnect from the connections.
     $connection->setReconnector(function ($connection) {
         $this->reconnect($connection->getName());
     });
     return $connection;
 }
 public function testRegister()
 {
     $provider = new InlinerServiceProvider($this->app);
     $provider->register();
     $this->assertTrue($this->app->bound('Chromabits\\Illuminated\\Contracts\\Inliner\\StyleInliner'));
     $this->assertInstanceOf('Chromabits\\Illuminated\\Contracts\\Inliner\\StyleInliner', $this->app->make('Chromabits\\Illuminated\\Contracts\\Inliner\\StyleInliner'));
 }
Example #3
0
 /**
  * Determines if passed ReflectionParameter $parameter can be resolved from IoC.
  * If $parameter can be resolved and it's bound in IoC it's bound class/interface name
  * will be returned.
  *
  * @param ReflectionParameter $parameter
  * @param $reflectionKey
  * @param array $params
  * @return bool|string
  */
 protected function isResolvable(ReflectionParameter $parameter, $reflectionKey, $params = array())
 {
     /**
      * check if parameter available from $params with $reflectionKey key
      */
     if (array_key_exists($reflectionKey, $params)) {
         return false;
     }
     /**
      * check if $parameter has type
      */
     preg_match('/\\[\\s\\<\\w+?>\\s([\\w\\\\]+)/s', (string) $parameter, $matches);
     if (count($matches) < 1) {
         return false;
     }
     /**
      * check if $parameter type is not array and can be treated as class/interface
      */
     $canBeCreated = array_key_exists(1, $matches) && !$parameter->isArray() && is_string($matches[1]);
     /**
      * check if $parameter class/interface exists or it's been bound
      */
     $existsOrBound = class_exists($matches[1]) || $this->laraApp->bound($matches[1]);
     return $canBeCreated && $existsOrBound ? $matches[1] : false;
 }
Example #4
0
 /**
  * Prepare the database connection instance.
  *
  * @param  \KageNoNeko\OSM\ConnectionInterface $connection
  *
  * @return \KageNoNeko\OSM\ConnectionInterface
  */
 protected function prepare(ConnectionInterface $connection)
 {
     if ($this->app->bound('events')) {
         $connection->setEventDispatcher($this->app['events']);
     }
     return $connection;
 }
Example #5
0
 /**
  * Remember the socket for the given request.
  *
  * @param  \Illuminate\Http\Request|null  $request
  * @return void
  */
 public function rememberSocket($request = null)
 {
     if (!$request && !$this->app->bound('request')) {
         return;
     }
     $request = $request ?: $this->app['request'];
     $this->app['cache']->forever('pusher:socket:' . $request->session()->getId(), $request->socket_id);
 }
 /**
  * Get the socket ID for the given request.
  *
  * @param  \Illuminate\Http\Request|null  $request
  * @return string|null
  */
 public function socket($request = null)
 {
     if (!$request && !$this->app->bound('request')) {
         return;
     }
     $request = $request ?: $this->app['request'];
     if ($request->hasHeader('X-Socket-ID')) {
         return $request->header('X-Socket-ID');
     }
 }
Example #7
0
 /**
  * Load a single module by it's name.
  *
  * @param string $module
  * @throws InvalidSignatureException module does'nt implement the right interface
  * @throws ModuleNotFoundException module does'nt exists
  * @return bool
  */
 protected function enableModule($module)
 {
     $definition = $this->getFullyQualifiedModuleClassName($module) . '\\Module';
     if (!(class_exists($definition) || $this->app->bound($definition))) {
         throw new ModuleNotFoundException("Module {$definition} does'nt exist");
     }
     /** @var ModuleDefinitionContract $module */
     $module = $this->app->make($definition, [$this->app, $module]);
     if (!$module instanceof ModuleDefinitionContract) {
         throw new InvalidSignatureException("Class {$definition} must implements ModuleDefinition interface");
     }
     return $module->bootstrap();
 }
Example #8
0
 /**
  * Create a new cache repository with the given implementation.
  *
  * @param  \Illuminate\Contracts\Cache\Store  $store
  * @return \Illuminate\Cache\Repository
  */
 public function repository(Store $store)
 {
     $repository = new Repository($store);
     if ($this->app->bound('Illuminate\\Contracts\\Events\\Dispatcher')) {
         $repository->setEventDispatcher($this->app['Illuminate\\Contracts\\Events\\Dispatcher']);
     }
     return $repository;
 }
Example #9
0
 /**
  * Create a new auth extension.
  *
  * @param \Illuminate\Foundation\Application $app
  */
 public function __construct(Application $app)
 {
     if ($app->bound('debugbar')) {
         $this->debugbar = $app['debugbar'];
     } else {
         $this->debugbar = null;
     }
 }
Example #10
0
 /**
  * Prepare the database connection instance.
  *
  * @param  \Illuminate\Database\Connection  $connection
  * @return \Illuminate\Database\Connection
  */
 protected function prepare(Connection $connection)
 {
     $connection->setFetchMode($this->app['config']['database.fetch']);
     if ($this->app->bound('events')) {
         $connection->setEventDispatcher($this->app['events']);
     }
     // Here we'll set a reconnector callback. This reconnector can be any callable
     // so we will set a Closure to reconnect from this manager with the name of
     // the connection, which will allow us to reconnect from the connections.
     $connection->setReconnector(function ($connection) {
         $this->reconnect($connection->getName());
     });
     return $connection;
 }
Example #11
0
 /**
  * Prepare the database connection instance.
  *
  * @param  \LMongo\Connection  $connection
  * @return \LMongo\Connection
  */
 protected function prepare(Connection $connection)
 {
     if ($this->app->bound('events')) {
         $connection->setEventDispatcher($this->app['events']);
     }
     // The database connection can also utilize a cache manager instance when cache
     // functionality is used on queries, which provides an expressive interface
     // to caching both fluent queries and Eloquent queries that are executed.
     $app = $this->app;
     $connection->setCacheManager(function () use($app) {
         return $app['cache'];
     });
     // We will setup a Closure to resolve the paginator instance on the connection
     // since the Paginator isn't sued on every request and needs quite a few of
     // our dependencies. It'll be more efficient to lazily resolve instances.
     $connection->setPaginator(function () use($app) {
         return $app['paginator'];
     });
     return $connection;
 }
Example #12
0
 /**
  * Determine if the given abstract type has been bound.
  * 
  * (Overriding Container::bound)
  *
  * @param string $abstract
  * @return bool 
  * @static 
  */
 public static function bound($abstract)
 {
     return \Illuminate\Foundation\Application::bound($abstract);
 }
 /**
  * Modify the response and inject the debugbar (or data in headers)
  *
  * @param  \Symfony\Component\HttpFoundation\Request $request
  * @param  \Symfony\Component\HttpFoundation\Response $response
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function modifyResponse(Request $request, Response $response)
 {
     $app = $this->app;
     if ($app->runningInConsole() || !$this->isEnabled() || $this->isDebugbarRequest()) {
         return $response;
     }
     // Show the Http Response Exception in the Debugbar, when available
     if (isset($response->exception)) {
         $this->addThrowable($response->exception);
     }
     if ($this->shouldCollect('config', false)) {
         try {
             $configCollector = new ConfigCollector();
             $configCollector->setData($app['config']->all());
             $this->addCollector($configCollector);
         } catch (\Exception $e) {
             $this->addThrowable(new Exception('Cannot add ConfigCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($this->app->bound(SessionManager::class)) {
         /** @var \Illuminate\Session\SessionManager $sessionManager */
         $sessionManager = $app->make(SessionManager::class);
         $httpDriver = new SymfonyHttpDriver($sessionManager, $response);
         $this->setHttpDriver($httpDriver);
         if ($this->shouldCollect('session') && !$this->hasCollector('session')) {
             try {
                 $this->addCollector(new SessionCollector($sessionManager));
             } catch (\Exception $e) {
                 $this->addThrowable(new Exception('Cannot add SessionCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
             }
         }
     } else {
         $sessionManager = null;
     }
     if ($this->shouldCollect('symfony_request', true) && !$this->hasCollector('request')) {
         try {
             $this->addCollector(new SymfonyRequestCollector($request, $response, $sessionManager));
         } catch (\Exception $e) {
             $this->addThrowable(new Exception('Cannot add SymfonyRequestCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
     }
     if ($app['config']->get('debugbar.clockwork') && !$this->hasCollector('clockwork')) {
         try {
             $this->addCollector(new ClockworkCollector($request, $response, $sessionManager));
         } catch (\Exception $e) {
             $this->addThrowable(new Exception('Cannot add ClockworkCollector to Laravel Debugbar: ' . $e->getMessage(), $e->getCode(), $e));
         }
         $this->addClockworkHeaders($response);
     }
     if ($response->isRedirection()) {
         try {
             $this->stackData();
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($this->isJsonRequest($request) && $app['config']->get('debugbar.capture_ajax', true)) {
         try {
             $this->sendDataInHeaders(true);
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($response->headers->has('Content-Type') && strpos($response->headers->get('Content-Type'), 'html') === false || $request->getRequestFormat() !== 'html') {
         try {
             // Just collect + store data, don't inject it.
             $this->collect();
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     } elseif ($app['config']->get('debugbar.inject', true)) {
         try {
             $this->injectDebugbar($response);
         } catch (\Exception $e) {
             $app['log']->error('Debugbar exception: ' . $e->getMessage());
         }
     }
     return $response;
 }
Example #14
0
 /**
  * Determine if the given abstract type has been bound.
  *
  * @param string $abstract
  * @return bool 
  * @static 
  */
 public static function bound($abstract)
 {
     //Method inherited from \Illuminate\Container\Container
     return \Illuminate\Foundation\Application::bound($abstract);
 }