Exemplo n.º 1
0
 /**
  * Handle the exception.
  * Return the <code>ActionForward</code> instance (if any) returned by
  * the called <code>ExceptionHandler</code>.
  *
  * @param \Exception ex The exception to handle
  * @param \Phruts\Config\ExceptionConfig ae The ExceptionConfig corresponding to the exception
  * @param \Phruts\Action\ActionMapping mapping The ActionMapping we are processing
  * @param \Phruts\Action\AbstractActionForm formInstance The \Phruts\Action\AbstractActionForm we are processing
  * @param \Symfony\Component\HttpFoundation\Request request The actionKernel request we are processing
  * @param \Symfony\Component\HttpFoundation\Response response The actionKernel response we are creating
  * @return \Phruts\Config\ForwardConfig
  * @exception ActionKernelException if a actionKernel exception occurs
  *
  * @since Struts 1.1
  */
 public function execute(\Exception $ex, \Phruts\Config\ExceptionConfig $ae, \Phruts\Action\ActionMapping $mapping, \Phruts\Action\AbstractActionForm $formInstance = null, \Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\HttpFoundation\Response $response)
 {
     $forward = null;
     //ActionForward
     $error = null;
     //\Phruts\Action\ActionError
     $property = null;
     //String
     // Build the forward from the exception mapping if it exists
     // or from the form input
     if ($ae->getPath() != null) {
         $forward = new \Phruts\Config\ForwardConfig();
         $forward->setPath($ae->getPath());
     } else {
         $forward = $mapping->getInputForward();
     }
     // Figure out the error
     if ($ex instanceof \Phruts\Util\ModuleException) {
         $error = $ex->getActionMessage();
         $property = $ex->getProperty();
     } else {
         $error = new \Phruts\Action\ActionError($ae->getKey(), $ex->getMessage());
         $property = $error->getKey();
     }
     // Store the exception
     $request->attributes->set(\Phruts\Util\Globals::EXCEPTION_KEY, $ex);
     $this->storeException($request, $property, $error, $forward, $ae->getScope());
     return $forward;
 }
Exemplo n.º 2
0
 public function testExecute()
 {
     // Add an exception config
     $exceptionConfig = new ExceptionConfig();
     $exceptionConfig->setPath('/exception.php');
     $exceptionConfig->setKey('example.exception');
     $exceptionConfig->setType('\\Exception');
     // Action Mapping
     $actionMapping = new ActionMapping();
     $actionMapping->setType('\\Phruts\\Actions\\ForwardAction');
     $actionMapping->addExceptionConfig($exceptionConfig);
     $actionMapping->setPath('throw');
     $formInstance = null;
     $request = new Request();
     $response = new Response();
     $forward = $this->exceptionHandler->execute(new \Exception('Example Error'), $exceptionConfig, $actionMapping, $formInstance, $request, $response);
     $this->assertTrue($forward instanceof \Phruts\Config\ForwardConfig);
 }
