/**
  * 
  * @param type $string
  * @return type
  */
 protected function _createUrlKey($string)
 {
     $neutralChars = array('.', ',', '_', '(', ')', '[', ']', '|', ' ');
     $preCleaned = StringMethods::fastClean($string, $neutralChars, '-');
     $cleaned = StringMethods::fastClean($preCleaned);
     $return = trim(trim($cleaned), '-');
     return strtolower($return);
 }
 /**
  * The _arguments() method is used for any of the statements, 
  * if they have a specific argument format (such as for, foreach, or macro). 
  * It returns the bits between the {...} characters in a neat associative array
  * 
  * @param string $source
  * @param array $expression
  * @return array
  */
 protected function _arguments($source, $expression)
 {
     $args = $this->_array($expression, array($expression => array("opener" => "{", "closer" => "}")));
     $tags = $args["tags"];
     $arguments = array();
     $sanitized = StringMethods::sanitize($expression, "()[],.<>*\$@");
     foreach ($tags as $i => $tag) {
         $sanitized = str_replace($tag, "(.*)", $sanitized);
         $tags[$i] = str_replace(array("{", "}"), "", $tag);
     }
     if (preg_match("#{$sanitized}#", $source, $matches)) {
         foreach ($tags as $i => $tag) {
             $arguments[$tag] = $matches[$i + 1];
         }
     }
     return $arguments;
 }
 /**
  * The match() method evaluates a $source string to 
  * determine if it matches a tag or statement
  * 
  * @param mixed $source
  * @return mixed
  */
 public function match($source)
 {
     $type = null;
     $delimiter = null;
     foreach ($this->_map as $_delimiter => $_type) {
         if (!$delimiter || StringMethods::indexOf($source, $type["opener"]) == -1) {
             $delimiter = $_delimiter;
             $type = $_type;
         }
         $indexOf = StringMethods::indexOf($source, $_type["opener"]);
         if ($indexOf > -1) {
             if (StringMethods::indexOf($source, $type["opener"]) > $indexOf) {
                 $delimiter = $_delimiter;
                 $type = $_type;
             }
         }
     }
     if ($type == null) {
         return null;
     }
     return array("type" => $type, "delimiter" => $delimiter);
 }
Esempio n. 4
0
 /**
  * There are four basic parts to our __call() method: 
  * checking to see that the inspector is set, 
  * handling the getProperty() methods, handling the setProperty() methods and 
  * handling the unsProperty() methods
  * 
  * @param string $name
  * @param string $arguments
  * @return null|\THCFrame\Core\Base
  * @throws Exception
  */
 public function __call($name, $arguments)
 {
     if (empty($this->_inspector)) {
         throw new Exception('Call parent::__construct!');
     }
     $getMatches = StringMethods::match($name, '#^get([a-zA-Z0-9_]+)$#');
     if (count($getMatches) > 0) {
         $normalized = lcfirst($getMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $meta = $this->_inspector->getPropertyMeta($property);
             if (empty($meta['@readwrite']) && empty($meta['@read'])) {
                 throw $this->_getWriteonlyException($normalized);
             }
             unset($meta);
             if (isset($this->{$property})) {
                 return $this->{$property};
             } else {
                 return null;
             }
         } elseif (array_key_exists($normalized, $this->_dataStore)) {
             return $this->_dataStore[$normalized];
         } else {
             return null;
         }
     }
     unset($getMatches);
     $setMatches = StringMethods::match($name, '#^set([a-zA-Z0-9_]+)$#');
     if (count($setMatches) > 0) {
         $normalized = lcfirst($setMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $meta = $this->_inspector->getPropertyMeta($property);
             if (empty($meta['@readwrite']) && empty($meta['@write'])) {
                 throw $this->_getReadonlyException($normalized);
             }
             unset($meta);
             $this->{$property} = $arguments[0];
             return $this;
         } else {
             //if variable is not class property its stored into _dataStore array
             $this->_dataStore[$normalized] = $arguments[0];
             return $this;
         }
     }
     unset($setMatches);
     $unsetMatches = StringMethods::match($name, '#^uns([a-zA-Z0-9_]+)$#');
     if (count($unsetMatches) > 0) {
         $normalized = lcfirst($setMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $meta = $this->_inspector->getPropertyMeta($property);
             if (empty($meta['@readwrite']) && empty($meta['@write'])) {
                 throw $this->_getReadonlyException($normalized);
             }
             unset($meta);
             unset($this->{$property});
             return $this;
         } else {
             unset($this->_dataStore[$normalized]);
             return $this;
         }
     }
     unset($unsetMatches);
     throw $this->_getImplementationException($name);
 }
 /**
  * The internal _parse() method uses a fairly simple regular expression to match key/value pairs
  * within the Doc Comment string returned by any of our _get…Meta() methods
  * 
  * @param type $comment
  * @return type
  */
 protected function _parse($comment)
 {
     $meta = array();
     $pattern = '(@[a-zá-žA-ZÁ-Ž]+\\s*[a-zá-žA-ZÁ-Ž0-9, ()_]*)';
     $matches = StringMethods::match($comment, $pattern);
     if ($matches != null) {
         foreach ($matches as $match) {
             $parts = ArrayMethods::clean(ArrayMethods::trim(StringMethods::split($match, '[\\s]', 2)));
             $meta[$parts[0]] = true;
             if (count($parts) > 1) {
                 $meta[$parts[0]] = ArrayMethods::clean(ArrayMethods::trim(StringMethods::split($parts[1], ',')));
             }
         }
     }
     return $meta;
 }
 /**
  * 
  * @param type $url
  * @param type $parameters
  * @return type
  */
 public function get($url, $parameters = array())
 {
     if (!empty($parameters)) {
         $url .= StringMethods::indexOf($url, '?') ? '&' : '?';
         $url .= is_string($parameters) ? $parameters : http_build_query($parameters, '', '&');
     }
     return $this->request('GET', $url);
 }
 /**
  * Get cleaned file name
  * 
  * @param string $path
  * @return null|string
  */
 public function getNormalizedFileName($path)
 {
     if ($path != '') {
         $name = pathinfo($path, PATHINFO_FILENAME);
         return StringMethods::removeDiacriticalMarks(str_replace('.', '_', str_replace(' ', '_', $name)));
     } else {
         return null;
     }
 }
