/**
  * 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());
     }
 }
 /**
  * @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'));
 }
 /**
  * Set up the tests
  */
 public function setUp()
 {
     date_default_timezone_set('Europe/London');
     // Create container
     $this->app = new Container();
     $provider = new EventServiceProvider($this->app);
     $provider->register();
     // Bind mocked instances into it
     $this->app['config'] = $this->mockConfig();
     $this->app->instance('request', $this->mockRequest());
     $this->app['translation.loader'] = Mockery::mock('Illuminate\\Translation\\FileLoader');
     $this->app->instance('Illuminate\\Container\\Container', $this->app);
 }
Example #4
0
 /**
  * Set up the tests
  *
  * @return void
  */
 public function setUp()
 {
     $this->app = new Container();
     // Laravel classes --------------------------------------------- /
     $this->app->instance('path.base', '/src');
     $this->app->instance('path', '/src/app');
     $this->app->instance('path.public', '/src/public');
     $this->app->instance('path.storage', '/src/app/storage');
     $this->app['files'] = new Filesystem();
     $this->app['config'] = $this->getConfig();
     // Trucker classes ------------------------------------------- /
     $serviceProvider = new TruckerServiceProvider($this->app);
     $this->app = $serviceProvider->bindClasses($this->app);
 }
Example #5
0
 /**
  * Load the external config files specified by the command line option.
  */
 protected function loadExternalConfig()
 {
     $config = new Repository(static::getDefaultConfig());
     $filesystem = new Filesystem();
     foreach ($this->getConfigFiles($filesystem) as $filename) {
         $this->output->writeln("<info>Reading config from <path>{$filename}</path></info>");
         if ($filesystem->extension($filename) == 'php') {
             $configValues = $filesystem->getRequire($filename);
         } else {
             $configValues = Yaml::parse($filesystem->get($filename));
         }
         $config->set(array_dot($configValues));
     }
     $this->container->instance('config', $config);
 }
Example #6
0
 /**
  * Set the route collection instance.
  *
  * @param  \Illuminate\Routing\RouteCollection  $routes
  * @return void
  */
 public function setRoutes(RouteCollection $routes)
 {
     foreach ($routes as $route) {
         $route->setRouter($this)->setContainer($this->container);
     }
     $this->routes = $routes;
     $this->container->instance('routes', $this->routes);
 }
Example #7
0
 /**
  * Dispatch a call to a registered macro
  *
  * @param  string $method       The macro's name
  * @param  array  $parameters   The macro's arguments
  *
  * @return mixed
  */
 public function toMacros($method, $parameters)
 {
     if (!$this->app['former']->hasMacro($method)) {
         return false;
     }
     // Get and format macro
     $callback = $this->app['former']->getMacro($method);
     if ($callback instanceof Closure) {
         return call_user_func_array($callback, $parameters);
     } elseif (!is_string($callback)) {
         return false;
     }
     // Get class and method
     list($class, $method) = explode('@', $callback);
     $this->app->instance('Illuminate\\Container\\Container', $this->app);
     return call_user_func_array(array($this->app->make($class), $method), $parameters);
 }
Example #8
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;
 }
 protected function createContainer()
 {
     $container = new Container();
     $container->instance('array_iterator', new \ArrayIterator(range(1, 5)));
     $container->bind('error', function () {
         throw new \RuntimeException();
     });
     return new LaravelContainerAdapter($container);
 }
Example #10
0
 /**
  * Set up the tests
  *
  * @return void
  */
 public function setUp()
 {
     $this->app = new Container();
     // Laravel classes --------------------------------------------- /
     $this->app->instance('path.base', '/src');
     $this->app->instance('path', '/src/app');
     $this->app->instance('path.public', '/src/public');
     $this->app->instance('path.storage', '/src/app/storage');
     $this->app['files'] = new Filesystem();
     $this->app['config'] = $this->getConfig();
     $this->app['remote'] = $this->getRemote();
     $this->app['artisan'] = $this->getArtisan();
     $this->app['rocketeer.command'] = $this->getCommand();
     // Rocketeer classes ------------------------------------------- /
     $serviceProvider = new RocketeerServiceProvider($this->app);
     $this->app = $serviceProvider->bindPaths($this->app);
     $this->app = $serviceProvider->bindCoreClasses($this->app);
     $this->app = $serviceProvider->bindClasses($this->app);
     $this->app = $serviceProvider->bindScm($this->app);
 }
