Beispiel #1
0
 /**
  * Set the type of this message
  * @param string $type
  * @return null
  */
 public function setType($type = null)
 {
     if ($type !== null && !String::isString($type, String::NOT_EMPTY)) {
         throw new ZiboException('The provided type is invalid or empty');
     }
     $this->type = $type;
 }
 /**
  * Sets the id of this cache object
  * @param string $id
  * @return null
  * @throws zibo\ZiboException when the provided id is empty or invalid
  */
 private function setId($id)
 {
     if (!String::isString($id, String::NOT_EMPTY)) {
         throw new ZiboException('Provided id is empty');
     }
     $this->id = $id;
 }
 /**
  * Sets the method name of this callback
  * @param string $methodName A method name
  * @return null
  */
 public function setMethodName($methodName)
 {
     if (!String::isString($methodName, String::NOT_EMPTY)) {
         throw new ZiboException('Provided class name is empty or invalid');
     }
     $this->methodName = $methodName;
 }
 /**
  * Sets the SQL for this condition
  * @param string $sql The SQL
  * @return null
  * @throws zibo\library\database\exception\DatabaseException when the provided SQL is empty or not a string
  */
 private function setSql($sql)
 {
     if (!String::isString($sql, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided sql is empty or not a valid string');
     }
     $this->sql = $sql;
 }
 /**
  * Set the name of this field
  * @param string $name
  * @return null
  * @throws zibo\library\database\exception\DatabaseException when the name is empty or not a string
  */
 private function setName($name)
 {
     if (!String::isString($name, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided name is empty');
     }
     $this->name = $name;
 }
Beispiel #6
0
 /**
  * Sets the id of this dependency
  * @param string $id A identifier
  * @return null
  */
 public function setId($id = null)
 {
     if ($id !== null && !String::isString($id, String::NOT_EMPTY)) {
         throw new ZiboException('Provided id is empty or invalid');
     }
     $this->id = $id;
 }
 /**
  * Quotes a database identifier
  * @param string $identifier Identifier to quote
  * @return string Quoted identifier
  * @throws zibo\library\database\exception\DatabaseException when the provided identifier is empty or not a scalar value
  */
 public function quoteIdentifier($identifier)
 {
     if (!String::isString($identifier, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided identifier is empty');
     }
     return $identifier;
 }
Beispiel #8
0
 private function parseVariables($string)
 {
     if (!String::isString($string, String::NOT_EMPTY) || !isset($this->variables)) {
         return $string;
     }
     foreach ($this->variables as $variable => $value) {
         $string = str_replace('%' . $variable . '%', $value, $string);
     }
     return $string;
 }
 /**
  * Set the join type
  * @param string $type possible values are INNER, LEFT and RIGHT
  * @return null
  * @throws zibo\library\database\exception\DatabaseException when the type is empty or not valid type
  */
 private function setType($type)
 {
     if (!String::isString($type, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided type is empty');
     }
     if ($type != self::TYPE_LEFT && $type != self::TYPE_INNER && $type != self::TYPE_RIGHT) {
         throw new DatabaseException($type . ' is not a valid type, try ' . self::TYPE_LEFT . ', ' . self::TYPE_INNER . ' or ' . self::TYPE_RIGHT);
     }
     $this->type = $type;
 }
 /**
  * Set the alias of this expression
  * @param string $alias
  * @return null
  * @throws zibo\library\database\exception\DatabaseException
  */
 public function setAlias($alias = null)
 {
     if ($alias === null) {
         $this->alias = null;
         return;
     }
     if (!String::isString($alias, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided alias is empty');
     }
     $this->alias = $alias;
 }
 /**
  * Sets the default action of this router
  * @param string $defaultController full class name of the default controller
  * @param string $defaultAction method name of the default action in the controller
  * @return null
  * @throws zibo\ZiboException when the default controller is an invalid or empty value
  * @throws zibo\ZiboException when the default action is an invalid or empty value
  */
 public function setDefaultAction($defaultController, $defaultAction = null)
 {
     if (!String::isString($defaultController, String::NOT_EMPTY)) {
         throw new ZiboException('Provided default controller is empty or not a string');
     }
     if ($defaultAction !== null && !String::isString($defaultAction, String::NOT_EMPTY)) {
         throw new ZiboException('Provided default action is empty or not a string');
     }
     $this->defaultController = $defaultController;
     $this->defaultAction = $defaultAction;
 }
Beispiel #12
0
 /**
  * Constructs a new DSN
  * @param string $dsn String of the database source name
  * @return null
  * @throws zibo\ZiboException when the provided DSN is not a string
  * @throws zibo\library\database\exception\DatabaseException when the provided DSN is empty or invalid
  */
 public function __construct($dsn)
 {
     if (!String::isString($dsn, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided dsn string is empty');
     }
     $validator = new DsnValidator();
     if (!$validator->isValid($dsn)) {
         throw new DatabaseException('Invalid dsn string provided: ' . $dsn);
     }
     $this->parseDsn($dsn);
 }
 /**
  * Set the mathematical operator of the expression
  * @param string $operator
  * @return null
  * @throws zibo\library\database\exception\DatabaseException when the operator is empty or invalid
  */
 private function setOperator($operator = null)
 {
     if ($operator === null) {
         $this->operator = MathematicalExpression::OPERATOR_ADDITION;
         return;
     }
     if (!String::isString($operator, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided operator is empty');
     }
     $this->operator = $operator;
 }
 /**
  * Set the direction of this order clause
  * @param string direction
  * @return null
  * @throws zibo\ZiboException when $direction is not a valid string
  * @throws zibo\library\database\exception\DatabaseException when the direction is empty or invalid
  */
 private function setDirection($direction = null)
 {
     if ($direction === null) {
         $direction = self::DIRECTION_ASC;
     }
     if (!String::isString($direction, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided direction is empty');
     }
     if ($direction != self::DIRECTION_ASC && $direction != self::DIRECTION_DESC) {
         throw new DatabaseException('Provided direction is invalid, try ' . self::DIRECTION_ASC . ' or ' . self::DIRECTION_DESC);
     }
     $this->direction = $direction;
 }
Beispiel #15
0
 /**
  * Sets a value to the session or clear a previously set key by passing a
  * null value
  * @param string $key Key of the value
  * @param mixed $value The value, null to clear
  * @return null
  * @throws zibo\ZiboException when an invalid key is provided
  */
 public function set($key, $value = null)
 {
     if (!String::isString($key, String::NOT_EMPTY)) {
         throw new ZiboException('Provided id is empty or invalid');
     }
     if ($value === null) {
         if (isset($_SESSION[$key])) {
             unset($_SESSION[$key]);
         }
     } else {
         $_SESSION[$key] = $value;
     }
 }
Beispiel #16
0
 /**
  * Executes a command on the server
  * @param string $command
  * @return string The output of the command
  * @throws zibo\ZiboException when the provided command is empty or not a string
  * @throws zibo\ZiboException when the command could not be executed
  */
 public static function execute($command)
 {
     if (!String::isString($command, String::NOT_EMPTY)) {
         throw new ZiboException('Provided command is empty or not a string');
     }
     $output = array();
     $code = '';
     exec($command, $output, $code);
     $output = implode("\n", $output);
     if ($code == 127) {
         throw new ZiboException('Could not execute ' . $command);
     }
     return $output;
 }
 /**
  * Sets the logical operator of this condition
  * @param string $operator Logical operator used before this part
  * @return null
  * @throws zibo\library\database\exception\DatabaseException when the operator is not AND or OR
  */
 private function setOperator($operator = null)
 {
     if ($operator === null) {
         $operator = Condition::OPERATOR_AND;
     } else {
         if (!String::isString($operator, String::NOT_EMPTY)) {
             throw new DatabaseException('Provided logical operator is empty. Try AND or OR');
         }
         $operator = strtoupper($operator);
         if ($operator != Condition::OPERATOR_AND && $operator != Condition::OPERATOR_OR) {
             throw new DatabaseException('Provided logical operator is invalid. Try AND or OR.');
         }
     }
     $this->operator = $operator;
 }
 /**
  * Set the SQL for this expression
  * @param string $sql
  * @return null
  * @throws zibo\library\database\exception\DatabaseException when the sql is empty or not a string
  */
 private function setSql($sql)
 {
     if ($sql === null) {
         $this->sql = 'NULL';
         return;
     }
     if (is_bool($sql)) {
         $this->sql = $sql ? '1' : '0';
         return;
     }
     if (!String::isString($sql, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided sql is empty');
     }
     $this->sql = $sql;
 }
 /**
  * Sets the comparison operator of this condition
  * @param string $operator Operator to compare the fields
  * @return null
  * @throws zibo\library\database\exception\DatabaseException when the operator is empty or not a valid string
  */
 protected function setOperator($operator = null)
 {
     if ($operator === null) {
         $this->operator = self::OPERATOR_EQUALS;
         return;
     }
     try {
         if (!String::isString($operator, String::NOT_EMPTY)) {
             throw new DatabaseException('Provided operator is empty');
         }
     } catch (ZiboException $e) {
         throw new DatabaseException('Provided operator is not a valid string');
     }
     $this->operator = strtoupper($operator);
 }
 /**
  * Gets a locale
  * @param string $code if not provided, the current locale will be returned
  * @return zibo\library\i18n\locale\Locale
  *
  * @uses zibo\library\i18n\locale\io\LocaleIO::getLocale()
  */
 public function getLocale($code = null)
 {
     $this->initLocales();
     if ($code === null) {
         if (!isset($this->currentLocale)) {
             $this->initCurrentLocale();
         }
         $code = $this->currentLocale;
     } elseif (!String::isString($code, String::NOT_EMPTY)) {
         throw new ZiboException('Provided code is invalid');
     }
     if (!isset($this->locales[$code])) {
         throw new LocaleNotFoundException($code);
     }
     return $this->locales[$code];
 }
 /**
  * Adds a dependency for the provided class to this container
  * @param string $for A full class name
  * @param Dependency $dependency
  * @return null
  */
 public function addDependency($for, Dependency $dependency)
 {
     if (!String::isString($for, String::NOT_EMPTY)) {
         throw new ZiboException('Invalid for class name provided');
     }
     $id = $dependency->getId();
     if (!isset($this->dependencies[$for])) {
         $this->dependencies[$for] = array();
     }
     if ($id) {
         $this->dependencies[$for][$id] = $dependency;
     } else {
         $this->dependencies[$for][] = $dependency;
         $ids = array_keys($this->dependencies[$for]);
         $dependency->setId(array_pop($ids));
     }
 }
 /**
  * Convert a PHP date format to a datepicker format
  * @param string $format PHP date format
  * @return string Datepicker date format of the PHP date format
  */
 public function convertFormatFromPhp($format)
 {
     if (!String::isString($format, String::NOT_EMPTY)) {
         throw new ZiboException('Provided format is empty or invalid');
     }
     $converted = '';
     $length = strlen($format);
     for ($i = 0; $i < $length; $i++) {
         $char = $format[$i];
         if (isset($this->formatCharacters[$char])) {
             $converted .= $this->formatCharacters[$char];
         } else {
             $converted .= $char;
         }
     }
     return $converted;
 }
 /**
  * Registers a archive implementation
  * @param string $extension File extension of the archive files
  * @param string $className Name of the archive implementation
  * @return null
  */
 public function register($extension, $className)
 {
     if (!String::isString($extension, String::NOT_EMPTY)) {
         throw new ArchiveException('Provided extension is empty');
     }
     if (!String::isString($className, String::NOT_EMPTY)) {
         throw new ArchiveException('Provided class name is empty');
     }
     try {
         $reflection = new ReflectionClass($className);
     } catch (ReflectionException $e) {
         throw new ArchiveException('Class ' . $className . ' does not exist');
     }
     if (!$reflection->implementsInterface(self::INTERFACE_ARCHIVE)) {
         throw new ArchiveException('Class ' . $className . ' does not implement the Archive interface');
     }
     $this->types[strtolower($extension)] = $className;
 }
Beispiel #24
0
 /**
  * Sets the callback
  * @param string|array|Callback $callback The callback
  * @return null
  * @throws zibo\ZiboException when an invalid callback has been provided
  */
 public function setCallback($callback)
 {
     if ($callback instanceof self) {
         // callback is already an instance of Callback, copy it's variables
         $this->callback = $callback->callback;
         $this->callbackString = $callback->callbackString;
         return;
     }
     if (String::isString($callback, String::NOT_EMPTY)) {
         // callback is a string, a global function call
         $this->callback = $callback;
         $this->callbackString = $callback;
         return;
     }
     if (!is_array($callback)) {
         throw new ZiboException('Provided callback is invalid: callback is not a string or an array');
     }
     if (count($callback) != 2) {
         throw new ZiboException('Provided callback is invalid: callback array should have 2 elements');
     }
     if (!isset($callback[0])) {
         throw new ZiboException('Provided callback is invalid: callback array should have an element 0 containing the class name or a class instance');
     }
     if (!isset($callback[1])) {
         throw new ZiboException('Provided callback is invalid: callback array should have an element 1 containing the method name');
     }
     // callback is an array with a class name or class instance as first
     // element and the method as the second element
     $object = $callback[0];
     $method = $callback[1];
     $isInstance = false;
     if (is_object($object)) {
         $object = get_class($object);
         $isInstance = true;
     }
     if (!String::isString($object, String::NOT_EMPTY)) {
         throw new ZiboException('Provided callback is invalid: class parameter is invalid or empty');
     }
     if (!String::isString($method, String::NOT_EMPTY)) {
         throw new ZiboException('Provided callback is invalid: method parameter is invalid or empty');
     }
     $this->callback = $callback;
     $this->callbackString = $object . ($isInstance ? '->' : '::') . $method;
 }
 /**
  * Construct a new regular expression validator
  * @param array $options options for this validator
  * @return null
  * @throws zibo\ZiboException when the regex option is empty or not a string
  */
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     if (!isset($options[self::OPTION_REGEX])) {
         throw new ZiboException('No regular expression provided through the options. Use option ' . self::OPTION_REGEX);
     }
     if (!String::isString($options[self::OPTION_REGEX], String::NOT_EMPTY)) {
         throw new ZiboException('Provided regular expression is empty');
     }
     $this->isRequired = true;
     if (isset($options[self::OPTION_REQUIRED])) {
         $this->isRequired = $options[self::OPTION_REQUIRED];
     }
     $this->regex = $options[self::OPTION_REGEX];
     $this->code = self::CODE;
     if (isset($options['message'])) {
         $this->code = $options['message'];
     }
     $this->message = 'Field does not match ' . $this->regex;
 }
 /**
  * Sets a translation for the provided locale
  * @param string $localeCode Code of the locale
  * @param string $key Key of the translation
  * @param string $translation
  * @return null
  * @throws zibo\ZiboException when the locale code is empty or invalid
  * @throws zibo\ZiboException when the translation key is empty or invalid
  * @throws zibo\ZiboException when the translation is empty or invalid
  */
 public function setTranslation($localeCode, $key, $translation)
 {
     if (!String::isString($localeCode, String::NOT_EMPTY)) {
         throw new ZiboException('Provided locale code is empty');
     }
     if (!String::isString($key, String::NOT_EMPTY)) {
         throw new ZiboException('Provided translation key is empty');
     }
     if (!String::isString($translation, String::NOT_EMPTY)) {
         throw new ZiboException('Provided translation is empty');
     }
     $translationFile = new File(Zibo::DIRECTORY_APPLICATION . File::DIRECTORY_SEPARATOR . Zibo::DIRECTORY_L10N, $localeCode . self::EXTENSION);
     if ($translationFile->exists()) {
         $translations = $this->getTranslationsFromFiles(array($translationFile));
     } else {
         $translations = array();
     }
     $translations[$key] = $translation;
     $this->setTranslationsToFile($translationFile, $translations);
 }
 /**
  * Checks whether a value is empty
  * @param mixed $value
  * @return boolean true if the value is empty, false otherwise
  */
 public function isValid($value)
 {
     $this->resetErrors();
     if (is_object($value)) {
         return true;
     }
     if (is_array($value)) {
         if (empty($value)) {
             $error = new ValidationError($this->errorCode, self::MESSAGE, array('value' => $value));
             $this->addError($error);
             return false;
         }
         return true;
     }
     if (!is_bool($value) && !String::isString($value, String::NOT_EMPTY)) {
         $error = new ValidationError($this->errorCode, self::MESSAGE, array('value' => $value));
         $this->addError($error);
         return false;
     }
     return true;
 }
Beispiel #28
0
 /**
  * Construct a new foreign key
  * @param string $fieldName Name of the field
  * @param string $referenceTableName Name of the referenced table
  * @param string $referenceFieldName Name of the linked field in the referenced table
  * @return null
  */
 public function __construct($fieldName, $referenceTableName, $referenceFieldName, $name = null)
 {
     if (!$name) {
         $name = $fieldName;
     }
     if (!String::isString($fieldName, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided name of the foreign key field is empty');
     }
     if (!String::isString($referenceTableName, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided name of the reference table is empty');
     }
     if (!String::isString($referenceFieldName, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided name of the reference field is empty');
     }
     if (!String::isString($name, String::NOT_EMPTY)) {
         throw new DatabaseException('Provided name of the foreign key is empty');
     }
     $this->name = $name;
     $this->fieldName = $fieldName;
     $this->referenceTableName = $referenceTableName;
     $this->referenceFieldName = $referenceFieldName;
 }
 /**
  * Look for files by looping through the include paths
  * @param string $fileName relative path of a file in the Zibo filesystem structure
  * @param boolean $firstOnly true to get the first matched file, false to get an array
  *                           with all the matched files
  * @return zibo\library\filesystem\File|array Depending on the firstOnly flag, an instance or an array of zibo\library\filesystem\File
  * @throws zibo\ZiboException when fileName is empty or not a string
  */
 protected function lookupFile($fileName, $firstOnly)
 {
     if (!$fileName instanceof File && !String::isString($fileName, String::NOT_EMPTY)) {
         throw new FileSystemException('Provided filename is empty');
     }
     $files = array();
     $includePaths = $this->getIncludePaths();
     foreach ($includePaths as $includePath) {
         $file = new File($includePath, $fileName);
         if (!$file->exists()) {
             continue;
         }
         if ($firstOnly) {
             return $file;
         }
         $files[$file->getPath()] = $file;
     }
     if ($firstOnly) {
         return null;
     }
     ksort($files);
     return $files;
 }
Beispiel #30
0
 /**
  * Gets the tokens of a configuration key. This method will read the
  * configuration for the section token (first token) if it has not been read before.
  * @return array Array with the tokens of the configuration key
  */
 private function getKeyTokens($key)
 {
     if (!String::isString($key, String::NOT_EMPTY)) {
         throw new ConfigException('Provided key is empty');
     }
     $tokens = explode(self::TOKEN_SEPARATOR, $key);
     $section = $tokens[0];
     if (!isset($this->data[$section])) {
         $this->data[$section] = $this->io->read($section);
     }
     return $tokens;
 }