Example #1
0
 public function registerGitService(Application $app)
 {
     $git = new GitService($app->get('blog.workdir'));
     $builder = new BuilderService($git);
     $app->getServices()->set('git', $git);
     $app->getServices()->set('builder', $builder);
 }
Example #2
0
 public function testPlugin()
 {
     $this->assertFalse(isset($this->object['PluginAction']));
     $this->assertFalse($this->object->getServices()->exists('pluginService'));
     $this->object->plugin(new MyTestPlugin());
     $this->assertTrue(isset($this->object['PluginAction']));
     $this->assertTrue($this->object->getServices()->exists('pluginService'));
 }
Example #3
0
 /**
  */
 protected function setUp()
 {
     $this->object = Application::factory('testApp')->addListener(new Components\RequestMatcher\RequestMatcherListener('requestMatcher'))->register('TestSimpleClosureAction', ProxyFactory::factory(function () {
         return "test";
     }))->register('TestClosureWithParams', ProxyFactory::factory(function ($name) {
         return "hello " . $name;
     }))->register('TestClosureResponse', ProxyFactory::factory(function () {
         return new RedirectResponse('http://www.example.org');
     }))->register('TestSimpleController', ProxyFactory::factory('Fwk\\Core\\TestController:show'))->register('TestHelloController', ProxyFactory::factory('Fwk\\Core\\HelloController:show'))->register('TestServiceClosure', ProxyFactory::factory('@actionService'))->register('TestServiceController', ProxyFactory::factory('@helloController:show'))->register('TestContextAwareClosure', ProxyFactory::factory(function ($context) {
         return $context;
     }))->register('TestServicesAwareClosure', ProxyFactory::factory(function ($services) {
         return $services;
     }));
     $this->object->getServices()->set('requestMatcher', new ClassDefinition('Fwk\\Core\\Components\\RequestMatcher\\RequestMatcher'), true);
     $this->object->getServices()->set('actionService', function () {
         return "testService";
     }, true);
     $this->object->getServices()->set('helloController', new ClassDefinition('Fwk\\Core\\HelloController'), true);
 }
Example #4
0
 /**
  *
  * @param string $result
  * @param Context $context
  * @param array $actionData
  * 
  * @return mixed
  * @throws Exception if no ResultType found for this result
  */
 public function execute($result, Context $context, Application $app, array $actionData = array())
 {
     $rule = $this->find($result, $context);
     if (false === $rule) {
         return $result;
     }
     $type = $this->getType($rule['typeName']);
     if ($type instanceof ContextAware) {
         $type->setContext($context);
     }
     if ($type instanceof ServicesAware) {
         $type->setServices($app->getServices());
     }
     if ($type instanceof ApplicationAware) {
         $type->setApplication($app);
     }
     return $type->getResponse($actionData, $rule['parameters']);
 }
 /**
  * Instanciates the controller class
  * 
  * @return mixed
  */
 protected function instantiate(Application $app)
 {
     return $app->getServices()->get($this->serviceName);
 }
 /**
  * Applies rules for ServicesAware, ContextAware and Preparable interfaces.
  * 
  * @param mixed       $instance Controller instance
  * @param Application $app      The running Application
  * @param Context     $context  Actual context
  * 
  * @return void
  */
 protected function populateCoreInterfaces($instance, Application $app, Context $context)
 {
     if ($instance instanceof ContextAware) {
         $instance->setContext($context);
     }
     if ($instance instanceof ServicesAware) {
         $instance->setServices($app->getServices());
     }
     if ($instance instanceof Preparable) {
         call_user_func(array($instance, Preparable::PREPARE_METHOD));
     }
 }
Example #7
0
 /**
  * Includes the PHP file and return the content.
  * 
  * @param Application $app     The running Application
  * @param Context     $context Actual context
  * 
  * @return mixed or void if the file doesn't end with a return statement
  * @throws Exception if the file is not readable/does not exist
  */
 public function execute(Application $app, Context $context)
 {
     if (!is_file($this->file) || !is_readable($this->file)) {
         throw new Exception('Unable to include file: ' . $this->file . ' (not found/readable)');
     }
     $this->context = $context;
     $this->services = $app->getServices();
     return include $this->file;
 }
Example #8
0
 /**
  * Executes the callable and returns the result
  * 
  * @param Application $app     The running Application
  * @param Context     $context Actual context
  * 
  * @return mixed The controller's result
  */
 public function execute(Application $app, Context $context)
 {
     if ($this->callable instanceof \Closure) {
         $refFunc = new \ReflectionFunction($this->callable);
         $params = array();
         $request = $context->getRequest();
         foreach ($refFunc->getParameters() as $param) {
             if ($param->getName() == self::PARAM_CONTEXT_NAME) {
                 $params[] = $context;
             } elseif ($param->getName() == self::PARAM_SERVICES_NAME) {
                 $params[] = $app->getServices();
             } else {
                 $params[] = $request->get($param->getName(), null);
             }
         }
         $result = call_user_func_array($this->callable, $params);
     } else {
         $result = call_user_func($this->callable);
     }
     if (is_array($result)) {
         $this->actionData = array_merge($result, $this->actionData);
     }
     return $result;
 }
Example #9
0
 /**
  * Executes the service and eventually return the result (if any) or an
  * instance.
  *  
  * @param Application $app     The running Application
  * @param Context     $context Actual context
  * 
  * @return mixed
  */
 public function execute(Application $app, Context $context)
 {
     $result = $app->getServices()->get($this->serviceName);
     if (is_array($result)) {
         $this->actionData = array_merge($result, $this->actionData);
     }
     return $result;
 }