Exemplo n.º 3
0
 public function testModuleConfig()
 {
     $config = new ModuleConfig('prefix2');
     $this->assertEquals('prefix2', $config->getPrefix());
     $config->setPrefix('prefix');
     $this->assertEquals('prefix', $config->getPrefix());
     $controllerConfig = new ControllerConfig();
     $controllerConfig->setProcessorClass('\\Mock\\Proccessor');
     $controllerConfig->setContentType('application/x-javascript');
     $controllerConfig->setNocache('true');
     $controllerConfig->setInputForward('true');
     $controllerConfig->setLocale('true');
     $expected = "\\Phruts\\Config\\ControllerConfig[processorClass='\\\\Mock\\\\Proccessor',contentType='application/x-javascript',nocache=true,inputForward=true,locale=true]";
     $this->assertEquals($expected, (string) $controllerConfig);
     $config->setControllerConfig($controllerConfig);
     $this->assertNotEmpty($config->getControllerConfig());
     $actionConfig1 = new ActionConfig();
     $actionConfig1->setPath('action1');
     $actionConfig1->setType('\\ForwardConfig');
     $config->addActionConfig($actionConfig1);
     $actionConfig2 = new ActionConfig();
     $actionConfig2->setPath('action2');
     $actionConfig2->setType('\\ForwardConfig');
     $config->addActionConfig($actionConfig2);
     $this->assertNotEmpty($config->findActionConfig('/action1'));
     $this->assertNotEmpty($config->findActionConfig('/action2'));
     $config->removeActionConfig($actionConfig2);
     $this->assertEmpty($config->findActionConfig('/action2'));
     $actionClass = '\\MyActionConfigClass';
     $config->setActionClass($actionClass);
     $this->assertEquals('\\MyActionConfigClass', $config->getActionClass());
     $formBeanConfig1 = new FormBeanConfig();
     $formBeanConfig1->setName('myForm1');
     $formBeanConfig1->setType('\\MyForm1');
     $formBeanConfig2 = new FormBeanConfig();
     $formBeanConfig2->setName('myForm2');
     $formBeanConfig2->setType('\\MyForm2');
     $config->addFormBeanConfig($formBeanConfig1);
     $config->addFormBeanConfig($formBeanConfig2);
     $this->assertEquals(2, count($config->findFormBeanConfigs()));
     $this->assertEquals($formBeanConfig1, $config->findFormBeanConfig('myForm1'));
     $this->assertEquals($formBeanConfig2, $config->findFormBeanConfig('myForm2'));
     $config->removeFormBeanConfig($formBeanConfig2);
     $this->assertEmpty($config->findFormBeanConfig('myForm2'));
     $forwardConfig1 = new ForwardConfig();
     $forwardConfig1->setName('welcome');
     $forwardConfig1->setPath('welcome.html.twig');
     $forwardConfig2 = new ForwardConfig();
     $forwardConfig2->setName('login');
     $forwardConfig1->setPath('login.html.twig');
     $config->addForwardConfig($forwardConfig1);
     $config->addForwardConfig($forwardConfig2);
     $this->assertEquals($forwardConfig1, $config->findForwardConfig('welcome'));
     $this->assertEquals($forwardConfig2, $config->findForwardConfig('login'));
     $config->removeForwardConfig($forwardConfig1);
     $this->assertEmpty($config->findForwardConfig('welcome'));
     $dataSourceConfig = new DataSourceConfig();
     $dataSourceConfig->setKey('key1');
     $config->addDataSourceConfig($dataSourceConfig);
     $dataSourceConfig2 = new DataSourceConfig();
     $dataSourceConfig2->setKey('key2');
     $config->addDataSourceConfig($dataSourceConfig2);
     $this->assertEquals(2, count($config->findDataSourceConfigs()));
     $this->assertEquals($dataSourceConfig, $config->findDataSourceConfig('key1'));
     $this->assertEquals($dataSourceConfig2, $config->findDataSourceConfig('key2'));
     $config->removeDataSourceConfig($dataSourceConfig);
     $this->assertEmpty($config->findDataSourceConfig('key1'));
     $messageConfig = new MessageResourcesConfig();
     $messageConfig->setKey('key1');
     $config->addMessageResourcesConfig($messageConfig);
     $this->assertEquals($messageConfig, $config->findMessageResourcesConfig('key1'));
     $this->assertEquals(1, count($config->findMessageResourcesConfigs()));
     $config->removeMessageResourcesConfig($messageConfig);
     $this->assertEmpty($config->findMessageResourcesConfig('key1'));
     $plugInConfig = new PlugInConfig();
     $plugInConfig->setKey('test');
     $plugInConfig->setClassName('\\stdClass');
     $config->addPlugInConfig($plugInConfig);
     $this->assertEquals(1, count($config->findPlugInConfigs()));
     $exceptionConfig = new ExceptionConfig();
     $exceptionConfig->setType('\\Exception');
     $config->addExceptionConfig($exceptionConfig);
     $this->assertEquals(1, count($config->findExceptionConfigs()));
     $this->assertEquals($exceptionConfig, $config->findExceptionConfig('\\Exception'));
     $config->removeExceptionConfig($exceptionConfig);
     $this->assertEmpty($config->findExceptionConfig('\\Exception'));
     // Test exception
     $config->freeze();
     $this->assertTrue($config->getConfigured());
     $this->setExpectedException('\\Phruts\\Exception\\IllegalStateException');
     $config->setPrefix('prefix2');
 }
Exemplo n.º 4
0
 /**
  * Remove the specified exception configuration instance.
  *
  * @param config ExceptionConfig instance to be removed
  *
  * @exception \Phruts\Exception\IllegalState if this module configuration
  *  has been frozen
  */
 public function removeExceptionConfig(\Phruts\Config\ExceptionConfig $config)
 {
     if ($this->configured) {
         throw new \Phruts\Exception\IllegalStateException("Configuration is frozen");
     }
     unset($this->exceptions[$config->getType()]);
 }