Example #1
0
 public function testLoadClass()
 {
     $this->assertEquals('Action', \Phruts\Util\ClassLoader::loadClass('\\Phruts\\Action\\Action'), '\\Phruts\\Action\\Action');
     $this->setExpectedException('\\Phruts\\Exception\\ClassNotFoundException');
     \Phruts\Util\ClassLoader::loadClass('\\NonExistant\\Class');
     $this->setExpectedException('\\Phruts\\Exception\\IllegalArgumentException');
     \Phruts\Util\ClassLoader::loadClass('\\1');
 }
Example #2
0
 /**
  * Create (if necessary) and return a \Phruts\Action\AbstractActionForm instance appropriate
  * for this request.
  *
  * If no \Phruts\Action\AbstractActionForm instance is required, return null.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The actionKernel request we are
  * processing
  * @param \Phruts\Config\ActionConfig $mapping The action mapping for this request
  * @param \Phruts\Config\ModuleConfig $moduleConfig The configuration for this
  * module
  * @param \Phruts\Action\ActionKernel $actionKernel The action actionKernel
  * @return \Phruts\Action\AbstractActionForm Form instance associated with this
  * request
  */
 public static function createActionForm(\Symfony\Component\HttpFoundation\Request $request, \Phruts\Config\ActionConfig $mapping, \Phruts\Config\ModuleConfig $moduleConfig, \Phruts\Action\ActionKernel $kernel)
 {
     // Is there a form bean associated with this mapping?
     $attribute = $mapping->getAttribute();
     if (is_null($attribute)) {
         return null;
     }
     // Look up the form bean configuration information to use
     $name = $mapping->getName();
     $config = $moduleConfig->findFormBeanConfig($name);
     if (is_null($config)) {
         return null;
     }
     $instance = null;
     $session = null;
     if ($mapping->getScope() == 'request') {
         $instance = $request->attributes->get($attribute);
     } else {
         \Phruts\Util\ClassLoader::loadClass($config->getType());
         $session = $request->getSession();
         if (!empty($session)) {
             $instance = $session->get($attribute);
         }
     }
     // Can we recycle the existing form bean instance (if there is one)?
     if (!is_null($instance)) {
         $configClass = $config->getType();
         $instanceClass = get_class($instance);
         if (\Phruts\Util\ClassLoader::classIsAssignableFrom($configClass, $instanceClass)) {
             return $instance;
         }
     }
     // Create and return a new form bean instance
     try {
         /** @var \Phruts\Action\AbstractActionForm $instance */
         $instance = \Phruts\Util\ClassLoader::newInstance($config->getType(), '\\Phruts\\Action\\AbstractActionForm');
         $instance->setActionKernel($kernel);
     } catch (\Exception $e) {
         $msg = $kernel->getInternal()->getMessage(null, 'formBean', $config->getType());
         throw new \Phruts\Exception($msg);
     }
     return $instance;
 }