public function givenIConfigureTheProviderFor_ToInjectAnyArgument($class) { $provider = new DefaultProvider($this->factory); $provider->setParameterFilter(function () { return true; }); $this->factory->setProvider($class, $provider); }
public function setUp() { parent::setUp(); $this->boxes = array(); $this->request = new WebRequest(Url::fromString(''), new Path(), 'get'); $this->factory = new Factory(); $this->store = new MemoryStore(); /** @noinspection PhpUnusedParameterInspection */ $this->factory->setProvider(RawFileStore::$CLASS, new CallbackProvider(function ($class, $args) { return new FileStoreAdapter($this->store, $args['rootDirectory']); })); }
/** * Creates a Factory with MockProvider set as default Provider * * @param callable $configureMockProvider Receives the MockProvider to be configured * @return Factory */ public static function createFactory(callable $configureMockProvider = null) { $factory = new Factory(); $provider = new MockProvider($factory); if ($configureMockProvider) { $configureMockProvider($provider); } $factory->setProvider('StdClass', $provider); return $factory; }
public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); $factory = new Factory(); $this->fixtureProvider = new FixtureProvider($this, $factory); $factory->setProvider(Fixture::$CLASS, $this->fixtureProvider); $injector = new Injector($factory); $injector->injectPropertyAnnotations($this, array($this, 'annotationPropertyFilter')); $this->setTimeZone(); }
/** * @param $name * @throws \BadMethodCallException If the method does not exist * @return mixed */ protected function invoke($name) { try { $reflection = new \ReflectionMethod($this->object, $name); } catch (\ReflectionException $e) { $class = get_class($this->object); throw new \BadMethodCallException("Method [{$name}] does not exist in [{$class}]"); } $this->factory->setProvider(Request::$REQUEST_CLASS, new CallbackProvider(function () { return $this->request; })); $analyzer = new MethodAnalyzer($reflection); $arguments = $this->request->getArguments()->toArray(); $arguments = $this->filter($analyzer, $arguments); $factory = $this->factory; $arguments = $analyzer->fillParameters($arguments, function ($class) use($factory) { return $factory->getInstance($class); }, $this->parameterInjectionFilter); return $reflection->invokeArgs($this->object, $arguments); }