Beispiel #1
0
 /**
  * Checking to see that the inspector is set, handling the getProperty() methods, and handling the setProperty() methods.
  * @param type $name
  * @param type $arguments
  * @return \Framework\Base
  * @throws Exception
  * @throws type
  */
 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 (sizeof($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->_getExceptionForWriteonly($normalized);
             }
             if (isset($this->{$property})) {
                 return $this->{$property};
             }
             return null;
         }
     }
     $setMatches = StringMethods::match($name, "^set([a-zA-Z0-9_]+)\$");
     if (sizeof($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->_getExceptionForReadonly($normalized);
             }
             $this->{$property} = $arguments[0];
             return $this;
         }
     }
     throw $this->_getExceptionForImplementation($name);
 }
Beispiel #2
0
 /**
  * Uses a fairly simple regular expression to match key/value pairs within the Doc Comment string returned by any of our _get…Meta() methods.
  * It does this using the StringMethods::match() method. It loops through all the matches, splitting them by key/value. If it finds no value component,
  * it sets the key to a value of true. This is useful for flag keys such as @readwrite or @once.
  * If it finds a value component, it splits the value by, and assigns an array of value parts to the key.
  * Finally, it returns the key/value(s) associative array.
  * 
  * @param type $comment string
  * @return type associative array
  */
 protected function _parse($comment)
 {
     $meta = array();
     $pattern = "(@[a-zA-Z]+\\s*[a-zA-Z0-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 (sizeof($parts) > 1) {
                 $meta[$parts[0]] = ArrayMethods::clean(ArrayMethods::trim(StringMethods::split($parts[1], ",")));
             }
         }
     }
     return $meta;
 }
Beispiel #3
0
 public function __call($name, $arguments)
 {
     $getMatches = StringMethods::match($name, "^get([a-zA-Z0-9]+)\$");
     if (sizeof($getMatches) > 0) {
         $normalized = lcfirst($getMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             return $this->{$property};
         }
     }
     $setMatches = StringMethods::match($name, "^set([a-zA-Z0-9]+)\$");
     if (sizeof($setMatches) > 0) {
         $normalized = lcfirst($setMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $this->{$property} = $arguments[0];
             return;
         }
     }
 }
Beispiel #4
0
 /**
  * Check the Inspector is set and handle and getProperty(),
  * setProperty() methods based upon metadata of defined properties
  * @param  string $name      Name of property to be inspected
  * @param  array $arguments Paramerters to be passed to property
  */
 public function __call($name, $arguments)
 {
     // Check class calls parent construct
     if (empty($this->_inspector)) {
         throw new \Exception("Call parent::_construct!");
     }
     // If reading permissable return property value
     $getMatches = StringMethods::match($name, "^get([a-zA-Z0-9]+)\$");
     if (sizeof($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->_getExceptionForWriteonly($normalized);
             }
             if (isset($this->{$property})) {
                 return $this->{$property};
             }
             return null;
         }
     }
     // If writing is permissable set property value
     $setMatches = StringMethods::match($name, "^set([a-zA-Z0-9]+)\$");
     if (sizeof($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->_getExceptionForReadonly($normalized);
             }
             $this->{$property} = $arguments[0];
             return $this;
         }
     }
     // If property does not exist in a class thow exception
     throw $this->_getExceptionForImplementation($name);
 }
Beispiel #5
0
 /**
  * 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, we extract the arguments.
  * We then run each validation method on the column data and generate error messages for those validation conditions that failed.
  * 
  * @return type
  * @throws Exception\Validation
  */
 public function validate()
 {
     $this->_errors = array();
     foreach ($this->columns as $column) {
         if ($column["validate"]) {
             $pattern = "#[a-z]+\\(([a-zA-Z0-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("The {$function} validator is not defined");
                 }
                 $template = $defined[$function];
                 if (!call_user_func_array(array($this, $template["handler"]), $arguments)) {
                     $replacements = array_merge(array($label ? $label : $raw), $arguments);
                     $message = $template["message"];
                     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 !sizeof($this->errors);
 }
Beispiel #6
0
 /**
  * Returns an array of objects
  * @return array|string Array of objects of \stdClass (success), Error Message (failure)
  */
 protected function _getSiteMaps(&$gClient, $website, $opts = array())
 {
     try {
         $webmaster = new Google_Service_Webmasters($gClient);
         $sitemaps = $webmaster->sitemaps;
         $response = $sitemaps->listSitemaps($website, $opts);
         $response = $response->getSitemap();
         $result = array();
         foreach ($response as $r) {
             $contents = $r->getContents();
             $content = array();
             foreach ($contents as $c) {
                 $content[] = array("type" => $c->type, "submitted" => $c->submitted, "indexed" => $c->indexed);
             }
             $result[] = array("path" => $r->path, "errors" => $r->errors, "pending" => $r->isPending, "type" => $r->type, "warnings" => $r->warnings, "lastDownloaded" => array_shift(StringMethods::match($r->lastDownloaded, "(.*)T")), "lastSubmitted" => array_shift(StringMethods::match($r->lastSubmitted, "(.*)T")), "contents" => $content);
         }
         $result = ArrayMethods::toObject($result);
     } catch (\Exception $e) {
         $result = $e->getMessage();
     }
     return $result;
 }
Beispiel #7
0
 /**
  * Validate that a given field passes regular expression check
  * @param  string $field      Field being validated
  * @param  mixed $value       Value being validated
  * @param  array $parameters  Regular expression to be matched
  * @return bool
  */
 protected function _validateMatch($field, $value, $parameters)
 {
     return StringMethods::match($value, $parameters[0]);
 }