Example #1
0
 /**
  * Validates the value. Returns true if everything is okey or an Error
  * object if there was an error.
  *
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @return boolean|\Zepi\Web\UserInterface\Form\Error
  */
 public function validate(Framework $framework)
 {
     $translationManager = $framework->getInstance('\\Zepi\\Core\\Language\\Manager\\TranslationManager');
     if (!filter_var($this->value, FILTER_VALIDATE_EMAIL)) {
         return new Error(Error::INVALID_VALUE, $translationManager->translate('The value for the field %field% is not an valid email address.', '\\Zepi\\Web\\UserInterface', array('field' => $this->label)));
     }
     return true;
 }
 /**
  * Returns the instance for the given class
  * 
  * @param \ReflectionClass $parameterClass
  * @return null|object
  */
 protected function getInstance(ReflectionClass $parameterClass)
 {
     if (!class_exists($parameterClass->name, true)) {
         return null;
     }
     if (strpos($parameterClass->name, 'Zepi\\Turbo\\') === 0) {
         return $this->getFrameworkInstance($parameterClass);
     }
     if ($parameterClass->isInstantiable()) {
         return $this->framework->getInstance($parameterClass->name);
     }
 }
Example #3
0
 /**
  * Returns the data source for the given type class.
  * 
  * @access public
  * @param string $typeClass
  * @return mixed
  * 
  * @throws \Zepi\Turbo\Exception Cannot find a driver for the given type class.
  * @throws \Zepi\Turbo\Exception Cannot find a data source for the given type class.
  */
 public function getDataSource($typeClass)
 {
     $driver = $this->getDriver($typeClass);
     // If there is no driver for the given type class throw an exception
     if ($driver === false) {
         throw new Exception('Cannot find a driver for the given type class "' . $typeClass . '".');
     }
     $dataSourceClass = $this->searchDataSourceClass($typeClass, $driver);
     // If there is no data source class for the given type class throw an exception
     if ($dataSourceClass === false) {
         throw new Exception('Cannot find a data source for the given type class "' . $typeClass . '" (selected driver: "' . $driver . '").');
     }
     return $this->framework->getInstance($dataSourceClass);
 }
Example #4
0
 /**
  * Renders a overview page for the given MenuEntry object
  * 
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Web\General\Entity\MenuEntry $menuEntry
  * @return string
  */
 public function render(Framework $framework, MenuEntry $menuEntry)
 {
     // If the MenuEntry hasn't any children we return an empty string.
     if (!$menuEntry->hasChildren()) {
         return '';
     }
     $templatesManager = $framework->getInstance('\\Zepi\\Web\\General\\Manager\\TemplatesManager');
     $htmlString = '';
     $emptyChilds = array();
     foreach ($menuEntry->getChildren() as $child) {
         if (!$child->hasChildren()) {
             $emptyChilds[] = $child;
         } else {
             $htmlString .= $templatesManager->renderTemplate('\\Zepi\\Web\\UserInterface\\Templates\\OverviewPageSection', array('menuEntry' => $child));
         }
     }
     $htmlString = $templatesManager->renderTemplate('\\Zepi\\Web\\UserInterface\\Templates\\OverviewPageItems', array('children' => $emptyChilds)) . $htmlString;
     return $htmlString;
 }
Example #5
0
 /**
  * Executes the given event handlers. Every event handler will
  * be initialized and executed.
  * 
  * @access protected
  * @param string $type
  * @param string $name
  * @param mixed $value
  * @return mixed
  */
 protected function executeItems($type, $name, $value = null)
 {
     if (!isset($this->handlers[$type][$name])) {
         return $value;
     }
     $request = $this->framework->getRequest();
     foreach ($this->filterHandlers($type, $name, $request) as $handlerName) {
         $handler = $this->framework->getInstance($handlerName);
         $response = $this->framework->getResponse();
         $response->setData('_executedType', $type);
         $response->setData('_executedName', $name);
         // Execute the handler
         $handlerResult = $handler->execute($this->framework, $this->framework->getRequest(), $response, $value);
         // Save the handler result to the variable if this is an filter handler
         if ($type === self::FILTER) {
             $value = $handlerResult;
         }
     }
     // Return the value if this is an filter handler
     if ($type === self::FILTER) {
         return $value;
     }
 }
Example #6
0
 /**
  * Validates the form data and returns an array with errors.
  * If the array is empty there was no error.
  * 
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @return array
  */
 public function validateFormData(Framework $framework)
 {
     $translationManager = $framework->getInstance('\\Zepi\\Core\\Language\\Manager\\TranslationManager');
     $errors = array();
     foreach ($this->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\Field\\FieldAbstract') as $field) {
         // Validate mandatory fields
         if ($field->isMandatory() && !$field->hasValue()) {
             $errors[] = new Error(Error::MANDATORY_FIELD, sprintf($translationManager->translate('%s is a mandatory field. Please fill out the field.', '\\Zepi\\Web\\UserInterface'), $field->getLabel()), $field);
         }
         $result = $field->validate($framework);
         if ($result !== true) {
             $errors[] = $result;
         }
     }
     return $errors;
 }
Example #7
0
 /**
  * Homepage
  * 
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @param \Zepi\Turbo\Request\WebRequest $request
  * @param \Zepi\Turbo\Response\Response $response
  */
 public function execute(Framework $framework, WebRequest $request, Response $response)
 {
     $templatesManager = $framework->getInstance('\\Zepi\\Web\\General\\Manager\\TemplatesManager');
     $response->setOutput($templatesManager->renderTemplate('\\Zepi\\Starter\\Templates\\Homepage', $framework, $request, $response));
 }
Example #8
0
 /**
  * Validates the value. Returns true if everything is okey or an Error
  * object if there was an error.
  *
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @return boolean|\Zepi\Web\UserInterface\Form\Error
  */
 public function validate(Framework $framework)
 {
     $translationManager = $framework->getInstance('\\Zepi\\Core\\Language\\Manager\\TranslationManager');
     if ($this->minValue !== null && $this->value < $this->minValue) {
         return new Error(Error::INVALID_VALUE, $translationManager->translate('The value for the field %field% is lower than the allowed minimum (%min%).', '\\Zepi\\Web\\UserInterface', array('field' => $this->label, 'min' => $this->minValue)));
     }
     if ($this->maxValue !== null && $this->value > $this->maxValue) {
         return new Error(Error::INVALID_VALUE, $translationManager->translate('The value for the field %field% is higher than the allowed maximum (%max%).', '\\Zepi\\Web\\UserInterface', array('field' => $this->label, 'max' => $this->maxValue)));
     }
     return true;
 }
Example #9
0
 /**
  * Validates the value. Returns true if everything is okey or an Error
  * object if there was an error.
  *
  * @access public
  * @param \Zepi\Turbo\Framework $framework
  * @return boolean|\Zepi\Web\UserInterface\Form\Error
  */
 public function validate(Framework $framework)
 {
     $translationManager = $framework->getInstance('\\Zepi\\Core\\Language\\Manager\\TranslationManager');
     try {
         $ipObject = $this->createIpObject($this->value);
     } catch (ParseException $e) {
         $ipObject = false;
     }
     if ($ipObject === false) {
         return new Error(Error::INVALID_VALUE, $translationManager->translate('The value for the field %field% is not valid.', '\\Zepi\\Web\\UserInterface', array('field' => $this->label)));
     }
     return true;
 }