コード例 #1
0
ファイル: FactoryFixture.php プロジェクト: watoki/factory
 public function givenIConfigureTheProviderFor_ToInjectAnyArgument($class)
 {
     $provider = new DefaultProvider($this->factory);
     $provider->setParameterFilter(function () {
         return true;
     });
     $this->factory->setProvider($class, $provider);
 }
コード例 #2
0
ファイル: BoxFixture.php プロジェクト: watoki/boxes
 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']);
     }));
 }
コード例 #3
0
ファイル: Mockster.php プロジェクト: rtens/mockster
 /**
  * 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;
 }
コード例 #4
0
ファイル: Specification.php プロジェクト: watoki/scrut
 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();
 }
コード例 #5
0
ファイル: ObjectTarget.php プロジェクト: watoki/deli
 /**
  * @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);
 }