/**
  * Executes the task.
  */
 public function main()
 {
     if ($this->property === null) {
         throw new BuildException('The property attribute must be specified');
     }
     if ($this->string === null) {
         throw new BuildException('The string attribute must be specified');
     }
     $result = str_replace('/', '_', AgaviToolkit::canonicalName($this->string));
     $this->project->setUserProperty($this->property, $result);
 }
 private function getActionClass($moduleName, $actionName)
 {
     $actionName = AgaviToolkit::canonicalName($actionName);
     $longActionName = str_replace('/', '_', $actionName);
     $class = $moduleName . '_' . $longActionName . 'Action';
     if (!class_exists($class)) {
         if (false !== ($file = AppKitAgaviUtil::getAgaviControllerInstance()->checkActionFile($moduleName, $actionName))) {
             require $file;
         } else {
             throw new AgaviException('Could not find file for Action "' . $actionName . '" in module "' . $moduleName . '"');
         }
         if (!class_exists($class, false)) {
             throw new AgaviException('Could not find Action "' . $longActionName . '" for module "' . $moduleName . '"');
         }
     }
     return $class;
 }
Ejemplo n.º 3
0
 /**
  * assert that the view forwards to the given module/action
  * 
  * @param      string the expected module name
  * @param      string the expected action name
  * @param      string the message to emit on failure
  *
  * @author     Felix Gilcher <*****@*****.**>
  * @since      1.0.0
  */
 protected function assertViewForwards($expectedModule, $expectedAction, $message = 'Failed asserting that the view forwards to "%1$s" "%2$s".')
 {
     if (!$this->viewResult instanceof AgaviExecutionContainer) {
         $this->fail(sprintf($message, $expectedModule, $expectedAction));
     }
     $this->assertEquals($expectedModule, $this->viewResult->getModuleName());
     $this->assertEquals(AgaviToolkit::canonicalName($expectedAction), $this->viewResult->getActionName());
 }
 /**
  * normalizes a viewname according to the configured rules
  * 
  * Please do not use this method, it exists only for internal 
  * purposes and will be removed ASAP. You have been warned
  * 
  * @param      string the short view name
  * 
  * @return     string the full view name
  * 
  * @author     Felix Gilcher <*****@*****.**>
  * @since      1.0.0
  */
 protected function normalizeViewName($shortName)
 {
     if ($shortName !== AgaviView::NONE) {
         $shortName = AgaviToolkit::evaluateModuleDirective($this->moduleName, 'agavi.view.name', array('actionName' => $this->actionName, 'viewName' => $shortName));
         $shortName = AgaviToolkit::canonicalName($shortName);
     }
     return $shortName;
 }
 /**
  * Get validation information from agavi for the given action and module
  * name for the request method 'read'.
  *
  * @author Jan Schütze <*****@*****.**>
  *
  * @param string $action name of action
  * @param string $module name of module
  *
  * @return array of parameters for all registered validators
  */
 protected function getParametersForActionAndModule($action, $module, $method = 'read')
 {
     /*
      * Agavi uses different coding standard, so we ignore the following...
      *
      * @codingStandardsIgnoreStart
      */
     $parameters = array();
     $this->getContext()->getController()->initializeModule($module);
     $validationManager = $this->getContext()->createInstanceFor('validation_manager');
     $validationConfig = \AgaviToolkit::evaluateModuleDirective($module, 'agavi.validate.path', array('moduleName' => $module, 'actionName' => \AgaviToolkit::canonicalName($action)));
     if (is_readable($validationConfig)) {
         require \AgaviConfigCache::checkConfig($validationConfig, $this->getContext()->getName());
     }
     foreach ($validationManager->getChilds() as $validator) {
         $property = new \ReflectionProperty(get_class($validator), 'arguments');
         $property->setAccessible(true);
         $arguments = $property->getValue($validator);
         $parameters[] = array('name' => implode(', ', $arguments), 'class' => $validator->getParameter('class'), 'required' => $validator->getParameter('required', 'true'), 'description' => $validator->getParameter('description', null), 'base' => $validator->getParameter('base', null));
     }
     /*
      * @codingStandardsIgnoreEnd
      */
     return $parameters;
 }