Esempio n. 8
0
 /**
  * 
  * @param type $alias
  */
 public function setTableAlias($alias)
 {
     if (StringMethods::match($alias, '#^([a-z_-]*)$#')) {
         $this->_alias = $alias;
     } else {
         throw new Exception('Table alias is not valid alias');
     }
     return $this;
 }
 /**
  * 
  * @param type $key
  * @param type $value
  */
 public function set($key, $value)
 {
     if (StringMethods::indexOf($value, "\$_text") > -1) {
         $first = StringMethods::indexOf($value, "\"");
         $last = StringMethods::lastIndexOf($value, "\"");
         $value = stripslashes(substr($value, $first + 1, $last - $first - 1));
     }
     if (is_array($key)) {
         $key = $this->_getKey($key);
     }
     $this->_setValue($key, $value);
 }
Esempio n. 10
0
 /**
  * Method begins by getting a list of columns and iterating over that list. 
  * For each column, we determine whether validation should occur. 
  * We then split the @validate metadata into a list of validation conditions. 
  * If a condition has arguments (e.g., max(100)), we extract the arguments. 
  * We then run each validation method on the column data and generate error 
  * messages for those validation conditions that failed. 
  * We return a final true/false to indicate whether the complete validation passed or failed.
  * 
  * @return type
  * @throws Exception\Validation
  */
 public function validate()
 {
     $this->_errors = array();
     $config = Registry::get('configuration');
     $errLang = $config->system->lang;
     foreach ($this->columns as $column) {
         if ($column['validate']) {
             $pattern = '#[a-z]+\\(([a-zá-žA-ZÁ-Ž0-9, ]+)\\)#';
             $raw = $column['raw'];
             $name = $column['name'];
             $validators = $column['validate'];
             $label = $column['label'];
             $defined = $this->getValidators();
             foreach ($validators as $validator) {
                 $function = $validator;
                 $arguments = array($this->{$raw});
                 $match = StringMethods::match($validator, $pattern);
                 if (count($match) > 0) {
                     $matches = StringMethods::split($match[0], ',\\s*');
                     $arguments = array_merge($arguments, $matches);
                     $offset = StringMethods::indexOf($validator, '(');
                     $function = substr($validator, 0, $offset);
                 }
                 if (!isset($defined[$function])) {
                     throw new Exception\Validation(sprintf('The %s validator is not defined', $function));
                 }
                 $template = $defined[$function];
                 if (!call_user_func_array(array($this, $template['handler']), $arguments)) {
                     $replacements = array_merge(array($label ? $label : $raw), $arguments);
                     $message = $template['message_' . $errLang];
                     foreach ($replacements as $i => $replacement) {
                         $message = str_replace("{{$i}}", $replacement, $message);
                     }
                     if (!isset($this->_errors[$name])) {
                         $this->_errors[$name] = array();
                     }
                     $this->_errors[$name][] = $message;
                 }
             }
         }
     }
     return !count($this->errors);
 }
Esempio n. 11
0
 /**
  * Save an image
  * The resulting format will be determined by the file extension.
  *
  * @param null|string	$filename	If omitted - original file will be overwritten
  * @param null|int		$quality	Output image quality in percents 0-100
  * @return Image
  * @throws Exception
  */
 public function save($filename = null, $quality = null)
 {
     // Determine quality, filename, and format
     $quality = $quality ?: $this->quality;
     $filename = $filename ? StringMethods::removeDiacriticalMarks(str_replace(' ', '_', $filename)) : $this->filename;
     $info = $this->getOriginalInfo();
     $format = $this->_fileExt($filename) ?: $info['format'];
     // Create the image
     switch (strtolower($format)) {
         case 'gif':
             $result = imagegif($this->image, $filename);
             break;
         case 'jpg':
         case 'jpeg':
             imageinterlace($this->image, true);
             $result = imagejpeg($this->image, $filename, round($quality));
             break;
         case 'png':
             $result = imagepng($this->image, $filename, round(9 * $quality / 100));
             break;
         default:
             throw new Exception\Type('Unsupported format');
     }
     if (!$result) {
         throw new Exception\IO(sprintf('Unable to save image: %s', $filename));
     }
     $this->filename = $filename;
     return $this;
 }