Example #11
0
 protected function createApplicationContainer()
 {
     $this->app = new \Illuminate\Container\Container();
     $this->app->singleton('config', function () {
         return new \Illuminate\Config\Repository();
     });
     $this->app->instance('log', $log = new \Illuminate\Log\Writer(new \Monolog\Logger('testing')));
     $this->app->instance('Psr\\Log\\LoggerInterface', $log = new \Illuminate\Log\Writer(new \Monolog\Logger('testing')));
     $this->registerConfigure();
     $this->registerDatabase();
     $this->registerCache();
     $annotationConfiguration = new \Ytake\LaravelAspect\AnnotationConfiguration($this->app['config']->get('ytake-laravel-aop.annotation'));
     $annotationConfiguration->ignoredAnnotations();
     $this->app->singleton('aspect.manager', function ($app) {
         return new \Ytake\LaravelAspect\AspectManager($app);
     });
     $this->app->bind(\Illuminate\Container\Container::class, function () {
         return $this->app;
     });
     \Illuminate\Container\Container::setInstance($this->app);
 }
Example #12
0
 /**
  * Get the routes controller instance.
  *
  * @return mixed
  */
 public function getController()
 {
     if (!isset($this->action['uses']) || !is_string($this->action['uses'])) {
         return;
     } elseif (isset($this->controller)) {
         return $this->controller;
     }
     if (Str::contains($this->action['uses'], '@')) {
         list($controller, $this->method) = explode('@', $this->action['uses']);
         $this->container->instance($controller, $this->controller = $this->container->make($controller));
         return $this->controller;
     }
 }
Example #13
0
 public function testDispatchShouldCallAfterResolvingIfCommandNotQueued()
 {
     $container = new Container();
     $handler = m::mock('StdClass')->shouldIgnoreMissing();
     $handler->shouldReceive('after')->once();
     $container->instance('Handler', $handler);
     $dispatcher = new Dispatcher($container);
     $dispatcher->mapUsing(function () {
         return 'Handler@handle';
     });
     $dispatcher->dispatch(new BusDispatcherTestBasicCommand(), function ($handler) {
         $handler->after();
     });
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $app = new Container();
     $app->instance('config', new Repository());
     (new EventServiceProvider($app))->register();
     (new AmiServiceProvider($app))->register();
     $this->loop = $app[LoopInterface::class];
     $this->loop->nextTick(function () {
         if (!$this->running) {
             $this->loop->stop();
         }
     });
     $this->stream = $app[Stream::class];
     $this->events = $app['events'];
     $this->app = $app;
 }
Example #15
0
 /**
  * Bind paths to the configuration files
  *
  * @return void
  */
 protected function bindConfiguration()
 {
     $path = $this->getBasePath();
     $logs = $this->getStoragePath();
     // Prepare the paths to bind
     $paths = array('config' => '.rocketeer', 'events' => '.rocketeer/events', 'tasks' => '.rocketeer/tasks', 'logs' => $logs . '/logs');
     foreach ($paths as $key => $file) {
         $filename = $path . $file;
         // Check whether we provided a file or folder
         if (!is_dir($filename) and file_exists($filename . '.php')) {
             $filename .= '.php';
         }
         // Use configuration in current folder if none found
         $realpath = realpath('.') . '/' . $file;
         if (!file_exists($filename) and file_exists($realpath)) {
             $filename = $realpath;
         }
         $this->app->instance('path.rocketeer.' . $key, $filename);
     }
 }
