/**
  * Create and return a MessageResourcesFactory instance of the
  * appropriate class, which can be used to create customized
  * MessageResources instances.
  *
  * If no such factory can be created, return null instead.
  *
  * @return MessageResourcesFactory
  */
 public static function createFactory()
 {
     try {
         $factory = \Phruts\Util\ClassLoader::newInstance(self::$factoryClass, '\\Phruts\\Util\\MessageResourcesFactory');
         return $factory;
     } catch (\Exception $e) {
         return null;
     }
 }
 /**
  * Create and return a DataSourceFactory instance of the appropriate
  * class, which can be used to create customized data source instances.
  *
  * @param \Phruts\Config\DataSourceConfig $config
  * @return DataSourceFactory
  */
 public static function createFactory(\Phruts\Config\DataSourceConfig $config)
 {
     try {
         $factory = \Phruts\Util\ClassLoader::newInstance(self::$factoryClass, '\\Phruts\\Util\\DataSourceFactory');
         $factory->setConfig($config);
         return $factory;
     } catch (\Exception $e) {
         throw $e;
     }
 }
 /**
  * @param  array  $attributes
  * @return object
  */
 public function createObject(array $attributes)
 {
     // Identify the name of the class to instantiate
     if (array_key_exists('className', $attributes)) {
         $className = $attributes['className'];
     } else {
         $className = '\\Phruts\\Config\\DataSourceConfig';
     }
     // Instantiate the new object and return it
     $config = null;
     try {
         $config = \Phruts\Util\ClassLoader::newInstance($className, '\\Phruts\\Config\\DataSourceConfig');
     } catch (\Exception $e) {
         $this->digester->getLogger()->error('\\Phruts\\Config\\DataSourceConfigFactory->createObject(): ' . $e->getMessage());
     }
     return $config;
 }
 /**
  * @param  array  $attributes
  * @return object
  */
 public function createObject(array $attributes)
 {
     // Identify the name of the class to instantiate
     if (array_key_exists('className', $attributes)) {
         $className = $attributes['className'];
     } else {
         $mc = $this->digester->peek();
         $className = $mc->getActionClass();
     }
     // Instantiate the new object and return it
     $actionConfig = null;
     try {
         $actionConfig = \Phruts\Util\ClassLoader::newInstance($className, '\\Phruts\\Action\\ActionMapping');
     } catch (\Exception $e) {
         $logger = $this->digester->getLogger();
         if (!empty($logger)) {
             $logger->error('\\Phruts\\Config\\ActionConfigFactory->createObject(): ' . $e->getMessage());
         }
         throw $e;
     }
     return $actionConfig;
 }
Example #5
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;
 }
 /**
  * <p>Return an object representing the initial value of this property.
  * This is calculated according to the following algorithm:</p>
  * <ul>
  * <li>If the value you have specified for the <code>type</code>
  *     property represents an array (i.e. it ends with "[]"):
  *     <ul>
  *     <li>If you have specified a value for the <code>initial</code>
  *         property, <code>ConvertUtils.convert()</code> will be
  *         called to convert it into an instance of the specified
  *         array type.</li>
  *     <li>If you have not specified a value for the <code>initial</code>
  *         property, an array of the length specified by the
  *         <code>size</code> property will be created.  Each element
  *         of the array will be instantiated via the zero-args constructor
  *         on the specified class (if any).  Otherwise, <code>null</code>
  *         will be returned.</li>
  *     </ul></li>
  * <li>If the value you have specified for the <code>type</code>
  *     property does not represent an array:
  *     <ul>
  *     <li>If you have specified a value for the <code>initial</code>
  *         property, <code>ConvertUtils.convert()</code>
  *         will be called to convert it into an object instance.</li>
  *     <li>If you have not specified a value for the <code>initial</code>
  *         attribute, Struts will instantiate an instance via the
  *         zero-args constructor on the specified class (if any).
  *         Otherwise, <code>null</code> will be returned.</li>
  *     </ul></li>
  * </ul>
  */
 public function initial()
 {
     $initialValue = null;
     try {
         $className = $this->getTypeClass();
         switch ($className) {
             case \Phruts\Config\FormPropertyConfig::TYPE_ARRAY:
                 if ($this->initial != null) {
                     $initialValue = explode(',', $this->initial);
                 } else {
                     $initialValue = array();
                 }
                 break;
             case \Phruts\Config\FormPropertyConfig::TYPE_BOOLEAN:
                 $value = $this->initial;
                 if ($value == null) {
                     $initialValue = true;
                 } elseif (strtolower($value) == "true") {
                     $initialValue = true;
                 } elseif (strtolower($value) == "yes") {
                     $initialValue = true;
                 } else {
                     $initialValue = false;
                 }
                 break;
             case \Phruts\Config\FormPropertyConfig::TYPE_STRING:
                 $initialValue = $this->initial;
                 break;
             case \Phruts\Config\FormPropertyConfig::TYPE_FLOAT:
                 if ($this->initial != null) {
                     $initialValue = floatval($this->initial);
                 } else {
                     $initialValue = floatval(0);
                 }
                 break;
             case \Phruts\Config\FormPropertyConfig::TYPE_INTEGER:
                 if ($this->initial != null) {
                     $initialValue = intval($this->initial);
                 } else {
                     $initialValue = intval(0);
                 }
                 break;
             default:
                 // Create the class
                 if ($this->indexed) {
                     // Place a indexed set of objects into the form
                     $initialValue = array();
                     $size = intval($this->initial);
                     if ($size > 0) {
                         for ($x = 0; $x < $size; $x++) {
                             $initialValue[] = \Phruts\Util\ClassLoader::newInstance($className);
                         }
                     }
                 } else {
                     $initialValue = \Phruts\Util\ClassLoader::newInstance($className);
                 }
                 break;
         }
     } catch (\Exception $e) {
         $initialValue = null;
     }
     return $initialValue;
 }
