code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
function generateAuthKey() { if (!class_exists('String')) { App::import('Core', 'String'); } return Security::hash(String::uuid()); }
Generate authorization hash. @return string Hash @access public @static
generateAuthKey
php
Datawalke/Coordino
cake/libs/security.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/security.php
MIT
function validateAuthKey($authKey) { return true; }
Validate authorization hash. @param string $authKey Authorization hash @return boolean Success @access public @static @todo Complete implementation
validateAuthKey
php
Datawalke/Coordino
cake/libs/security.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/security.php
MIT
function hash($string, $type = null, $salt = false) { $_this =& Security::getInstance(); if ($salt) { if (is_string($salt)) { $string = $salt . $string; } else { $string = Configure::read('Security.salt') . $string; } } if (empty($type)) { $type = $_this->hashType; } $type = strtolower($type); if ($type == 'sha1' || $type == null) { if (function_exists('sha1')) { $return = sha1($string); return $return; } $type = 'sha256'; } if ($type == 'sha256' && function_exists('mhash')) { return bin2hex(mhash(MHASH_SHA256, $string)); } if (function_exists('hash')) { return hash($type, $string); } return md5($string); }
Create a hash from string using given method. Fallback on next available method. @param string $string String to hash @param string $type Method to use (sha1/sha256/md5) @param boolean $salt If true, automatically appends the application's salt value to $string (Security.salt) @return string Hash @access public @static
hash
php
Datawalke/Coordino
cake/libs/security.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/security.php
MIT
function setHash($hash) { $_this =& Security::getInstance(); $_this->hashType = $hash; }
Sets the default hash method for the Security object. This affects all objects using Security::hash(). @param string $hash Method to use (sha1/sha256/md5) @access public @return void @static @see Security::hash()
setHash
php
Datawalke/Coordino
cake/libs/security.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/security.php
MIT
function cipher($text, $key) { if (empty($key)) { trigger_error(__('You cannot use an empty key for Security::cipher()', true), E_USER_WARNING); return ''; } srand(Configure::read('Security.cipherSeed')); $out = ''; $keyLength = strlen($key); for ($i = 0, $textLength = strlen($text); $i < $textLength; $i++) { $j = ord(substr($key, $i % $keyLength, 1)); while ($j--) { rand(0, 255); } $mask = rand(0, 255); $out .= chr(ord(substr($text, $i, 1)) ^ $mask); } srand(); return $out; }
Encrypts/Decrypts a text using the given key. @param string $text Encrypted string to decrypt, normal string to encrypt @param string $key Key to use @return string Encrypted/Decrypted string @access public @static
cipher
php
Datawalke/Coordino
cake/libs/security.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/security.php
MIT
function filter($var, $isArray = false) { if (is_array($var) && (!empty($var) || $isArray)) { return array_filter($var, array('Set', 'filter')); } if ($var === 0 || $var === '0' || !empty($var)) { return true; } return false; }
Filters empty elements out of a route array, excluding '0'. @param mixed $var Either an array to filter, or value when in callback @param boolean $isArray Force to tell $var is an array when $var is empty @return mixed Either filtered array, or true/false when in callback @access public @static
filter
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function pushDiff($array, $array2) { if (empty($array) && !empty($array2)) { return $array2; } if (!empty($array) && !empty($array2)) { foreach ($array2 as $key => $value) { if (!array_key_exists($key, $array)) { $array[$key] = $value; } else { if (is_array($value)) { $array[$key] = Set::pushDiff($array[$key], $array2[$key]); } } } } return $array; }
Pushes the differences in $array2 onto the end of $array @param mixed $array Original array @param mixed $array2 Differences to push @return array Combined array @access public @static
pushDiff
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function map($class = 'stdClass', $tmp = 'stdClass') { if (is_array($class)) { $val = $class; $class = $tmp; } if (empty($val)) { return null; } return Set::__map($val, $class); }
Maps the contents of the Set object to an object hierarchy. Maintains numeric keys as arrays of objects @param string $class A class name of the type of object to map to @param string $tmp A temporary class name used as $class if $class is an array @return object Hierarchical object @access public @static
map
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function __array($array) { if (empty($array)) { $array = array(); } elseif (is_object($array)) { $array = get_object_vars($array); } elseif (!is_array($array)) { $array = array($array); } return $array; }
Get the array value of $array. If $array is null, it will return the current array Set holds. If it is an object of type Set, it will return its value. If it is another object, its object variables. If it is anything else but an array, it will return an array whose first element is $array. @param mixed $array Data from where to get the array. @return array Array from $array. @access private
__array
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function __map(&$array, $class, $primary = false) { if ($class === true) { $out = new stdClass; } else { $out = new $class; } if (is_array($array)) { $keys = array_keys($array); foreach ($array as $key => $value) { if ($keys[0] === $key && $class !== true) { $primary = true; } if (is_numeric($key)) { if (is_object($out)) { $out = get_object_vars($out); } $out[$key] = Set::__map($value, $class); if (is_object($out[$key])) { if ($primary !== true && is_array($value) && Set::countDim($value, true) === 2) { if (!isset($out[$key]->_name_)) { $out[$key]->_name_ = $primary; } } } } elseif (is_array($value)) { if ($primary === true) { if (!isset($out->_name_)) { $out->_name_ = $key; } $primary = false; foreach ($value as $key2 => $value2) { $out->{$key2} = Set::__map($value2, true); } } else { if (!is_numeric($key)) { $out->{$key} = Set::__map($value, true, $key); if (is_object($out->{$key}) && !is_numeric($key)) { if (!isset($out->{$key}->_name_)) { $out->{$key}->_name_ = $key; } } } else { $out->{$key} = Set::__map($value, true); } } } else { $out->{$key} = $value; } } } else { $out = $array; } return $out; }
Maps the given value as an object. If $value is an object, it returns $value. Otherwise it maps $value as an object of type $class, and if primary assign _name_ $key on first array. If $value is not empty, it will be used to set properties of returned object (recursively). If $key is numeric will maintain array structure @param mixed $value Value to map @param string $class Class name @param boolean $primary whether to assign first array key as the _name_ @return mixed Mapped object @access private @static
__map
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function numeric($array = null) { if (empty($array)) { return null; } if ($array === range(0, count($array) - 1)) { return true; } $numeric = true; $keys = array_keys($array); $count = count($keys); for ($i = 0; $i < $count; $i++) { if (!is_numeric($array[$keys[$i]])) { $numeric = false; break; } } return $numeric; }
Checks to see if all the values in the array are numeric @param array $array The array to check. If null, the value of the current Set object @return boolean true if values are numeric, false otherwise @access public @static
numeric
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function enum($select, $list = null) { if (empty($list)) { $list = array('no', 'yes'); } $return = null; $list = Set::normalize($list, false); if (array_key_exists($select, $list)) { $return = $list[$select]; } return $return; }
Return a value from an array list if the key exists. If a comma separated $list is passed arrays are numeric with the key of the first being 0 $list = 'no, yes' would translate to $list = array(0 => 'no', 1 => 'yes'); If an array is used, keys can be strings example: array('no' => 0, 'yes' => 1); $list defaults to 0 = no 1 = yes if param is not passed @param mixed $select Key in $list to return @param mixed $list can be an array or a comma-separated list. @return string the value of the array key or null if no match @access public @static
enum
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function format($data, $format, $keys) { $extracted = array(); $count = count($keys); if (!$count) { return; } for ($i = 0; $i < $count; $i++) { $extracted[] = Set::extract($data, $keys[$i]); } $out = array(); $data = $extracted; $count = count($data[0]); if (preg_match_all('/\{([0-9]+)\}/msi', $format, $keys2) && isset($keys2[1])) { $keys = $keys2[1]; $format = preg_split('/\{([0-9]+)\}/msi', $format); $count2 = count($format); for ($j = 0; $j < $count; $j++) { $formatted = ''; for ($i = 0; $i <= $count2; $i++) { if (isset($format[$i])) { $formatted .= $format[$i]; } if (isset($keys[$i]) && isset($data[$keys[$i]][$j])) { $formatted .= $data[$keys[$i]][$j]; } } $out[] = $formatted; } } else { $count2 = count($data); for ($j = 0; $j < $count; $j++) { $args = array(); for ($i = 0; $i < $count2; $i++) { if (array_key_exists($j, $data[$i])) { $args[] = $data[$i][$j]; } } $out[] = vsprintf($format, $args); } } return $out; }
Returns a series of values extracted from an array, formatted in a format string. @param array $data Source array from which to extract the data @param string $format Format string into which values will be inserted, see sprintf() @param array $keys An array containing one or more Set::extract()-style key paths @return array An array of strings extracted from $keys and formatted with $format @access public @static
format
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function matches($conditions, $data = array(), $i = null, $length = null) { if (empty($conditions)) { return true; } if (is_string($conditions)) { return !!Set::extract($conditions, $data); } foreach ($conditions as $condition) { if ($condition === ':last') { if ($i != $length) { return false; } continue; } elseif ($condition === ':first') { if ($i != 1) { return false; } continue; } if (!preg_match('/(.+?)([><!]?[=]|[><])(.*)/', $condition, $match)) { if (ctype_digit($condition)) { if ($i != $condition) { return false; } } elseif (preg_match_all('/(?:^[0-9]+|(?<=,)[0-9]+)/', $condition, $matches)) { return in_array($i, $matches[0]); } elseif (!array_key_exists($condition, $data)) { return false; } continue; } list(,$key,$op,$expected) = $match; if (!isset($data[$key])) { return false; } $val = $data[$key]; if ($op === '=' && $expected && $expected{0} === '/') { return preg_match($expected, $val); } if ($op === '=' && $val != $expected) { return false; } if ($op === '!=' && $val == $expected) { return false; } if ($op === '>' && $val <= $expected) { return false; } if ($op === '<' && $val >= $expected) { return false; } if ($op === '<=' && $val > $expected) { return false; } if ($op === '>=' && $val < $expected) { return false; } } return true; }
This function can be used to see if a single item or a given xpath match certain conditions. @param mixed $conditions An array of condition strings or an XPath expression @param array $data An array of data to execute the match on @param integer $i Optional: The 'nth'-number of the item being matched. @return boolean @access public @static
matches
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function classicExtract($data, $path = null) { if (empty($path)) { return $data; } if (is_object($data)) { $data = get_object_vars($data); } if (!is_array($data)) { return $data; } if (!is_array($path)) { if (!class_exists('String')) { App::import('Core', 'String'); } $path = String::tokenize($path, '.', '{', '}'); } $tmp = array(); if (!is_array($path) || empty($path)) { return null; } foreach ($path as $i => $key) { if (is_numeric($key) && intval($key) > 0 || $key === '0') { if (isset($data[intval($key)])) { $data = $data[intval($key)]; } else { return null; } } elseif ($key === '{n}') { foreach ($data as $j => $val) { if (is_int($j)) { $tmpPath = array_slice($path, $i + 1); if (empty($tmpPath)) { $tmp[] = $val; } else { $tmp[] = Set::classicExtract($val, $tmpPath); } } } return $tmp; } elseif ($key === '{s}') { foreach ($data as $j => $val) { if (is_string($j)) { $tmpPath = array_slice($path, $i + 1); if (empty($tmpPath)) { $tmp[] = $val; } else { $tmp[] = Set::classicExtract($val, $tmpPath); } } } return $tmp; } elseif (false !== strpos($key,'{') && false !== strpos($key,'}')) { $pattern = substr($key, 1, -1); foreach ($data as $j => $val) { if (preg_match('/^'.$pattern.'/s', $j) !== 0) { $tmpPath = array_slice($path, $i + 1); if (empty($tmpPath)) { $tmp[$j] = $val; } else { $tmp[$j] = Set::classicExtract($val, $tmpPath); } } } return $tmp; } else { if (isset($data[$key])) { $data = $data[$key]; } else { return null; } } } return $data; }
Gets a value from an array or object that is contained in a given path using an array path syntax, i.e.: "{n}.Person.{[a-z]+}" - Where "{n}" represents a numeric key, "Person" represents a string literal, and "{[a-z]+}" (i.e. any string literal enclosed in brackets besides {n} and {s}) is interpreted as a regular expression. @param array $data Array from where to extract @param mixed $path As an array, or as a dot-separated string. @return array Extracted data @access public @static
classicExtract
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function insert($list, $path, $data = null) { if (!is_array($path)) { $path = explode('.', $path); } $_list =& $list; foreach ($path as $i => $key) { if (is_numeric($key) && intval($key) > 0 || $key === '0') { $key = intval($key); } if ($i === count($path) - 1) { $_list[$key] = $data; } else { if (!isset($_list[$key])) { $_list[$key] = array(); } $_list =& $_list[$key]; } if (!is_array($_list)) { return array(); } } return $list; }
Inserts $data into an array as defined by $path. @param mixed $list Where to insert into @param mixed $path A dot-separated string. @param array $data Data to insert @return array @access public @static
insert
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function remove($list, $path = null) { if (empty($path)) { return $list; } if (!is_array($path)) { $path = explode('.', $path); } $_list =& $list; foreach ($path as $i => $key) { if (is_numeric($key) && intval($key) > 0 || $key === '0') { $key = intval($key); } if ($i === count($path) - 1) { unset($_list[$key]); } else { if (!isset($_list[$key])) { return $list; } $_list =& $_list[$key]; } } return $list; }
Removes an element from a Set or array as defined by $path. @param mixed $list From where to remove @param mixed $path A dot-separated string. @return array Array with $path removed from its value @access public @static
remove
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function check($data, $path = null) { if (empty($path)) { return $data; } if (!is_array($path)) { $path = explode('.', $path); } foreach ($path as $i => $key) { if (is_numeric($key) && intval($key) > 0 || $key === '0') { $key = intval($key); } if ($i === count($path) - 1) { return (is_array($data) && array_key_exists($key, $data)); } if (!is_array($data) || !array_key_exists($key, $data)) { return false; } $data =& $data[$key]; } return true; }
Checks if a particular path is set in an array @param mixed $data Data to check on @param mixed $path A dot-separated string. @return boolean true if path is found, false otherwise @access public @static
check
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function diff($val1, $val2 = null) { if (empty($val1)) { return (array)$val2; } if (empty($val2)) { return (array)$val1; } $intersection = array_intersect_key($val1, $val2); while (($key = key($intersection)) !== null) { if ($val1[$key] == $val2[$key]) { unset($val1[$key]); unset($val2[$key]); } next($intersection); } return $val1 + $val2; }
Computes the difference between a Set and an array, two Sets, or two arrays @param mixed $val1 First value @param mixed $val2 Second value @return array Returns the key => value pairs that are not common in $val1 and $val2 The expression for this function is ($val1 - $val2) + ($val2 - ($val1 - $val2)) @access public @static
diff
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function contains($val1, $val2 = null) { if (empty($val1) || empty($val2)) { return false; } foreach ($val2 as $key => $val) { if (is_numeric($key)) { Set::contains($val, $val1); } else { if (!isset($val1[$key]) || $val1[$key] != $val) { return false; } } } return true; }
Determines if one Set or array contains the exact keys and values of another. @param array $val1 First value @param array $val2 Second value @return boolean true if $val1 contains $val2, false otherwise @access public @static
contains
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function countDim($array = null, $all = false, $count = 0) { if ($all) { $depth = array($count); if (is_array($array) && reset($array) !== false) { foreach ($array as $value) { $depth[] = Set::countDim($value, true, $count + 1); } } $return = max($depth); } else { if (is_array(reset($array))) { $return = Set::countDim(reset($array)) + 1; } else { $return = 1; } } return $return; }
Counts the dimensions of an array. If $all is set to false (which is the default) it will only consider the dimension of the first element in the array. @param array $array Array to count dimensions on @param boolean $all Set to true to count the dimension considering all elements in array @param integer $count Start the dimension count at this number @return integer The number of dimensions in $array @access public @static
countDim
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function normalize($list, $assoc = true, $sep = ',', $trim = true) { if (is_string($list)) { $list = explode($sep, $list); if ($trim) { foreach ($list as $key => $value) { $list[$key] = trim($value); } } if ($assoc) { return Set::normalize($list); } } elseif (is_array($list)) { $keys = array_keys($list); $count = count($keys); $numeric = true; if (!$assoc) { for ($i = 0; $i < $count; $i++) { if (!is_int($keys[$i])) { $numeric = false; break; } } } if (!$numeric || $assoc) { $newList = array(); for ($i = 0; $i < $count; $i++) { if (is_int($keys[$i])) { $newList[$list[$keys[$i]]] = null; } else { $newList[$keys[$i]] = $list[$keys[$i]]; } } $list = $newList; } } return $list; }
Normalizes a string or array list. @param mixed $list List to normalize @param boolean $assoc If true, $list will be converted to an associative array @param string $sep If $list is a string, it will be split into an array with $sep @param boolean $trim If true, separated strings will be trimmed @return array @access public @static
normalize
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function combine($data, $path1 = null, $path2 = null, $groupPath = null) { if (empty($data)) { return array(); } if (is_object($data)) { $data = get_object_vars($data); } if (is_array($path1)) { $format = array_shift($path1); $keys = Set::format($data, $format, $path1); } else { $keys = Set::extract($data, $path1); } if (empty($keys)) { return array(); } if (!empty($path2) && is_array($path2)) { $format = array_shift($path2); $vals = Set::format($data, $format, $path2); } elseif (!empty($path2)) { $vals = Set::extract($data, $path2); } else { $count = count($keys); for ($i = 0; $i < $count; $i++) { $vals[$i] = null; } } if ($groupPath != null) { $group = Set::extract($data, $groupPath); if (!empty($group)) { $c = count($keys); for ($i = 0; $i < $c; $i++) { if (!isset($group[$i])) { $group[$i] = 0; } if (!isset($out[$group[$i]])) { $out[$group[$i]] = array(); } $out[$group[$i]][$keys[$i]] = $vals[$i]; } return $out; } } if (empty($vals)) { return array(); } return array_combine($keys, $vals); }
Creates an associative array using a $path1 as the path to build its keys, and optionally $path2 as path to get the values. If $path2 is not specified, all values will be initialized to null (useful for Set::merge). You can optionally group the values by what is obtained when following the path specified in $groupPath. @param mixed $data Array or object from where to extract keys and values @param mixed $path1 As an array, or as a dot-separated string. @param mixed $path2 As an array, or as a dot-separated string. @param string $groupPath As an array, or as a dot-separated string. @return array Combined array @access public @static
combine
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function reverse($object) { $out = array(); if (is_a($object, 'XmlNode')) { $out = $object->toArray(); return $out; } else if (is_object($object)) { $keys = get_object_vars($object); if (isset($keys['_name_'])) { $identity = $keys['_name_']; unset($keys['_name_']); } $new = array(); foreach ($keys as $key => $value) { if (is_array($value)) { $new[$key] = (array)Set::reverse($value); } else { if (isset($value->_name_)) { $new = array_merge($new, Set::reverse($value)); } else { $new[$key] = Set::reverse($value); } } } if (isset($identity)) { $out[$identity] = $new; } else { $out = $new; } } elseif (is_array($object)) { foreach ($object as $key => $value) { $out[$key] = Set::reverse($value); } } else { $out = $object; } return $out; }
Converts an object into an array. @param object $object Object to reverse @return array Array representation of given object @public @static
reverse
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function __flatten($results, $key = null) { $stack = array(); foreach ($results as $k => $r) { $id = $k; if (!is_null($key)) { $id = $key; } if (is_array($r) && !empty($r)) { $stack = array_merge($stack, Set::__flatten($r, $id)); } else { $stack[] = array('id' => $id, 'value' => $r); } } return $stack; }
Flattens an array for sorting @param array $results @param string $key @return array @access private
__flatten
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function sort($data, $path, $dir) { $originalKeys = array_keys($data); if (is_numeric(implode('', $originalKeys))) { $data = array_values($data); } $result = Set::__flatten(Set::extract($data, $path)); list($keys, $values) = array(Set::extract($result, '{n}.id'), Set::extract($result, '{n}.value')); $dir = strtolower($dir); if ($dir === 'asc') { $dir = SORT_ASC; } elseif ($dir === 'desc') { $dir = SORT_DESC; } array_multisort($values, $dir, $keys, $dir); $sorted = array(); $keys = array_unique($keys); foreach ($keys as $k) { $sorted[] = $data[$k]; } return $sorted; }
Sorts an array by any value, determined by a Set-compatible path @param array $data An array of data to sort @param string $path A Set-compatible path to the array value @param string $dir Direction of sorting - either ascending (ASC), or descending (DESC) @return array Sorted array of data @static
sort
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function apply($path, $data, $callback, $options = array()) { $defaults = array('type' => 'pass'); $options = array_merge($defaults, $options); $extracted = Set::extract($path, $data); if ($options['type'] === 'map') { $result = array_map($callback, $extracted); } elseif ($options['type'] === 'reduce') { $result = array_reduce($extracted, $callback); } elseif ($options['type'] === 'pass') { $result = call_user_func_array($callback, array($extracted)); } else { return null; } return $result; }
Allows the application of a callback method to elements of an array extracted by a Set::extract() compatible path. @param mixed $path Set-compatible path to the array value @param array $data An array of data to extract from & then process with the $callback. @param mixed $callback Callback method to be applied to extracted data. See http://ca2.php.net/manual/en/language.pseudo-types.php#language.types.callback for examples of callback formats. @param array $options Options are: - type : can be pass, map, or reduce. Map will handoff the given callback to array_map, reduce will handoff to array_reduce, and pass will use call_user_func_array(). @return mixed Result of the callback when applied to extracted data @access public @static
apply
php
Datawalke/Coordino
cake/libs/set.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/set.php
MIT
function uuid() { $node = env('SERVER_ADDR'); $pid = null; if (strpos($node, ':') !== false) { if (substr_count($node, '::')) { $node = str_replace( '::', str_repeat(':0000', 8 - substr_count($node, ':')) . ':', $node ); } $node = explode(':', $node) ; $ipv6 = '' ; foreach ($node as $id) { $ipv6 .= str_pad(base_convert($id, 16, 2), 16, 0, STR_PAD_LEFT); } $node = base_convert($ipv6, 2, 10); if (strlen($node) < 38) { $node = null; } else { $node = crc32($node); } } elseif (empty($node)) { $host = env('HOSTNAME'); if (empty($host)) { $host = env('HOST'); } if (!empty($host)) { $ip = gethostbyname($host); if ($ip === $host) { $node = crc32($host); } else { $node = ip2long($ip); } } } elseif ($node !== '127.0.0.1') { $node = ip2long($node); } else { $node = null; } if (empty($node)) { $node = crc32(Configure::read('Security.salt')); } if (function_exists('zend_thread_id')) { $pid = zend_thread_id(); } else { $pid = getmypid(); } if (!$pid || $pid > 65535) { $pid = mt_rand(0, 0xfff) | 0x4000; } list($timeMid, $timeLow) = explode(' ', microtime()); $uuid = sprintf( "%08x-%04x-%04x-%02x%02x-%04x%08x", (int)$timeLow, (int)substr($timeMid, 2) & 0xffff, mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3f) | 0x80, mt_rand(0, 0xff), $pid, $node ); return $uuid; }
Generate a random UUID @see http://www.ietf.org/rfc/rfc4122.txt @return RFC 4122 UUID @static
uuid
php
Datawalke/Coordino
cake/libs/string.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/string.php
MIT
function tokenize($data, $separator = ',', $leftBound = '(', $rightBound = ')') { if (empty($data) || is_array($data)) { return $data; } $depth = 0; $offset = 0; $buffer = ''; $results = array(); $length = strlen($data); $open = false; while ($offset <= $length) { $tmpOffset = -1; $offsets = array( strpos($data, $separator, $offset), strpos($data, $leftBound, $offset), strpos($data, $rightBound, $offset) ); for ($i = 0; $i < 3; $i++) { if ($offsets[$i] !== false && ($offsets[$i] < $tmpOffset || $tmpOffset == -1)) { $tmpOffset = $offsets[$i]; } } if ($tmpOffset !== -1) { $buffer .= substr($data, $offset, ($tmpOffset - $offset)); if ($data{$tmpOffset} == $separator && $depth == 0) { $results[] = $buffer; $buffer = ''; } else { $buffer .= $data{$tmpOffset}; } if ($leftBound != $rightBound) { if ($data{$tmpOffset} == $leftBound) { $depth++; } if ($data{$tmpOffset} == $rightBound) { $depth--; } } else { if ($data{$tmpOffset} == $leftBound) { if (!$open) { $depth++; $open = true; } else { $depth--; $open = false; } } } $offset = ++$tmpOffset; } else { $results[] = $buffer . substr($data, $offset); $offset = $length + 1; } } if (empty($results) && !empty($buffer)) { $results[] = $buffer; } if (!empty($results)) { $data = array_map('trim', $results); } else { $data = array(); } return $data; } /** * Replaces variable placeholders inside a $str with any given $data. Each key in the $data array * corresponds to a variable placeholder name in $str. * Example: `String::insert(':name is :age years old.', array('name' => 'Bob', '65'));` * Returns: Bob is 65 years old. * * Available $options are: * * - before: The character or string in front of the name of the variable placeholder (Defaults to `:`) * - after: The character or string after the name of the variable placeholder (Defaults to null) * - escape: The character or string used to escape the before character / string (Defaults to `\`) * - format: A regex to use for matching variable placeholders. Default is: `/(?<!\\)\:%s/` * (Overwrites before, after, breaks escape / clean) * - clean: A boolean or array with instructions for String::cleanInsert * * @param string $str A string containing variable placeholders * @param string $data A key => val array where each key stands for a placeholder variable name * to be replaced with val * @param string $options An array of options, see description above * @return string * @access public * @static */ function insert($str, $data, $options = array()) { $defaults = array( 'before' => ':', 'after' => null, 'escape' => '\\', 'format' => null, 'clean' => false ); $options += $defaults; $format = $options['format']; $data = (array)$data; if (empty($data)) { return ($options['clean']) ? String::cleanInsert($str, $options) : $str; } if (!isset($format)) { $format = sprintf( '/(?<!%s)%s%%s%s/', preg_quote($options['escape'], '/'), str_replace('%', '%%', preg_quote($options['before'], '/')), str_replace('%', '%%', preg_quote($options['after'], '/')) ); } if (strpos($str, '?') !== false && is_numeric(key($data))) { $offset = 0; while (($pos = strpos($str, '?', $offset)) !== false) { $val = array_shift($data); $offset = $pos + strlen($val); $str = substr_replace($str, $val, $pos, 1); } return ($options['clean']) ? String::cleanInsert($str, $options) : $str; } else { asort($data); $hashKeys = array(); foreach ($data as $key => $value) { $hashKeys[] = crc32($key); } $tempData = array_combine(array_keys($data), array_values($hashKeys)); krsort($tempData); foreach ($tempData as $key => $hashVal) { $key = sprintf($format, preg_quote($key, '/')); $str = preg_replace($key, $hashVal, $str); } $dataReplacements = array_combine($hashKeys, array_values($data)); foreach ($dataReplacements as $tmpHash => $tmpValue) { $tmpValue = (is_array($tmpValue)) ? '' : $tmpValue; $str = str_replace($tmpHash, $tmpValue, $str); } } if (!isset($options['format']) && isset($options['before'])) { $str = str_replace($options['escape'].$options['before'], $options['before'], $str); } return ($options['clean']) ? String::cleanInsert($str, $options) : $str; } /** * Cleans up a String::insert() formated string with given $options depending on the 'clean' key in * $options. The default method used is text but html is also available. The goal of this function * is to replace all whitespace and uneeded markup around placeholders that did not get replaced * by String::insert(). * * @param string $str * @param string $options * @return string * @access public * @static * @see String::insert() */ function cleanInsert($str, $options) { $clean = $options['clean']; if (!$clean) { return $str; } if ($clean === true) { $clean = array('method' => 'text'); } if (!is_array($clean)) { $clean = array('method' => $options['clean']); } switch ($clean['method']) { case 'html': $clean = array_merge(array( 'word' => '[\w,.]+', 'andText' => true, 'replacement' => '', ), $clean); $kleenex = sprintf( '/[\s]*[a-z]+=(")(%s%s%s[\s]*)+\\1/i', preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/') ); $str = preg_replace($kleenex, $clean['replacement'], $str); if ($clean['andText']) { $options['clean'] = array('method' => 'text'); $str = String::cleanInsert($str, $options); } break; case 'text': $clean = array_merge(array( 'word' => '[\w,.]+', 'gap' => '[\s]*(?:(?:and|or)[\s]*)?', 'replacement' => '', ), $clean); $kleenex = sprintf( '/(%s%s%s%s|%s%s%s%s)/', preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/'), $clean['gap'], $clean['gap'], preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/') ); $str = preg_replace($kleenex, $clean['replacement'], $str); break; } return $str; } }
Tokenizes a string using $separator, ignoring any instance of $separator that appears between $leftBound and $rightBound @param string $data The data to tokenize @param string $separator The token to split the data on. @param string $leftBound The left boundary to ignore separators in. @param string $rightBound The right boundary to ignore separators in. @return array Array of tokens in $data. @access public @static
tokenize
php
Datawalke/Coordino
cake/libs/string.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/string.php
MIT
function insert($str, $data, $options = array()) { $defaults = array( 'before' => ':', 'after' => null, 'escape' => '\\', 'format' => null, 'clean' => false ); $options += $defaults; $format = $options['format']; $data = (array)$data; if (empty($data)) { return ($options['clean']) ? String::cleanInsert($str, $options) : $str; } if (!isset($format)) { $format = sprintf( '/(?<!%s)%s%%s%s/', preg_quote($options['escape'], '/'), str_replace('%', '%%', preg_quote($options['before'], '/')), str_replace('%', '%%', preg_quote($options['after'], '/')) ); } if (strpos($str, '?') !== false && is_numeric(key($data))) { $offset = 0; while (($pos = strpos($str, '?', $offset)) !== false) { $val = array_shift($data); $offset = $pos + strlen($val); $str = substr_replace($str, $val, $pos, 1); } return ($options['clean']) ? String::cleanInsert($str, $options) : $str; } else { asort($data); $hashKeys = array(); foreach ($data as $key => $value) { $hashKeys[] = crc32($key); } $tempData = array_combine(array_keys($data), array_values($hashKeys)); krsort($tempData); foreach ($tempData as $key => $hashVal) { $key = sprintf($format, preg_quote($key, '/')); $str = preg_replace($key, $hashVal, $str); } $dataReplacements = array_combine($hashKeys, array_values($data)); foreach ($dataReplacements as $tmpHash => $tmpValue) { $tmpValue = (is_array($tmpValue)) ? '' : $tmpValue; $str = str_replace($tmpHash, $tmpValue, $str); } } if (!isset($options['format']) && isset($options['before'])) { $str = str_replace($options['escape'].$options['before'], $options['before'], $str); } return ($options['clean']) ? String::cleanInsert($str, $options) : $str; }
Replaces variable placeholders inside a $str with any given $data. Each key in the $data array corresponds to a variable placeholder name in $str. Example: `String::insert(':name is :age years old.', array('name' => 'Bob', '65'));` Returns: Bob is 65 years old. Available $options are: - before: The character or string in front of the name of the variable placeholder (Defaults to `:`) - after: The character or string after the name of the variable placeholder (Defaults to null) - escape: The character or string used to escape the before character / string (Defaults to `\`) - format: A regex to use for matching variable placeholders. Default is: `/(?<!\\)\:%s/` (Overwrites before, after, breaks escape / clean) - clean: A boolean or array with instructions for String::cleanInsert @param string $str A string containing variable placeholders @param string $data A key => val array where each key stands for a placeholder variable name to be replaced with val @param string $options An array of options, see description above @return string @access public @static
insert
php
Datawalke/Coordino
cake/libs/string.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/string.php
MIT
function cleanInsert($str, $options) { $clean = $options['clean']; if (!$clean) { return $str; } if ($clean === true) { $clean = array('method' => 'text'); } if (!is_array($clean)) { $clean = array('method' => $options['clean']); } switch ($clean['method']) { case 'html': $clean = array_merge(array( 'word' => '[\w,.]+', 'andText' => true, 'replacement' => '', ), $clean); $kleenex = sprintf( '/[\s]*[a-z]+=(")(%s%s%s[\s]*)+\\1/i', preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/') ); $str = preg_replace($kleenex, $clean['replacement'], $str); if ($clean['andText']) { $options['clean'] = array('method' => 'text'); $str = String::cleanInsert($str, $options); } break; case 'text': $clean = array_merge(array( 'word' => '[\w,.]+', 'gap' => '[\s]*(?:(?:and|or)[\s]*)?', 'replacement' => '', ), $clean); $kleenex = sprintf( '/(%s%s%s%s|%s%s%s%s)/', preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/'), $clean['gap'], $clean['gap'], preg_quote($options['before'], '/'), $clean['word'], preg_quote($options['after'], '/') ); $str = preg_replace($kleenex, $clean['replacement'], $str); break; } return $str; }
Cleans up a String::insert() formated string with given $options depending on the 'clean' key in $options. The default method used is text but html is also available. The goal of this function is to replace all whitespace and uneeded markup around placeholders that did not get replaced by String::insert(). @param string $str @param string $options @return string @access public @static @see String::insert()
cleanInsert
php
Datawalke/Coordino
cake/libs/string.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/string.php
MIT
function &getInstance() { static $instance = array(); if (!$instance) { $instance[0] =& new Validation(); } return $instance[0]; }
Gets a reference to the Validation object instance @return object Validation instance @access public @static
getInstance
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function notEmpty($check) { $_this =& Validation::getInstance(); $_this->__reset(); $_this->check = $check; if (is_array($check)) { $_this->_extract($check); } if (empty($_this->check) && $_this->check != '0') { return false; } $_this->regex = '/[^\s]+/m'; return $_this->_check(); }
Checks that a string contains something other than whitespace Returns true if string contains something other than whitespace $check can be passed as an array: array('check' => 'valueToCheck'); @param mixed $check Value to check @return boolean Success @access public
notEmpty
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function alphaNumeric($check) { $_this =& Validation::getInstance(); $_this->__reset(); $_this->check = $check; if (is_array($check)) { $_this->_extract($check); } if (empty($_this->check) && $_this->check != '0') { return false; } $_this->regex = '/^[\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]+$/mu'; return $_this->_check(); }
Checks that a string contains only integer or letters Returns true if string contains only integer or letters $check can be passed as an array: array('check' => 'valueToCheck'); @param mixed $check Value to check @return boolean Success @access public
alphaNumeric
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function between($check, $min, $max) { $length = mb_strlen($check); return ($length >= $min && $length <= $max); }
Checks that a string length is within s specified range. Spaces are included in the character count. Returns true is string matches value min, max, or between min and max, @param string $check Value to check for length @param integer $min Minimum value in range (inclusive) @param integer $max Maximum value in range (inclusive) @return boolean Success @access public
between
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function blank($check) { $_this =& Validation::getInstance(); $_this->__reset(); $_this->check = $check; if (is_array($check)) { $_this->_extract($check); } $_this->regex = '/[^\\s]/'; return !$_this->_check(); }
Returns true if field is left blank -OR- only whitespace characters are present in it's value Whitespace characters include Space, Tab, Carriage Return, Newline $check can be passed as an array: array('check' => 'valueToCheck'); @param mixed $check Value to check @return boolean Success @access public
blank
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function cc($check, $type = 'fast', $deep = false, $regex = null) { $_this =& Validation::getInstance(); $_this->__reset(); $_this->check = $check; $_this->type = $type; $_this->deep = $deep; $_this->regex = $regex; if (is_array($check)) { $_this->_extract($check); } $_this->check = str_replace(array('-', ' '), '', $_this->check); if (mb_strlen($_this->check) < 13) { return false; } if (!is_null($_this->regex)) { if ($_this->_check()) { return $_this->_luhn(); } } $cards = array( 'all' => array( 'amex' => '/^3[4|7]\\d{13}$/', 'bankcard' => '/^56(10\\d\\d|022[1-5])\\d{10}$/', 'diners' => '/^(?:3(0[0-5]|[68]\\d)\\d{11})|(?:5[1-5]\\d{14})$/', 'disc' => '/^(?:6011|650\\d)\\d{12}$/', 'electron' => '/^(?:417500|4917\\d{2}|4913\\d{2})\\d{10}$/', 'enroute' => '/^2(?:014|149)\\d{11}$/', 'jcb' => '/^(3\\d{4}|2100|1800)\\d{11}$/', 'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/', 'mc' => '/^5[1-5]\\d{14}$/', 'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/', 'switch' => '/^(?:49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})\\d{10}(\\d{2,3})?)|(?:564182\\d{10}(\\d{2,3})?)|(6(3(33[0-4][0-9])|759[0-9]{2})\\d{10}(\\d{2,3})?)$/', 'visa' => '/^4\\d{12}(\\d{3})?$/', 'voyager' => '/^8699[0-9]{11}$/' ), 'fast' => '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/' ); if (is_array($_this->type)) { foreach ($_this->type as $value) { $_this->regex = $cards['all'][strtolower($value)]; if ($_this->_check()) { return $_this->_luhn(); } } } elseif ($_this->type == 'all') { foreach ($cards['all'] as $value) { $_this->regex = $value; if ($_this->_check()) { return $_this->_luhn(); } } } else { $_this->regex = $cards['fast']; if ($_this->_check()) { return $_this->_luhn(); } } }
Validation of credit card numbers. Returns true if $check is in the proper credit card format. @param mixed $check credit card number to validate @param mixed $type 'all' may be passed as a sting, defaults to fast which checks format of most major credit cards if an array is used only the values of the array are checked. Example: array('amex', 'bankcard', 'maestro') @param boolean $deep set to true this will check the Luhn algorithm of the credit card. @param string $regex A custom regex can also be passed, this will be used instead of the defined regex values @return boolean Success @access public @see Validation::_luhn()
cc
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function comparison($check1, $operator = null, $check2 = null) { if (is_array($check1)) { extract($check1, EXTR_OVERWRITE); } $operator = str_replace(array(' ', "\t", "\n", "\r", "\0", "\x0B"), '', strtolower($operator)); switch ($operator) { case 'isgreater': case '>': if ($check1 > $check2) { return true; } break; case 'isless': case '<': if ($check1 < $check2) { return true; } break; case 'greaterorequal': case '>=': if ($check1 >= $check2) { return true; } break; case 'lessorequal': case '<=': if ($check1 <= $check2) { return true; } break; case 'equalto': case '==': if ($check1 == $check2) { return true; } break; case 'notequal': case '!=': if ($check1 != $check2) { return true; } break; default: $_this =& Validation::getInstance(); $_this->errors[] = __('You must define the $operator parameter for Validation::comparison()', true); break; } return false; }
Used to compare 2 numeric values. @param mixed $check1 if string is passed for a string must also be passed for $check2 used as an array it must be passed as array('check1' => value, 'operator' => 'value', 'check2' -> value) @param string $operator Can be either a word or operand is greater >, is less <, greater or equal >= less or equal <=, is less <, equal to ==, not equal != @param integer $check2 only needed if $check1 is a string @return boolean Success @access public
comparison
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function custom($check, $regex = null) { $_this =& Validation::getInstance(); $_this->__reset(); $_this->check = $check; $_this->regex = $regex; if (is_array($check)) { $_this->_extract($check); } if ($_this->regex === null) { $_this->errors[] = __('You must define a regular expression for Validation::custom()', true); return false; } return $_this->_check(); }
Used when a custom regular expression is needed. @param mixed $check When used as a string, $regex must also be a valid regular expression. As and array: array('check' => value, 'regex' => 'valid regular expression') @param string $regex If $check is passed as a string, $regex must also be set to valid regular expression @return boolean Success @access public
custom
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function date($check, $format = 'ymd', $regex = null) { $_this =& Validation::getInstance(); $_this->__reset(); $_this->check = $check; $_this->regex = $regex; if (!is_null($_this->regex)) { return $_this->_check(); } $regex['dmy'] = '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)(\\/|-|\\.|\\x20)(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29(\\/|-|\\.|\\x20)0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\\d|2[0-8])(\\/|-|\\.|\\x20)(?:(?:0?[1-9])|(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%'; $regex['mdy'] = '%^(?:(?:(?:0?[13578]|1[02])(\\/|-|\\.|\\x20)31)\\1|(?:(?:0?[13-9]|1[0-2])(\\/|-|\\.|\\x20)(?:29|30)\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:0?2(\\/|-|\\.|\\x20)29\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\\/|-|\\.|\\x20)(?:0?[1-9]|1\\d|2[0-8])\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%'; $regex['ymd'] = '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\\/|-|\\.|\\x20)(?:0?2\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\d)?\\d{2})(\\/|-|\\.|\\x20)(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]))))$%'; $regex['dMy'] = '/^((31(?!\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\b|t)t?|Nov)(ember)?)))|((30|29)(?!\\ Feb(ruary)?))|(29(?=\\ Feb(ruary)?\\ (((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])\\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)\\ ((1[6-9]|[2-9]\\d)\\d{2})$/'; $regex['Mdy'] = '/^(?:(((Jan(uary)?|Ma(r(ch)?|y)|Jul(y)?|Aug(ust)?|Oct(ober)?|Dec(ember)?)\\ 31)|((Jan(uary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep)(tember)?|(Nov|Dec)(ember)?)\\ (0?[1-9]|([12]\\d)|30))|(Feb(ruary)?\\ (0?[1-9]|1\\d|2[0-8]|(29(?=,?\\ ((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))))\\,?\\ ((1[6-9]|[2-9]\\d)\\d{2}))$/'; $regex['My'] = '%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)[ /]((1[6-9]|[2-9]\\d)\\d{2})$%'; $regex['my'] = '%^(((0[123456789]|10|11|12)([- /.])(([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))))$%'; $format = (is_array($format)) ? array_values($format) : array($format); foreach ($format as $key) { $_this->regex = $regex[$key]; if ($_this->_check() === true) { return true; } } return false; }
Date validation, determines if the string passed is a valid date. keys that expect full month, day and year will validate leap years @param string $check a valid date string @param mixed $format Use a string or an array of the keys below. Arrays should be passed as array('dmy', 'mdy', etc) Keys: dmy 27-12-2006 or 27-12-06 separators can be a space, period, dash, forward slash mdy 12-27-2006 or 12-27-06 separators can be a space, period, dash, forward slash ymd 2006-12-27 or 06-12-27 separators can be a space, period, dash, forward slash dMy 27 December 2006 or 27 Dec 2006 Mdy December 27, 2006 or Dec 27, 2006 comma is optional My December 2006 or Dec 2006 my 12/2006 separators can be a space, period, dash, forward slash @param string $regex If a custom regular expression is used this is the only validation that will occur. @return boolean Success @access public
date
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function time($check) { $_this =& Validation::getInstance(); $_this->__reset(); $_this->check = $check; $_this->regex = '%^((0?[1-9]|1[012])(:[0-5]\d){0,2} ?([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%'; return $_this->_check(); }
Time validation, determines if the string passed is a valid time. Validates time as 24hr (HH:MM) or am/pm ([H]H:MM[a|p]m) Does not allow/validate seconds. @param string $check a valid time string @return boolean Success @access public
time
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function boolean($check) { $booleanList = array(0, 1, '0', '1', true, false); return in_array($check, $booleanList, true); }
Boolean validation, determines if value passed is a boolean integer or true/false. @param string $check a valid boolean @return boolean Success @access public
boolean
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function decimal($check, $places = null, $regex = null) { $_this =& Validation::getInstance(); $_this->__reset(); $_this->regex = $regex; $_this->check = $check; if (is_null($_this->regex)) { if (is_null($places)) { $_this->regex = '/^[-+]?[0-9]*\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/'; } else { $_this->regex = '/^[-+]?[0-9]*\\.{1}[0-9]{'.$places.'}$/'; } } return $_this->_check(); }
Checks that a value is a valid decimal. If $places is null, the $check is allowed to be a scientific float If no decimal point is found a false will be returned. Both the sign and exponent are optional. @param integer $check The value the test for decimal @param integer $places if set $check value must have exactly $places after the decimal point @param string $regex If a custom regular expression is used this is the only validation that will occur. @return boolean Success @access public
decimal
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function email($check, $deep = false, $regex = null) { $_this =& Validation::getInstance(); $_this->__reset(); $_this->check = $check; $_this->regex = $regex; $_this->deep = $deep; if (is_array($check)) { $_this->_extract($check); } if (is_null($_this->regex)) { $_this->regex = '/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@' . $_this->__pattern['hostname'] . '$/i'; } $return = $_this->_check(); if ($_this->deep === false || $_this->deep === null) { return $return; } if ($return === true && preg_match('/@(' . $_this->__pattern['hostname'] . ')$/i', $_this->check, $regs)) { if (function_exists('getmxrr') && getmxrr($regs[1], $mxhosts)) { return true; } if (function_exists('checkdnsrr') && checkdnsrr($regs[1], 'MX')) { return true; } return is_array(gethostbynamel($regs[1])); } return false; }
Validates for an email address. @param string $check Value to check @param boolean $deep Perform a deeper validation (if true), by also checking availability of host @param string $regex Regex to use (if none it will use built in regex) @return boolean Success @access public
email
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function equalTo($check, $comparedTo) { return ($check === $comparedTo); }
Check that value is exactly $comparedTo. @param mixed $check Value to check @param mixed $comparedTo Value to compare @return boolean Success @access public
equalTo
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function extension($check, $extensions = array('gif', 'jpeg', 'png', 'jpg')) { if (is_array($check)) { return Validation::extension(array_shift($check), $extensions); } $extension = strtolower(array_pop(explode('.', $check))); foreach ($extensions as $value) { if ($extension == strtolower($value)) { return true; } } return false; }
Check that value has a valid file extension. @param mixed $check Value to check @param array $extensions file extenstions to allow @return boolean Success @access public
extension
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function ip($check, $type = 'both') { $_this =& Validation::getInstance(); $success = false; $type = strtolower($type); if ($type === 'ipv4' || $type === 'both') { $success |= $_this->_ipv4($check); } if ($type === 'ipv6' || $type === 'both') { $success |= $_this->_ipv6($check); } return $success; }
Validation of an IP address. Valid IP version strings for type restriction are: - both: Check both IPv4 and IPv6, return true if the supplied address matches either version - IPv4: Version 4 (Eg: 127.0.0.1, 192.168.10.123, 203.211.24.8) - IPv6: Version 6 (Eg: ::1, 2001:0db8::1428:57ab) @param string $check The string to test. @param string $type The IP Version to test against @return boolean Success @access public
ip
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function _ipv4($check) { if (function_exists('filter_var')) { return filter_var($check, FILTER_VALIDATE_IP, array('flags' => FILTER_FLAG_IPV4)) !== false; } $this->__populateIp(); $this->check = $check; $this->regex = '/^' . $this->__pattern['IPv4'] . '$/'; return $this->_check(); }
Validation of IPv4 addresses. @param string $check IP Address to test @return boolean Success @access protected
_ipv4
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function _ipv6($check) { if (function_exists('filter_var')) { return filter_var($check, FILTER_VALIDATE_IP, array('flags' => FILTER_FLAG_IPV6)) !== false; } $this->__populateIp(); $this->check = $check; $this->regex = '/^' . $this->__pattern['IPv6'] . '$/'; return $this->_check(); }
Validation of IPv6 addresses. @param string $check IP Address to test @return boolean Success @access protected
_ipv6
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function minLength($check, $min) { $length = mb_strlen($check); return ($length >= $min); }
Checks whether the length of a string is greater or equal to a minimal length. @param string $check The string to test @param integer $min The minimal string length @return boolean Success @access public
minLength
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function maxLength($check, $max) { $length = mb_strlen($check); return ($length <= $max); }
Checks whether the length of a string is smaller or equal to a maximal length.. @param string $check The string to test @param integer $max The maximal string length @return boolean Success @access public
maxLength
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function money($check, $symbolPosition = 'left') { $_this =& Validation::getInstance(); $_this->check = $check; if ($symbolPosition == 'right') { $_this->regex = '/^(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?(?<!\x{00a2})\p{Sc}?$/u'; } else { $_this->regex = '/^(?!\x{00a2})\p{Sc}?(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$/u'; } return $_this->_check(); }
Checks that a value is a monetary amount. @param string $check Value to check @param string $symbolPosition Where symbol is located (left/right) @return boolean Success @access public
money
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function multiple($check, $options = array()) { $defaults = array('in' => null, 'max' => null, 'min' => null); $options = array_merge($defaults, $options); $check = array_filter((array)$check); if (empty($check)) { return false; } if ($options['max'] && count($check) > $options['max']) { return false; } if ($options['min'] && count($check) < $options['min']) { return false; } if ($options['in'] && is_array($options['in'])) { foreach ($check as $val) { if (!in_array($val, $options['in'])) { return false; } } } return true; }
Validate a multiple select. Valid Options - in => provide a list of choices that selections must be made from - max => maximun number of non-zero choices that can be made - min => minimum number of non-zero choices that can be made @param mixed $check Value to check @param mixed $options Options for the check. @return boolean Success @access public
multiple
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function numeric($check) { return is_numeric($check); }
Checks if a value is numeric. @param string $check Value to check @return boolean Succcess @access public
numeric
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function phone($check, $regex = null, $country = 'all') { $_this =& Validation::getInstance(); $_this->check = $check; $_this->regex = $regex; $_this->country = $country; if (is_array($check)) { $_this->_extract($check); } if (is_null($_this->regex)) { switch ($_this->country) { case 'us': case 'all': case 'can': // includes all NANPA members. see http://en.wikipedia.org/wiki/North_American_Numbering_Plan#List_of_NANPA_countries_and_territories $_this->regex = '/^(?:\+?1)?[-. ]?\\(?[2-9][0-8][0-9]\\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}$/'; break; } } if (empty($_this->regex)) { return $_this->_pass('phone', $check, $country); } return $_this->_check(); }
Check that a value is a valid phone number. @param mixed $check Value to check (string or array) @param string $regex Regular expression to use @param string $country Country code (defaults to 'all') @return boolean Success @access public
phone
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function postal($check, $regex = null, $country = null) { $_this =& Validation::getInstance(); $_this->check = $check; $_this->regex = $regex; $_this->country = $country; if (is_array($check)) { $_this->_extract($check); } if (empty($country)) { $_this->country = 'us'; } if (is_null($_this->regex)) { switch ($_this->country) { case 'uk': $_this->regex = '/\\A\\b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\\b\\z/i'; break; case 'ca': $_this->regex = '/\\A\\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] ?[0-9][A-Z][0-9]\\b\\z/i'; break; case 'it': case 'de': $_this->regex = '/^[0-9]{5}$/i'; break; case 'be': $_this->regex = '/^[1-9]{1}[0-9]{3}$/i'; break; case 'us': $_this->regex = '/\\A\\b[0-9]{5}(?:-[0-9]{4})?\\b\\z/i'; break; } } if (empty($_this->regex)) { return $_this->_pass('postal', $check, $country); } return $_this->_check(); }
Checks that a given value is a valid postal code. @param mixed $check Value to check @param string $regex Regular expression to use @param string $country Country to use for formatting @return boolean Success @access public
postal
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function ssn($check, $regex = null, $country = null) { $_this =& Validation::getInstance(); $_this->check = $check; $_this->regex = $regex; $_this->country = $country; if (is_array($check)) { $_this->_extract($check); } if (is_null($_this->regex)) { switch ($_this->country) { case 'dk': $_this->regex = '/\\A\\b[0-9]{6}-[0-9]{4}\\b\\z/i'; break; case 'nl': $_this->regex = '/\\A\\b[0-9]{9}\\b\\z/i'; break; case 'us': $_this->regex = '/\\A\\b[0-9]{3}-[0-9]{2}-[0-9]{4}\\b\\z/i'; break; } } if (empty($_this->regex)) { return $_this->_pass('ssn', $check, $country); } return $_this->_check(); }
Checks that a value is a valid Social Security Number. @param mixed $check Value to check @param string $regex Regular expression to use @param string $country Country @return boolean Success @access public
ssn
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function uuid($check) { $_this =& Validation::getInstance(); $_this->check = $check; $_this->regex = '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i'; return $_this->_check(); }
Checks that a value is a valid uuid - http://tools.ietf.org/html/rfc4122 @param string $check Value to check @return boolean Success @access public
uuid
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function url($check, $strict = false) { $_this =& Validation::getInstance(); $_this->__populateIp(); $_this->check = $check; $validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~[]') . '\/0-9a-z\p{L}\p{N}]|(%[0-9a-f]{2}))'; $_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') . '(?:' . $_this->__pattern['IPv4'] . '|\[' . $_this->__pattern['IPv6'] . '\]|' . $_this->__pattern['hostname'] . ')' . '(?::[1-9][0-9]{0,4})?' . '(?:\/?|\/' . $validChars . '*)?' . '(?:\?' . $validChars . '*)?' . '(?:#' . $validChars . '*)?$/iu'; return $_this->_check(); }
Checks that a value is a valid URL according to http://www.w3.org/Addressing/URL/url-spec.txt The regex checks for the following component parts: - a valid, optional, scheme - a valid ip address OR a valid domain name as defined by section 2.3.1 of http://www.ietf.org/rfc/rfc1035.txt with an optional port number - an optional valid path - an optional query string (get parameters) - an optional fragment (anchor tag) @param string $check Value to check @param boolean $strict Require URL to be prefixed by a valid scheme (one of http(s)/ftp(s)/file/news/gopher) @return boolean Success @access public
url
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function inList($check, $list) { return in_array($check, $list); }
Checks if a value is in a given list. @param string $check Value to check @param array $list List to check against @return boolean Succcess @access public
inList
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function userDefined($check, $object, $method, $args = null) { return call_user_func_array(array(&$object, $method), array($check, $args)); }
Runs an user-defined validation. @param mixed $check value that will be validated in user-defined methods. @param object $object class that holds validation method @param string $method class method name for validation to run @param array $args arguments to send to method @return mixed user-defined class class method returns @access public
userDefined
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function _pass($method, $check, $classPrefix) { $className = ucwords($classPrefix) . 'Validation'; if (!class_exists($className)) { trigger_error(sprintf(__('Could not find %s class, unable to complete validation.', true), $className), E_USER_WARNING); return false; } if (!is_callable(array($className, $method))) { trigger_error(sprintf(__('Method %s does not exist on %s unable to complete validation.', true), $method, $className), E_USER_WARNING); return false; } $check = (array)$check; return call_user_func_array(array($className, $method), $check); }
Attempts to pass unhandled Validation locales to a class starting with $classPrefix and ending with Validation. For example $classPrefix = 'nl', the class would be `NlValidation`. @param string $method The method to call on the other class. @param mixed $check The value to check or an array of parameters for the method to be called. @param string $classPrefix The prefix for the class to do the validation. @return mixed Return of Passed method, false on failure @access protected
_pass
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function _check() { $_this =& Validation::getInstance(); if (preg_match($_this->regex, $_this->check)) { $_this->error[] = false; return true; } else { $_this->error[] = true; return false; } }
Runs a regular expression match. @return boolean Success of match @access protected
_check
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function _extract($params) { $_this =& Validation::getInstance(); extract($params, EXTR_OVERWRITE); if (isset($check)) { $_this->check = $check; } if (isset($regex)) { $_this->regex = $regex; } if (isset($country)) { $_this->country = mb_strtolower($country); } if (isset($deep)) { $_this->deep = $deep; } if (isset($type)) { $_this->type = $type; } }
Get the values to use when value sent to validation method is an array. @param array $params Parameters sent to validation method @return void @access protected
_extract
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function _luhn() { $_this =& Validation::getInstance(); if ($_this->deep !== true) { return true; } if ($_this->check == 0) { return false; } $sum = 0; $length = strlen($_this->check); for ($position = 1 - ($length % 2); $position < $length; $position += 2) { $sum += $_this->check[$position]; } for ($position = ($length % 2); $position < $length; $position += 2) { $number = $_this->check[$position] * 2; $sum += ($number < 10) ? $number : $number - 9; } return ($sum % 10 == 0); }
Luhn algorithm @see http://en.wikipedia.org/wiki/Luhn_algorithm @return boolean Success @access protected
_luhn
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function __reset() { $this->check = null; $this->regex = null; $this->country = null; $this->deep = null; $this->type = null; $this->error = array(); $this->errors = array(); }
Reset internal variables for another validation run. @return void @access private
__reset
php
Datawalke/Coordino
cake/libs/validation.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/validation.php
MIT
function __construct($name = null, $value = null, $namespace = null) { if (strpos($name, ':') !== false) { list($prefix, $name) = explode(':', $name); if (!$namespace) { $namespace = $prefix; } } $this->name = $name; if ($namespace) { $this->namespace = $namespace; } if (is_array($value) || is_object($value)) { $this->normalize($value); } elseif (!empty($value) || $value === 0 || $value === '0') { $this->createTextNode($value); } }
Constructor. @param string $name Node name @param array $attributes Node attributes @param mixed $value Node contents (text) @param array $children Node children
__construct
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function addNamespace($prefix, $url) { if ($ns = Xml::addGlobalNs($prefix, $url)) { $this->namespaces = array_merge($this->namespaces, $ns); return true; } return false; }
Adds a namespace to the current node @param string $prefix The namespace prefix @param string $url The namespace DTD URL @return void
addNamespace
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function removeNamespace($prefix) { if (Xml::removeGlobalNs($prefix)) { return true; } return false; }
Adds a namespace to the current node @param string $prefix The namespace prefix @param string $url The namespace DTD URL @return void
removeNamespace
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &createNode($name = null, $value = null, $namespace = false) { $node =& new XmlNode($name, $value, $namespace); $node->setParent($this); return $node; }
Creates an XmlNode object that can be appended to this document or a node in it @param string $name Node name @param string $value Node value @param string $namespace Node namespace @return object XmlNode
createNode
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &createElement($name = null, $value = null, $attributes = array(), $namespace = false) { $element =& new XmlElement($name, $value, $attributes, $namespace); $element->setParent($this); return $element; }
Creates an XmlElement object that can be appended to this document or a node in it @param string $name Element name @param string $value Element value @param array $attributes Element attributes @param string $namespace Node namespace @return object XmlElement
createElement
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &createTextNode($value = null) { $node = new XmlTextNode($value); $node->setParent($this); return $node; }
Creates an XmlTextNode object that can be appended to this document or a node in it @param string $value Node value @return object XmlTextNode
createTextNode
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function normalize($object, $keyName = null, $options = array()) { if (is_a($object, 'XmlNode')) { return $object; } $name = null; $options += array('format' => 'attributes'); if ($keyName !== null && !is_numeric($keyName)) { $name = $keyName; } elseif (!empty($object->_name_)) { $name = $object->_name_; } elseif (isset($object->name)) { $name = $object->name; } elseif ($options['format'] == 'attributes') { $name = get_class($object); } $tagOpts = $this->__tagOptions($name); if ($tagOpts === false) { return; } if (isset($tagOpts['name'])) { $name = $tagOpts['name']; } elseif ($name != strtolower($name) && $options['slug'] !== false) { $name = Inflector::slug(Inflector::underscore($name)); } if (!empty($name)) { $node =& $this->createElement($name); } else { $node =& $this; } $namespace = array(); $attributes = array(); $children = array(); $chldObjs = array(); if (is_object($object)) { $chldObjs = get_object_vars($object); } elseif (is_array($object)) { $chldObjs = $object; } elseif (!empty($object) || $object === 0 || $object === '0') { $node->createTextNode($object); } $attr = array(); if (isset($tagOpts['attributes'])) { $attr = $tagOpts['attributes']; } if (isset($tagOpts['value']) && isset($chldObjs[$tagOpts['value']])) { $node->createTextNode($chldObjs[$tagOpts['value']]); unset($chldObjs[$tagOpts['value']]); } $n = $name; if (isset($chldObjs['_name_'])) { $n = null; unset($chldObjs['_name_']); } $c = 0; foreach ($chldObjs as $key => $val) { if (in_array($key, $attr) && !is_object($val) && !is_array($val)) { $attributes[$key] = $val; } else { if (!isset($tagOpts['children']) || $tagOpts['children'] === array() || (is_array($tagOpts['children']) && in_array($key, $tagOpts['children']))) { if (!is_numeric($key)) { $n = $key; } if (is_array($val)) { foreach ($val as $n2 => $obj2) { if (is_numeric($n2)) { $n2 = $n; } $node->normalize($obj2, $n2, $options); } } else { if (is_object($val)) { $node->normalize($val, $n, $options); } elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) { if ($options['slug'] == true) { $key = Inflector::slug(Inflector::underscore($key)); } $tmp =& $node->createElement($key); if (!empty($val) || $val === 0 || $val === '0') { $tmp->createTextNode($val); } } elseif ($options['format'] == 'attributes') { $node->addAttribute($key, $val); } } } } $c++; } if (!empty($name)) { return $node; } return $children; }
Gets the XML element properties from an object. @param object $object Object to get properties from @return array Properties from object @access public
normalize
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function name() { if (!empty($this->namespace)) { $_this =& XmlManager::getInstance(); if (!isset($_this->options['verifyNs']) || !$_this->options['verifyNs'] || in_array($this->namespace, array_keys($_this->namespaces))) { return $this->namespace . ':' . $this->name; } } return $this->name; }
Returns the fully-qualified XML node name, with namespace @access public
name
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function setParent(&$parent) { if (strtolower(get_class($this)) == 'xml') { return; } if (isset($this->__parent) && is_object($this->__parent)) { if ($this->__parent->compare($parent)) { return; } foreach ($this->__parent->children as $i => $child) { if ($this->compare($child)) { array_splice($this->__parent->children, $i, 1); break; } } } if ($parent == null) { unset($this->__parent); } else { $parent->children[] =& $this; $this->__parent =& $parent; } }
Sets the parent node of this XmlNode. @access public
setParent
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function cloneNode() { return clone($this); }
Returns a copy of self. @return object Cloned instance @access public
cloneNode
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function compare($node) { $keys = array(get_object_vars($this), get_object_vars($node)); return ($keys[0] === $keys[1]); }
Compares $node to this XmlNode object @param object An XmlNode or subclass instance @return boolean True if the nodes match, false otherwise @access public
compare
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &append(&$child, $options = array()) { if (empty($child)) { $return = false; return $return; } if (is_object($child)) { if ($this->compare($child)) { trigger_error(__('Cannot append a node to itself.', true)); $return = false; return $return; } } else if (is_array($child)) { $child = Set::map($child); if (is_array($child)) { if (!is_a(current($child), 'XmlNode')) { foreach ($child as $i => $childNode) { $child[$i] = $this->normalize($childNode, null, $options); } } else { foreach ($child as $childNode) { $this->append($childNode, $options); } } return $child; } } else { $attributes = array(); if (func_num_args() >= 2) { $attributes = func_get_arg(1); } $child =& $this->createNode($child, null, $attributes); } $child = $this->normalize($child, null, $options); if (empty($child->namespace) && !empty($this->namespace)) { $child->namespace = $this->namespace; } if (is_a($child, 'XmlNode')) { $child->setParent($this); } return $child; }
Append given node as a child. @param object $child XmlNode with appended child @param array $options XML generator options for objects and arrays @return object A reference to the appended child node @access public
append
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &first() { if (isset($this->children[0])) { return $this->children[0]; } else { $return = null; return $return; } }
Returns first child node, or null if empty. @return object First XmlNode @access public
first
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &last() { if (count($this->children) > 0) { return $this->children[count($this->children) - 1]; } else { $return = null; return $return; } }
Returns last child node, or null if empty. @return object Last XmlNode @access public
last
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &child($id) { $null = null; if (is_int($id)) { if (isset($this->children[$id])) { return $this->children[$id]; } else { return null; } } elseif (is_string($id)) { for ($i = 0; $i < count($this->children); $i++) { if ($this->children[$i]->name == $id) { return $this->children[$i]; } } } return $null; }
Returns child node with given ID. @param string $id Name of child node @return object Child XmlNode @access public
child
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function children($name) { $nodes = array(); $count = count($this->children); for ($i = 0; $i < $count; $i++) { if ($this->children[$i]->name == $name) { $nodes[] =& $this->children[$i]; } } return $nodes; }
Gets a list of childnodes with the given tag name. @param string $name Tag name of child nodes @return array An array of XmlNodes with the given tag name @access public
children
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &nextSibling() { $null = null; $count = count($this->__parent->children); for ($i = 0; $i < $count; $i++) { if ($this->__parent->children[$i] == $this) { if ($i >= $count - 1 || !isset($this->__parent->children[$i + 1])) { return $null; } return $this->__parent->children[$i + 1]; } } return $null; }
Gets a reference to the next child node in the list of this node's parent. @return object A reference to the XmlNode object @access public
nextSibling
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &previousSibling() { $null = null; $count = count($this->__parent->children); for ($i = 0; $i < $count; $i++) { if ($this->__parent->children[$i] == $this) { if ($i == 0 || !isset($this->__parent->children[$i - 1])) { return $null; } return $this->__parent->children[$i - 1]; } } return $null; }
Gets a reference to the previous child node in the list of this node's parent. @return object A reference to the XmlNode object @access public
previousSibling
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &parent() { return $this->__parent; }
Returns parent node. @return object Parent XmlNode @access public
parent
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &document() { $document =& $this; while (true) { if (get_class($document) == 'Xml' || $document == null) { break; } $document =& $document->parent(); } return $document; }
Returns the XML document to which this node belongs @return object Parent XML object @access public
document
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function hasChildren() { if (is_array($this->children) && !empty($this->children)) { return true; } return false; }
Returns true if this structure has child nodes. @return bool @access public
hasChildren
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function toString($options = array(), $depth = 0) { if (is_int($options)) { $depth = $options; $options = array(); } $defaults = array('cdata' => true, 'whitespace' => false, 'convertEntities' => false, 'showEmpty' => true, 'leaveOpen' => false); $options = array_merge($defaults, Xml::options(), $options); $tag = !(strpos($this->name, '#') === 0); $d = ''; if ($tag) { if ($options['whitespace']) { $d .= str_repeat("\t", $depth); } $d .= '<' . $this->name(); if (!empty($this->namespaces) > 0) { foreach ($this->namespaces as $key => $val) { $val = str_replace('"', '\"', $val); $d .= ' xmlns:' . $key . '="' . $val . '"'; } } $parent =& $this->parent(); if ($parent->name === '#document' && !empty($parent->namespaces)) { foreach ($parent->namespaces as $key => $val) { $val = str_replace('"', '\"', $val); $d .= ' xmlns:' . $key . '="' . $val . '"'; } } if (is_array($this->attributes) && !empty($this->attributes)) { foreach ($this->attributes as $key => $val) { if (is_bool($val) && $val === false) { $val = 0; } $d .= ' ' . $key . '="' . htmlspecialchars($val, ENT_QUOTES, Configure::read('App.encoding')) . '"'; } } } if (!$this->hasChildren() && empty($this->value) && $this->value !== 0 && $tag) { if (!$options['leaveOpen']) { $d .= ' />'; } if ($options['whitespace']) { $d .= "\n"; } } elseif ($tag || $this->hasChildren()) { if ($tag) { $d .= '>'; } if ($this->hasChildren()) { if ($options['whitespace']) { $d .= "\n"; } $count = count($this->children); $cDepth = $depth + 1; for ($i = 0; $i < $count; $i++) { $d .= $this->children[$i]->toString($options, $cDepth); } if ($tag) { if ($options['whitespace'] && $tag) { $d .= str_repeat("\t", $depth); } if (!$options['leaveOpen']) { $d .= '</' . $this->name() . '>'; } if ($options['whitespace']) { $d .= "\n"; } } } } return $d; }
Returns this XML structure as a string. @return string String representation of the XML structure. @access public
toString
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function toArray($camelize = true) { $out = $this->attributes; foreach ($this->children as $child) { $key = $camelize ? Inflector::camelize($child->name) : $child->name; $leaf = false; if (is_a($child, 'XmlTextNode')) { $out['value'] = $child->value; continue; } elseif (isset($child->children[0]) && is_a($child->children[0], 'XmlTextNode')) { $value = $child->children[0]->value; if ($child->attributes) { $value = array_merge(array('value' => $value), $child->attributes); } if (count($child->children) == 1) { $leaf = true; } } elseif (count($child->children) === 0 && $child->value == '') { $value = $child->attributes; if (empty($value)) { $leaf = true; } } else { $value = $child->toArray($camelize); } if (isset($out[$key])) { if(!isset($out[$key][0]) || !is_array($out[$key]) || !is_int(key($out[$key]))) { $out[$key] = array($out[$key]); } $out[$key][] = $value; } elseif (isset($out[$child->name])) { $t = $out[$child->name]; unset($out[$child->name]); $out[$key] = array($t); $out[$key][] = $value; } elseif ($leaf) { $out[$child->name] = $value; } else { $out[$key] = $value; } } return $out; }
Return array representation of current object. @param boolean $camelize true will camelize child nodes, false will not alter node names @return array Array representation @access public
toArray
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function __toString() { return $this->toString(); }
Returns data from toString when this object is converted to a string. @return string String representation of this structure. @access private
__toString
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function _killParent($recursive = true) { unset($this->__parent, $this->_log); if ($recursive && $this->hasChildren()) { for ($i = 0; $i < count($this->children); $i++) { $this->children[$i]->_killParent(true); } } }
Debug method. Deletes the parent. Also deletes this node's children, if given the $recursive parameter. @param boolean $recursive Recursively delete elements. @access protected
_killParent
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function __construct($input = null, $options = array()) { $defaults = array( 'root' => '#document', 'tags' => array(), 'namespaces' => array(), 'version' => '1.0', 'encoding' => 'UTF-8', 'format' => 'attributes', 'slug' => true ); $options = array_merge($defaults, Xml::options(), $options); foreach (array('version', 'encoding', 'namespaces') as $key) { $this->{$key} = $options[$key]; } $this->__tags = $options['tags']; parent::__construct('#document'); if ($options['root'] !== '#document') { $Root =& $this->createNode($options['root']); } else { $Root =& $this; } if (!empty($input)) { if (is_string($input)) { $Root->load($input); } elseif (is_array($input) || is_object($input)) { $Root->append($input, $options); } } }
Constructor. Sets up the XML parser with options, gives it this object as its XML object, and sets some variables. ### Options - 'root': The name of the root element, defaults to '#document' - 'version': The XML version, defaults to '1.0' - 'encoding': Document encoding, defaults to 'UTF-8' - 'namespaces': An array of namespaces (as strings) used in this document - 'format': Specifies the format this document converts to when parsed or rendered out as text, either 'attributes' or 'tags', defaults to 'attributes' - 'tags': An array specifying any tag-specific formatting options, indexed by tag name. See XmlNode::normalize(). - 'slug': A boolean to indicate whether or not you want the string version of the XML document to have its tags run through Inflector::slug(). Defaults to true @param mixed $input The content with which this XML document should be initialized. Can be a string, array or object. If a string is specified, it may be a literal XML document, or a URL or file path to read from. @param array $options Options to set up with, for valid options see above: @see XmlNode::normalize()
__construct
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function load($input) { if (!is_string($input)) { return false; } $this->__rawData = null; $this->__header = null; if (strstr($input, "<")) { $this->__rawData = $input; } elseif (strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) { App::import('Core', 'HttpSocket'); $socket = new HttpSocket(); $this->__rawData = $socket->get($input); } elseif (file_exists($input)) { $this->__rawData = file_get_contents($input); } else { trigger_error(__('XML cannot be read', true)); return false; } return $this->parse(); }
Initialize XML object from a given XML string. Returns false on error. @param string $input XML string, a path to a file, or an HTTP resource to load @return boolean Success @access public
load
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function parse() { $this->__initParser(); $this->__rawData = trim($this->__rawData); $this->__header = trim(str_replace( array('<' . '?', '?' . '>'), array('', ''), substr($this->__rawData, 0, strpos($this->__rawData, '?' . '>')) )); xml_parse_into_struct($this->__parser, $this->__rawData, $vals); $xml =& $this; $count = count($vals); for ($i = 0; $i < $count; $i++) { $data = $vals[$i]; $data += array('tag' => null, 'value' => null, 'attributes' => array()); switch ($data['type']) { case "open" : $xml =& $xml->createElement($data['tag'], $data['value'], $data['attributes']); break; case "close" : $xml =& $xml->parent(); break; case "complete" : $xml->createElement($data['tag'], $data['value'], $data['attributes']); break; case 'cdata': $xml->createTextNode($data['value']); break; } } xml_parser_free($this->__parser); $this->__parser = null; return true; }
Parses and creates XML nodes from the __rawData property. @return boolean Success @access public @see Xml::load() @todo figure out how to link attributes and namespaces
parse
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function __initParser() { if (empty($this->__parser)) { $this->__parser = xml_parser_create(); xml_set_object($this->__parser, $this); xml_parser_set_option($this->__parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($this->__parser, XML_OPTION_SKIP_WHITE, 1); } }
Initializes the XML parser resource @return void @access private
__initParser
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function compose($options = array()) { return $this->toString($options); }
Returns a string representation of the XML object @param mixed $options If boolean: whether to include the XML header with the document (defaults to true); if an array, overrides the default XML generation options @return string XML data @access public @deprecated @see Xml::toString()
compose
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function error($msg, $code = 0, $line = 0) { if (Configure::read('debug')) { echo $msg . " " . $code . " " . $line; } }
If debug mode is on, this method echoes an error message. @param string $msg Error message @param integer $code Error code @param integer $line Line in file @access public
error
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function getError($code) { $r = @xml_error_string($code); return $r; }
Returns a string with a textual description of the error code, or FALSE if no description was found. @param integer $code Error code @return string Error message @access public
getError
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &next() { $return = null; return $return; }
Get next element. NOT implemented. @return object @access public
next
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT
function &previous() { $return = null; return $return; }
Get previous element. NOT implemented. @return object @access public
previous
php
Datawalke/Coordino
cake/libs/xml.php
https://github.com/Datawalke/Coordino/blob/master/cake/libs/xml.php
MIT