Example #16
0
 /**
  * Acts as a router that redirects methods to all of Form classes
  *
  * @param  string $method     The method called
  * @param  array  $parameters An array of parameters
  *
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     // Dispatch to Form\Elements
     // Explicitly check false since closeGroup() may return an empty string
     if (($element = $this->dispatch->toElements($method, $parameters)) !== false) {
         return $element;
     }
     // Dispatch to Form\Form
     if ($form = $this->dispatch->toForm($method, $parameters)) {
         $this->app->instance('form.form', $form);
         return $this->app['form.form'];
     }
     // Dispatch to Form\Group
     if ($group = $this->dispatch->toGroup($method, $parameters)) {
         return $group;
     }
     // Dispatch to Form\Actions
     if ($actions = $this->dispatch->toActions($method, $parameters)) {
         return $actions;
     }
     // Dispatch to macros
     if ($macro = $this->dispatch->toMacros($method, $parameters)) {
         return $macro;
     }
     // Checking for any supplementary classes
     $classes = explode('_', $method);
     $method = array_pop($classes);
     // Dispatch to the different Form\Fields
     $framework = isset($this->app['form.form.framework']) ? $this->app['form.form.framework'] : $this->app['form.framework'];
     $field = $this->dispatch->toFields($method, $parameters);
     if ($field instanceof Field) {
         $field = $framework->getFieldClasses($field, $classes);
     }
     // Else bind field
     $this->app->instance('form.field', $field);
     return $this->app['form.field'];
 }
Example #17
0
 /**
  * Make a new controller instance through the container.
  *
  * @return \Illuminate\Routing\Controller|\Laravel\Lumen\Routing\Controller
  */
 protected function makeControllerInstance()
 {
     list($this->controllerClass, $this->controllerMethod) = explode('@', $this->action['uses']);
     $this->container->instance($this->controllerClass, $this->controller = $this->container->make($this->controllerClass));
     return $this->controller;
 }
Example #18
0
File: Router.php Project: jrean/api
 /**
  * Set the raw adapter routes.
  *
  * @param array $routes
  *
  * @return void
  */
 public function setAdapterRoutes(array $routes)
 {
     $this->adapter->setRoutes($routes);
     $this->container->instance('api.routes', $this->getRoutes());
 }
Example #19
0
 /**
  * Replace the request instance with the previous request instance.
  *
  * @return void
  */
 protected function replaceRequestInstance()
 {
     array_pop($this->requestStack);
     $this->container->instance('request', end($this->requestStack));
 }
Example #20
0
 /**
  * Set the cache manager to be used by connections.
  *
  * @param  \Illuminate\Cache\CacheManager  $cache
  * @return void
  */
 public function setCacheManager(CacheManager $cache)
 {
     $this->container->instance('cache', $cache);
 }
Example #21
0
<?php

/**
 *
 * Author: snake
 * Date: 15-7-22
 * Time: 上午11:14
 */
require __DIR__ . '/../vendor/autoload.php';
use Illuminate\Container\Container;
// 用法
$container = new Container();
$container->instance('app', $container);
// 构造函数自动注入
/**
 * @var Desktop $d
 */
//$d = $container->make('Desktop');
//$d->description();
// 绑定
// 把一个类起一个重命名
//$container->bind('SnakeBox',function(){
//    return new Box();
//});
//
///**
// * @var Box $b
// */
//$b = $container->make('SnakeBox');
//$b->description();
// 别名注入
Example #22
0
 /**
  * Associate an abstract with a concrete object.
  *
  * @param $abstract
  * @param $instance
  */
 public function instance($abstract, $instance)
 {
     static::$container->instance($abstract, $instance);
 }
Example #23
0
 /**
  * Replace the request instance with the previous request instance.
  *
  * @return void
  */
 protected function replaceRequestInstance()
 {
     array_pop($this->requestStack);
     $this->container->instance('request', end($this->requestStack));
     $this->router->setCurrentRequest($this->container['request']);
 }
Example #24
0
 /**
  * Register an existing instance as shared in the container.
  *
  * @param string $abstract
  * @param mixed  $instance
  */
 public function instance($abstract, $instance)
 {
     $this->delegate->instance($abstract, $instance);
 }