Ejemplo n.º 6
0
 /**
  * Retrieve a Model implementation instance.
  *
  * @param      string A model name.
  * @param      string A module name, if the requested model is a module model,
  *                    or null for global models.
  * @param      array  An array of parameters to be passed to initialize() or
  *                    the constructor.
  *
  * @return     AgaviModel A Model implementation instance.
  *
  * @throws     AgaviAutloadException if class is ultimately not found.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function getModel($modelName, $moduleName = null, array $parameters = null)
 {
     $origModelName = $modelName;
     $modelName = AgaviToolkit::canonicalName($modelName);
     $class = str_replace('/', '_', $modelName) . 'Model';
     $file = null;
     $rc = null;
     if ($moduleName === null) {
         // global model
         // let's try to autoload that baby
         if (!class_exists($class)) {
             // it's not there. the hunt is on
             $file = AgaviConfig::get('core.model_dir') . '/' . $modelName . 'Model.class.php';
         }
     } else {
         try {
             $this->controller->initializeModule($moduleName);
         } catch (AgaviDisabledModuleException $e) {
             // swallow, this will load the modules autoload but throw an exception
             // if the module is disabled.
         }
         // module model
         // alternative name
         $class = $moduleName . '_' . $class;
         // let's try to autoload the baby
         if (!class_exists($class)) {
             // it's not there. the hunt is on
             $file = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/models/' . $modelName . 'Model.class.php';
         }
     }
     if (null !== $file && is_readable($file)) {
         require $file;
     }
     if (!class_exists($class)) {
         // it's not there.
         throw new AgaviAutoloadException(sprintf("Couldn't find class for Model %s", $origModelName));
     }
     // so if we're here, we found something, right? good.
     $rc = new ReflectionClass($class);
     if ($rc->implementsInterface('AgaviISingletonModel')) {
         // it's a singleton
         if (!isset($this->singletonModelInstances[$class])) {
             // no instance yet, so we create one
             if ($parameters === null || $rc->getConstructor() === null) {
                 // it has an initialize() method, or no parameters were given, so we don't hand arguments to the constructor
                 $this->singletonModelInstances[$class] = new $class();
             } else {
                 // we use this approach so we can pass constructor params or if it doesn't have an initialize() method
                 $this->singletonModelInstances[$class] = $rc->newInstanceArgs($parameters);
             }
         }
         $model = $this->singletonModelInstances[$class];
     } else {
         // create an instance
         if ($parameters === null || $rc->getConstructor() === null) {
             // it has an initialize() method, or no parameters were given, so we don't hand arguments to the constructor
             $model = new $class();
         } else {
             // we use this approach so we can pass constructor params or if it doesn't have an initialize() method
             $model = $rc->newInstanceArgs($parameters);
         }
     }
     if (is_callable(array($model, 'initialize'))) {
         // pass the constructor params again. dual use for the win
         $model->initialize($this, (array) $parameters);
     }
     return $model;
 }
Ejemplo n.º 7
0
 public function testCanonicalName()
 {
     $this->assertEquals('path', AgaviToolkit::canonicalName("path"));
     $this->assertEquals('/path/warm/hot/unbearable', AgaviToolkit::canonicalName("/path/warm/hot/unbearable"));
     $this->assertEquals('path/warm/hot/unbearable', AgaviToolkit::canonicalName("path.warm.hot.unbearable"));
     $this->assertEquals('/path//warm/hot///unbearable', AgaviToolkit::canonicalName(".path..warm.hot...unbearable"));
 }
 /**
  * Set the module name for this container.
  *
  * @param      string A view name.
  *
  * @author     David Zülke <*****@*****.**>
  * @since      0.11.0
  */
 public function setViewName($viewName)
 {
     if (null === $viewName) {
         $this->viewName = null;
     } elseif (preg_match(self::SANE_VIEW_NAME, $viewName)) {
         $viewName = AgaviToolkit::canonicalName($viewName);
         $this->viewName = $viewName;
     } else {
         throw new AgaviException(sprintf('Invalid view name "%1$s"', $viewName));
     }
 }
Ejemplo n.º 9
0
 /**
  * Indicates whether or not a module has a specific model.
  *
  * @param      string A module name.
  * @param      string A model name.
  *
  * @return     bool true, if the model exists, otherwise false.
  *
  * @author     Sean Kerr <*****@*****.**>
  * @since      0.9.0
  */
 public function modelExists($moduleName, $modelName)
 {
     $modelName = AgaviToolkit::canonicalName($modelName);
     $file = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/models/' . $modelName . 'Model.class.php';
     return is_readable($file);
 }