Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 /**
  * Adds Actions and Listeners to the Application
  *
  * @param Application $app The running Application
  *
  * @return void
  */
 public function load(Application $app)
 {
     $app->register('PageView', ProxyFactory::factory('Nitronet\\Fwk\\CMF\\Controllers\\PageView:show'));
     $console = $this->cfg('consoleService', false);
     if ($console) {
         $app->addListener(new CommandsListener($this->cfg('consoleService', 'console'), $this->cfg('serviceName', 'cmf')));
     }
 }
Ejemplo n.º 3
0
 /**
  *
  * @param array $actionData
  * @param array $params
  * 
  * @return Response
  */
 public function getResponse(array $actionData = array(), array $params = array())
 {
     $actionName = isset($params['actionName']) ? $params['actionName'] : null;
     unset($params['actionName']);
     if (null === $actionName) {
         throw new Exception('Missing ResultType parameter "actionName"');
     }
     $this->context->setActionName($actionName);
     foreach ($params as $key => $value) {
         if (!empty($value) && strpos($value, ':', 0) !== false && array_key_exists(substr($value, 1), $actionData)) {
             $value = $actionData[substr($value, 1)];
         }
         $this->context->getRequest()->query->set($key, $value);
     }
     return $this->application->runAction($this->context);
 }
Ejemplo n.º 4
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'));
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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']);
 }
Ejemplo n.º 7
0
 public function testDirectResponse()
 {
     $rsp = new \Symfony\Component\HttpFoundation\Response();
     $this->object->register('TestDirectResponse', ProxyFactory::factory(function () use($rsp) {
         return $rsp;
     }));
     $request = Request::create('/TestDirectResponse.action');
     $response = $this->object->run($request);
     $this->assertEquals($rsp, $response);
 }
Ejemplo n.º 8
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $service = new UrlRewriterService();
     $service->addRoutes(array(new Route('TestAction', '/test/:result', array(new RouteParameter('result'))), new Route('Unknown', '/bad/action')));
     $app = \Fwk\Core\Application::factory('testApp')->addListener(new \Fwk\Core\Components\RequestMatcher\RequestMatcherListener('requestMatcher'))->addListener(new UrlRewriterListener('urlRewriter'));
     $app['TestAction'] = function ($result) {
         return $result;
     };
     $app->getServices()->set('requestMatcher', new ClassDefinition('Fwk\\Core\\Components\\RequestMatcher\\RequestMatcher'), true);
     $app->getServices()->set('urlRewriter', $service, true);
     $this->object = $app;
 }
Ejemplo n.º 9
0
 public function testWrongService()
 {
     $service = new ViewHelperService();
     $service->add('test', new TestHelper2());
     $app = \Fwk\Core\Application::factory('testApp')->addListener(new \Fwk\Core\Components\RequestMatcher\RequestMatcherListener('requestMatcher'))->addListener(new ViewHelperListener('requestMatcher'));
     $app['TestAction'] = '+' . TEST_RESOURCES_DIR . DIRECTORY_SEPARATOR . 'viewhelper_template.php';
     $app->getServices()->set('requestMatcher', new \Fwk\Core\Components\RequestMatcher\RequestMatcher(), true);
     $app->getServices()->set('viewHelperService', $service, true);
     $this->object = $app;
     $req = Request::create('/TestAction.action');
     $this->setExpectedException('Fwk\\Core\\Components\\ViewHelper\\Exception');
     $this->object->run($req);
 }
