Esempio n. 1
0
 public function testGetResources()
 {
     $getDataSource = self::getMethod('getResources');
     // Get from the request
     $messages = new \Phruts\Util\PropertyMessageResources(__DIR__ . '/UtilTest/Example');
     $this->request->attributes->set(\Phruts\Util\Globals::MESSAGES_KEY, $messages);
     $result = $getDataSource->invokeArgs($this->action, array($this->request));
     $this->assertNotEmpty($result);
     // Get from the application
     $request = \Symfony\Component\HttpFoundation\Request::create('http://localhost/test', 'GET', array(), array(), array(), array('PATH_INFO' => '/test'));
     $application = new \Silex\Application();
     $application[\Phruts\Util\Globals::PREFIXES_KEY] = array();
     $moduleConfig = new \Phruts\Config\ModuleConfig('');
     $application[\Phruts\Util\Globals::MODULE_KEY] = $moduleConfig;
     \Phruts\Util\RequestUtils::selectModule($request, $application);
     $key = 'key';
     $application[$key] = $messages;
     $actionKernel = new \Phruts\Action\ActionKernel($application);
     $this->action->setActionKernel($actionKernel);
     $result = $getDataSource->invokeArgs($this->action, array($this->request, $key));
     $this->assertNotEmpty($result);
 }
Esempio n. 2
0
 public function execute(ActionMapping $mapping, AbstractActionForm $form = null, Request $request, Response $response)
 {
     // Identify the request parameters controlling our actions
     $page = $request->get("page");
     $prefix = $request->get("prefix");
     if ($page == null || $prefix == null) {
         $message = $this->getActionKernel()->getInternal()->getMessage("switch.required", $mapping->getPath());
         throw new \Phruts\Exception($message);
     }
     // Switch to the requested module
     \Phruts\Util\RequestUtils::selectModule($request, $this->getActionKernel()->getApplication());
     if ($request->attributes->get(\Phruts\Util\Globals::MODULE_KEY) == null) {
         $message = $this->getActionKernel()->getInternal()->getMessage("switch.prefix", $prefix);
         $response->setContent(400);
         $response->setContent($message);
         return null;
     }
     // Forward control to the specified module-relative URI
     $forward = new \Phruts\Config\ForwardConfig();
     $forward->setPath($page);
     return $forward;
 }
Esempio n. 3
0
 /**
  * Populate the properties of the specified ActionForm instance from
  * the request parameters included with this request.
  *
  * In addition, request attribute <samp>\Phruts\Util\Globals::CANCEL_KEY</samp> will be
  * set if the request was submitted with a cancel button.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The kernel request we are
  * processing
  * @param \Symfony\Component\HttpFoundation\Response $response The kernel response we are
  * creating
  * @param \Phruts\Action\AbstractActionForm $form The ActionForm instance we are
  * populating
  * @param \Phruts\Action\ActionMapping $mapping The ActionMapping we are using
  * @throws \Phruts\Exception - If thrown by \Phruts\Util\RequestUtils->populate()
  */
 protected function processPopulate(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\HttpFoundation\Response $response, \Phruts\Action\AbstractActionForm $form = null, \Phruts\Action\ActionMapping $mapping)
 {
     if (is_null($form)) {
         return;
     }
     // Populate the bean properties of this ActionForm instance
     if (!empty($this->log)) {
         $this->log->debug('  Populating bean properties from this request');
     }
     $form->setActionKernel($this->actionKernel);
     $form->reset($mapping, $request);
     try {
         \Phruts\Util\RequestUtils::populate($form, $mapping->getPrefix(), $mapping->getSuffix(), $request);
     } catch (\Phruts\Exception $e) {
         throw $e;
     }
     // Set the cancellation request attribute if appropriate
     if (!is_null($request->get(\Phruts\Util\Globals::CANCEL_PROPERTY))) {
         $request->attributes->set(\Phruts\Util\Globals::CANCEL_KEY, true);
     }
 }
Esempio n. 4
0
 /**
  * Return the specified or default (key = "") message resources for the
  * current module.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The actionKernel request we are
  * processing
  * @param string $key The key specified in the <message-resources> element
  * for the requested bundle
  * @return \Phruts\Util\MessageResources
  * module ($request = null).
  */
 protected function getResources(Request $request, $key = '')
 {
     if ($key == '') {
         return $request->attributes->get(\Phruts\Util\Globals::MESSAGES_KEY);
     } else {
         // Identify the current module
         $app = $this->actionKernel->getApplication();
         $moduleConfig = \Phruts\Util\RequestUtils::getModuleConfig($request, $app);
         // Return the requested message resources instance
         return $app[$key . $moduleConfig->getPrefix()];
     }
 }
Esempio n. 5
0
 /**
  * @param  Request  $request
  * @param $key
  * @return \Phruts\
  */
 public function getDataSource(Request $request, $key)
 {
     // Identify the current module
     $moduleConfig = \Phruts\Util\RequestUtils::getModuleConfig($request, $this->getApplication());
     // Return the requested data source instance
     $keyPrefixed = $key . $moduleConfig->getPrefix();
     $dataSource = $request->attributes->get($keyPrefixed);
     if (empty($dataSource)) {
         if (!array_key_exists($keyPrefixed, $this->dataSourceFactories)) {
             return null;
         }
         /** @var \Phruts\Util\DataSourceFactory $dsFactory */
         $dsFactory = $this->dataSourceFactories[$keyPrefixed];
         try {
             $dataSource = $dsFactory->createDataSource();
         } catch (\Exception $e) {
             throw $e;
         }
         $request->attributes->set($keyPrefixed, $dataSource);
     }
     return $dataSource;
 }