set() public method

Define an object or a value in the container.
public set ( string $name, mixed | DI\Definition\Helper\DefinitionHelper $value )
$name string Entry name
$value mixed | DI\Definition\Helper\DefinitionHelper Value, use definition helpers to define objects
Beispiel #1
0
 /**
  * クライアントの準備
  * @return void
  */
 protected function boot()
 {
     $this->container->set('config', $this->config);
     $this->container->set('api', $this->container->get(QiitaAPIInterface::class));
     Model::setFactory($this->container);
     Model::setApi($this->container->get('api'));
 }
Beispiel #2
0
 protected function readyApiMock()
 {
     $this->apiMock = \Mockery::mock(QiitaAPIInterface::class);
     $this->container->set('api', $this->apiMock);
     $this->container->set(QiitaAPIInterface::class, $this->apiMock);
     Model::setApi($this->apiMock);
 }
 /**
  * Configure the engine and start it.
  *
  * Compute and register some information such as computed global configuration,
  * input, output etc to the DI container for easier access later to
  * lower level components.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return void
  */
 public function configAndStart(InputInterface $input, OutputInterface $output)
 {
     $startUpMsg = "\n" . "Starting the test run. Version ( " . Application::APP_VERSION . " )\n" . "Type character h for help when prompted for an input value.\n";
     $output->writeln($startUpMsg);
     $config = $this->configFactory->config($input, $output);
     $this->container->set('Box\\TestScribe\\Config\\GlobalComputedConfig', $config);
     App::Init($this->appInstance);
     $this->engine->start();
 }
 protected function createContainer()
 {
     $container = new Container();
     $container->set('array_iterator', new \ArrayIterator(range(1, 5)));
     $container->set('error', function () {
         throw new \RuntimeException();
     });
     return new PHPDIContainerAdapter($container);
 }
Beispiel #5
0
 /**
  * Приготовить ответ из вывода handler.
  *
  * @param null|string|Response $output
  * @return Response
  */
 protected function makeResponse($output)
 {
     /** @var Response $response */
     $response = $this->container->get(Response::class);
     if ($output instanceof Response) {
         $response = $output;
     } elseif (is_string($output)) {
         $response->setContent($output);
     }
     $this->container->set(Response::class, $response);
     return $response;
 }
 protected function registerMocks()
 {
     $parser = new PhpDocReader();
     $class = new ReflectionClass($this);
     $registeredNames = array();
     //Find every member that begins with "mock" or "spy"
     foreach ($class->getProperties() as $property) {
         if (strpos($property->name, 'mock') === 0 || strpos($property->name, 'spy') === 0) {
             if ($property->name == "mockObjects") {
                 //This is inherited from PHPUnit_Framework_TestCase and we can't mock it
                 continue;
             }
             //Use the type as the DI name
             $name = $parser->getPropertyType($property);
             //TODO: Check for duplicates
             //$this->DIContainer->getDefinitionManager()->getDefinition()
             $property->setAccessible(true);
             $this->DIContainer->set($name, $property->getValue($this));
         }
     }
 }
Beispiel #7
0
 public function build($env = null) : Application
 {
     $this->env = $env;
     $router = new FastRouteRouter();
     $finalHandler = new FinalHandler();
     $emitter = new EmitterStack();
     if ($this->useSAPIEmitter) {
         $emitter->push(new SapiEmitter());
     } else {
         $emitter->push(new PHPUnitEmitter());
     }
     foreach ($this->initScripts as $initScriptClassName) {
         $script = new $initScriptClassName();
         $script($this);
     }
     $app = new Application($router, $this->container, $finalHandler, $emitter);
     foreach ($this->initAppScripts as $initAppScriptClassName) {
         $script = new $initAppScriptClassName();
         $script($app);
     }
     $this->container->set(Application::class, $app);
     return $app;
 }
Beispiel #8
0
 /**
  * {@inheritdoc}
  */
 public function set($name, $value)
 {
     parent::set($name, $value);
     return $this;
 }
Beispiel #9
0
 public function setDemoStatus(Config $config)
 {
     $this->container->set(DemoStatus::class, $config->getDemo());
 }
Beispiel #10
0
 /**
  * Configure the application dispatcher.
  */
 private function configureDispatcher()
 {
     $dispatcher = new Dispatcher($this->container);
     $this->setDispatcher($dispatcher);
     $this->container->set('dispatcher', $dispatcher);
 }
Beispiel #11
0
 /**
  * @param $name
  * @param $value
  */
 public function set($name, $value)
 {
     $this->phpDiContainer->set($name, $value);
 }