Ejemplo n.º 10
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $service = new ResultTypeService();
     $service->addType('json', new JsonResultType());
     $service->addType('php', new PhpTemplateResultType(array('templatesDir' => TEST_RESOURCES_DIR)));
     $service->addType('redirect', new RedirectResultType());
     $service->register('TestAction', \Fwk\Core\Action\Result::SUCCESS, 'json');
     $service->register('TestAction', \Fwk\Core\Action\Result::REDIRECT, 'redirect', array('uri' => '/'));
     $service->register('TestAction', 'template', 'php', array('file' => 'phptemplate_resulttype.php'));
     $app = \Fwk\Core\Application::factory('testApp')->addListener(new \Fwk\Core\Components\RequestMatcher\RequestMatcherListener('requestMatcher'))->addListener(new ResultTypeListener('resultTypeService'));
     $app['TestAction'] = function ($result) {
         return $result;
     };
     $app['TestActionObj'] = function () {
         return new \stdClass();
     };
     $app->getServices()->set('requestMatcher', new ClassDefinition('Fwk\\Core\\Components\\RequestMatcher\\RequestMatcher'), true);
     $app->getServices()->set('resultTypeService', $service, true);
     $this->object = $app;
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
0
 /**
  * @return Application
  */
 public function execute($appName, Container $services = null)
 {
     $this->sources = array_reverse($this->sources);
     $app = Application::factory($appName, $services);
     if (null === $services) {
         $services = $app->getServices();
     }
     $app->addListener(new DescriptorListener($this));
     $this->loadIniFiles();
     $this->loadServices($services);
     foreach ($this->loadListeners($services) as $listener) {
         $app->addListener($listener);
     }
     foreach ($this->loadPlugins($services) as $plugin) {
         $app->plugin($plugin);
     }
     foreach ($this->loadActions() as $actionName => $str) {
         $app->register($actionName, ProxyFactory::factory($str));
     }
     return $app;
 }
Ejemplo n.º 13
0
 /**
  * Returns a list of Actions for this plugin
  *
  * @param Application $app The running Application
  *
  * @return void
  */
 public function load(Application $app)
 {
     $app->addListener(new RequestMatcherListener(self::SERVICE_NAME));
 }
Ejemplo n.º 14
0
 /**
  * Returns a list of Actions for this plugin
  *
  * @param Application $app The running Application
  *
  * @return void
  */
 public function load(Application $app)
 {
     $app->addListener(new UrlRewriterListener(self::SERVICE_NAME));
 }
Ejemplo n.º 15
0
 protected function getApp()
 {
     return \Fwk\Core\Application::factory('testApp');
 }
Ejemplo n.º 16
0
 /**
  * Adds Actions and Listeners to the Application
  *
  * @param Application $app The running Application
  *
  * @return void
  */
 public function load(Application $app)
 {
     $app->register('CommentsThread', PF::factory('Nitronet\\Fwk\\Comments\\Controllers\\Thread:show'));
     $app->register('CommentsCount', PF::factory('Nitronet\\Fwk\\Comments\\Controllers\\Thread:countComments'));
     $app->register('CommentPost', PF::factory('Nitronet\\Fwk\\Comments\\Controllers\\Comment:post'));
 }
Ejemplo n.º 17
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;
 }
Ejemplo n.º 18
0
 public function testChainResultType()
 {
     $req = Request::create('/HomeChain.action');
     $result = $this->app->run($req);
     $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\JsonResponse', $result);
 }
Ejemplo n.º 19
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Fwk\Core\Application, Fwk\Core\Descriptor;
$desc = new Descriptor(__DIR__ . '/../Nitronet/fwk.xml');
$app = new Application($desc);
$app->run(\Symfony\Component\HttpFoundation\Request::createFromGlobals());
Ejemplo n.º 20
0
 /**
  * Returns a list of Actions for this plugin
  *
  * @param Application $app The running Application
  *
  * @return void
  */
 public function load(Application $app)
 {
     $app->addListener(new ViewHelperListener(self::SERVICE_NAME));
 }
Ejemplo n.º 21
0
 /**
  * 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));
     }
 }
Ejemplo n.º 22
0
 public function load(Application $app)
 {
     $app->register($this->cfg('action', 'Asset'), PF::factory($this->cfg('controller', 'Nitronet\\Fwk\\Assetic\\Controllers\\AssetAction:show')));
 }
Ejemplo n.º 23
0
 public function testRoutesFromDescriptor()
 {
     $req = Request::create('/hello/joe');
     $result = $this->app->run($req);
     $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\JsonResponse', $result);
 }
Ejemplo n.º 24
0
 /**
  * Instanciates the controller class
  * 
  * @return mixed
  */
 protected function instantiate(Application $app)
 {
     return $app->getServices()->get($this->serviceName);
 }
Ejemplo n.º 25
0
 /**
  * Returns a list of Actions for this plugin
  *
  * @param Application $app The running Application
  *
  * @return void
  */
 public function load(Application $app)
 {
     $app->addListener(new ResultTypeListener(self::SERVICE_NAME));
 }