Example #7
0
 /**
  * Return a Action instance that will be used to process the current
  * request, creating a new one if necessary.
  *
  * @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\ActionMapping $mapping The mapping we are using
  * @return \Phruts\Config\ForwardConfig
  */
 protected function processActionCreate(\Symfony\Component\HttpFoundation\Request $request, \Symfony\Component\HttpFoundation\Response $response, \Phruts\Action\ActionMapping $mapping)
 {
     // Acquire the Action instance we will be using (if there is one)
     $className = $mapping->getType();
     if (!empty($this->log)) {
         $this->log->debug('  Looking for Action instance for class ' . $className);
     }
     $instance = null;
     // Return any existing Action instance of this class
     if (array_key_exists($className, $this->actions)) {
         $instance = $this->actions[$className];
     }
     if (!is_null($instance)) {
         if (!empty($this->log)) {
             $this->log->debug('  Returning existing Action instance');
         }
         return $instance;
     }
     // Create an return a new Action instance
     if (!empty($this->log)) {
         $this->log->debug('  Creating new Action instance');
     }
     try {
         $instance = \Phruts\Util\ClassLoader::newInstance($className, '\\Phruts\\Action\\Action');
     } catch (\Exception $e) {
         $msg = $this->getInternal()->getMessage(null, 'actionCreate', $mapping->getPath());
         if (!empty($this->log)) {
             $this->log->error($msg . ' - ' . $e->getMessage());
         }
         throw new HttpException(500, $msg);
     }
     $instance->setActionKernel($this->actionKernel);
     $this->actions[$className] = $instance;
     return $instance;
 }
 public function testProcessActionPerform()
 {
     $method = self::getMethod('processActionPerform');
     $mapping = $this->actionConfig1;
     $action = ClassLoader::newInstance($this->actionConfig1->getType(), '\\Phruts\\Action\\Action');
     $form = null;
     $method->invokeArgs($this->requestProcessor, array($this->request, $this->response, $action, $form, $mapping));
 }
Example #9
0
 public function testNewInstanceConstructor()
 {
     // Test params in Constructor
     $this->setExpectedException('\\Phruts\\Exception\\InstantiationException');
     \Phruts\Util\ClassLoader::newInstance('\\Phruts\\Action\\ActionKernel');
 }
Example #10
0
 protected function initModulePlugIns(\Phruts\Config\ModuleConfig $config)
 {
     if (!empty($this->log)) {
         $this->log->debug('Initializing module "' . $config->getPrefix() . '" plug ins');
     }
     $plugInConfigs = $config->findPlugInConfigs();
     $plugIns = array();
     foreach ($plugInConfigs as $plugInConfig) {
         /* @var $plugInConfig \Phruts\Config\PlugInConfig */
         try {
             /* @var $plugIn \Phruts\Action\PlugInInterface */
             $plugIn = \Phruts\Util\ClassLoader::newInstance($plugInConfig->getClassName(), '\\Phruts\\Action\\PlugInInterface');
             \Phruts\Util\BeanUtils::populate($plugIn, $plugInConfig->getProperties());
             $plugIn->init($this, $config);
             $plugIns[] = $plugIn;
         } catch (\Exception $e) {
             $msg = $this->getInternal()->getMessage(null, 'plugIn.init', $plugInConfig->getClassName());
             if (!empty($this->log)) {
                 $this->log->error($msg . ' - ' . $e->getMessage());
             }
             throw new \Phruts\Exception($msg);
         }
     }
     $this->application[\Phruts\Util\Globals::PLUG_INS_KEY . $config->getPrefix()] = $plugIns;
 }