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 create() {
$dir = $this->Folder->pwd();
if (is_dir($dir) && is_writable($dir) && !$this->exists()) {
$old = umask(0);
if (touch($this->path)) {
umask($old);
return true;
}
}
return false;
}
|
Creates the File.
@return boolean Success
@access public
|
create
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function open($mode = 'r', $force = false) {
if (!$force && is_resource($this->handle)) {
return true;
}
clearstatcache();
if ($this->exists() === false) {
if ($this->create() === false) {
return false;
}
}
$this->handle = fopen($this->path, $mode);
if (is_resource($this->handle)) {
return true;
}
return false;
}
|
Opens the current file with a given $mode
@param string $mode A valid 'fopen' mode string (r|w|a ...)
@param boolean $force If true then the file will be re-opened even if its already opened, otherwise it won't
@return boolean True on success, false on failure
@access public
|
open
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function read($bytes = false, $mode = 'rb', $force = false) {
if ($bytes === false && $this->lock === null) {
return file_get_contents($this->path);
}
if ($this->open($mode, $force) === false) {
return false;
}
if ($this->lock !== null && flock($this->handle, LOCK_SH) === false) {
return false;
}
if (is_int($bytes)) {
return fread($this->handle, $bytes);
}
$data = '';
while (!feof($this->handle)) {
$data .= fgets($this->handle, 4096);
}
if ($this->lock !== null) {
flock($this->handle, LOCK_UN);
}
if ($bytes === false) {
$this->close();
}
return trim($data);
}
|
Return the contents of this File as a string.
@param string $bytes where to start
@param string $mode A `fread` compatible mode.
@param boolean $force If true then the file will be re-opened even if its already opened, otherwise it won't
@return mixed string on success, false on failure
@access public
|
read
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function offset($offset = false, $seek = SEEK_SET) {
if ($offset === false) {
if (is_resource($this->handle)) {
return ftell($this->handle);
}
} elseif ($this->open() === true) {
return fseek($this->handle, $offset, $seek) === 0;
}
return false;
}
|
Sets or gets the offset for the currently opened file.
@param mixed $offset The $offset in bytes to seek. If set to false then the current offset is returned.
@param integer $seek PHP Constant SEEK_SET | SEEK_CUR | SEEK_END determining what the $offset is relative to
@return mixed True on success, false on failure (set mode), false on failure or integer offset on success (get mode)
@access public
|
offset
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function prepare($data, $forceWindows = false) {
$lineBreak = "\n";
if (DIRECTORY_SEPARATOR == '\\' || $forceWindows === true) {
$lineBreak = "\r\n";
}
return strtr($data, array("\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak));
}
|
Prepares a ascii string for writing. Converts line endings to the
correct terminator for the current platform. If windows "\r\n" will be used
all other platforms will use "\n"
@param string $data Data to prepare for writing.
@return string The with converted line endings.
@access public
|
prepare
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function write($data, $mode = 'w', $force = false) {
$success = false;
if ($this->open($mode, $force) === true) {
if ($this->lock !== null) {
if (flock($this->handle, LOCK_EX) === false) {
return false;
}
}
if (fwrite($this->handle, $data) !== false) {
$success = true;
}
if ($this->lock !== null) {
flock($this->handle, LOCK_UN);
}
}
return $success;
}
|
Write given data to this File.
@param string $data Data to write to this File.
@param string $mode Mode of writing. {@link http://php.net/fwrite See fwrite()}.
@param string $force force the file to open
@return boolean Success
@access public
|
write
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function append($data, $force = false) {
return $this->write($data, 'a', $force);
}
|
Append given data string to this File.
@param string $data Data to write
@param string $force force the file to open
@return boolean Success
@access public
|
append
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function close() {
if (!is_resource($this->handle)) {
return true;
}
return fclose($this->handle);
}
|
Closes the current file if it is opened.
@return boolean True if closing was successful or file was already closed, otherwise false
@access public
|
close
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function delete() {
clearstatcache();
if (is_resource($this->handle)) {
fclose($this->handle);
$this->handle = null;
}
if ($this->exists()) {
return unlink($this->path);
}
return false;
}
|
Deletes the File.
@return boolean Success
@access public
|
delete
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function info() {
if ($this->info == null) {
$this->info = pathinfo($this->path);
}
if (!isset($this->info['filename'])) {
$this->info['filename'] = $this->name();
}
return $this->info;
}
|
Returns the File info.
@return string The File extension
@access public
|
info
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function ext() {
if ($this->info == null) {
$this->info();
}
if (isset($this->info['extension'])) {
return $this->info['extension'];
}
return false;
}
|
Returns the File extension.
@return string The File extension
@access public
|
ext
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function name() {
if ($this->info == null) {
$this->info();
}
if (isset($this->info['extension'])) {
return basename($this->name, '.'.$this->info['extension']);
} elseif ($this->name) {
return $this->name;
}
return false;
}
|
Returns the File name without extension.
@return string The File name without extension.
@access public
|
name
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function safe($name = null, $ext = null) {
if (!$name) {
$name = $this->name;
}
if (!$ext) {
$ext = $this->ext();
}
return preg_replace( "/(?:[^\w\.-]+)/", "_", basename($name, $ext));
}
|
makes filename safe for saving
@param string $name The name of the file to make safe if different from $this->name
@param strin $ext The name of the extension to make safe if different from $this->ext
@return string $ext the extension of the file
@access public
|
safe
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function md5($maxsize = 5) {
if ($maxsize === true) {
return md5_file($this->path);
}
$size = $this->size();
if ($size && $size < ($maxsize * 1024) * 1024) {
return md5_file($this->path);
}
return false;
}
|
Get md5 Checksum of file with previous check of Filesize
@param mixed $maxsize in MB or true to force
@return string md5 Checksum {@link http://php.net/md5_file See md5_file()}
@access public
|
md5
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function pwd() {
if (is_null($this->path)) {
$this->path = $this->Folder->slashTerm($this->Folder->pwd()) . $this->name;
}
return $this->path;
}
|
Returns the full path of the File.
@return string Full path to file
@access public
|
pwd
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function exists() {
return (file_exists($this->path) && is_file($this->path));
}
|
Returns true if the File exists.
@return boolean true if it exists, false otherwise
@access public
|
exists
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function perms() {
if ($this->exists()) {
return substr(sprintf('%o', fileperms($this->path)), -4);
}
return false;
}
|
Returns the "chmod" (permissions) of the File.
@return string Permissions for the file
@access public
|
perms
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function size() {
if ($this->exists()) {
return filesize($this->path);
}
return false;
}
|
Returns the Filesize
@return integer size of the file in bytes, or false in case of an error
@access public
|
size
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function writable() {
return is_writable($this->path);
}
|
Returns true if the File is writable.
@return boolean true if its writable, false otherwise
@access public
|
writable
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function executable() {
return is_executable($this->path);
}
|
Returns true if the File is executable.
@return boolean true if its executable, false otherwise
@access public
|
executable
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function readable() {
return is_readable($this->path);
}
|
Returns true if the File is readable.
@return boolean true if file is readable, false otherwise
@access public
|
readable
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function owner() {
if ($this->exists()) {
return fileowner($this->path);
}
return false;
}
|
Returns the File's owner.
@return integer the Fileowner
@access public
|
owner
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function group() {
if ($this->exists()) {
return filegroup($this->path);
}
return false;
}
|
Returns the File's group.
@return integer the Filegroup
@access public
|
group
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function lastAccess() {
if ($this->exists()) {
return fileatime($this->path);
}
return false;
}
|
Returns last access time.
@return integer timestamp Timestamp of last access time
@access public
|
lastAccess
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function lastChange() {
if ($this->exists()) {
return filemtime($this->path);
}
return false;
}
|
Returns last modified time.
@return integer timestamp Timestamp of last modification
@access public
|
lastChange
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function &Folder() {
return $this->Folder;
}
|
Returns the current folder.
@return Folder Current folder
@access public
|
Folder
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function copy($dest, $overwrite = true) {
if (!$this->exists() || is_file($dest) && !$overwrite) {
return false;
}
return copy($this->path, $dest);
}
|
Copy the File to $dest
@param string $dest destination for the copy
@param boolean $overwrite Overwrite $dest if exists
@return boolean Succes
@access public
|
copy
|
php
|
Datawalke/Coordino
|
cake/libs/file.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/file.php
|
MIT
|
function __construct($path = false, $create = false, $mode = false) {
parent::__construct();
if (empty($path)) {
$path = TMP;
}
if ($mode) {
$this->mode = $mode;
}
if (!file_exists($path) && $create === true) {
$this->create($path, $this->mode);
}
if (!Folder::isAbsolute($path)) {
$path = realpath($path);
}
if (!empty($path)) {
$this->cd($path);
}
}
|
Constructor.
@param string $path Path to folder
@param boolean $create Create folder if not found
@param mixed $mode Mode (CHMOD) to apply to created folder, false to ignore
|
__construct
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function pwd() {
return $this->path;
}
|
Return current path.
@return string Current path
@access public
|
pwd
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function cd($path) {
$path = $this->realpath($path);
if (is_dir($path)) {
return $this->path = $path;
}
return false;
}
|
Change directory to $path.
@param string $path Path to the directory to change to
@return string The new path. Returns false on failure
@access public
|
cd
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function read($sort = true, $exceptions = false, $fullPath = false) {
$dirs = $files = array();
if (!$this->pwd()) {
return array($dirs, $files);
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
if (false === ($dir = @opendir($this->path))) {
return array($dirs, $files);
}
while (false !== ($item = readdir($dir))) {
if ($item === '.' || $item === '..' || ($skipHidden && $item[0] === '.') || isset($exceptions[$item])) {
continue;
}
$path = Folder::addPathElement($this->path, $item);
if (is_dir($path)) {
$dirs[] = $fullPath ? $path : $item;
} else {
$files[] = $fullPath ? $path : $item;
}
}
if ($sort || $this->sort) {
sort($dirs);
sort($files);
}
closedir($dir);
return array($dirs, $files);
}
|
Returns an array of the contents of the current directory.
The returned array holds two arrays: One of directories and one of files.
@param boolean $sort Whether you want the results sorted, set this and the sort property
to false to get unsorted results.
@param mixed $exceptions Either an array or boolean true will not grab dot files
@param boolean $fullPath True returns the full path
@return mixed Contents of current directory as an array, an empty array on failure
@access public
|
read
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function find($regexpPattern = '.*', $sort = false) {
list($dirs, $files) = $this->read($sort);
return array_values(preg_grep('/^' . $regexpPattern . '$/i', $files)); ;
}
|
Returns an array of all matching files in current directory.
@param string $pattern Preg_match pattern (Defaults to: .*)
@param boolean $sort Whether results should be sorted.
@return array Files that match given pattern
@access public
|
find
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function findRecursive($pattern = '.*', $sort = false) {
if (!$this->pwd()) {
return array();
}
$startsOn = $this->path;
$out = $this->_findRecursive($pattern, $sort);
$this->cd($startsOn);
return $out;
}
|
Returns an array of all matching files in and below current directory.
@param string $pattern Preg_match pattern (Defaults to: .*)
@param boolean $sort Whether results should be sorted.
@return array Files matching $pattern
@access public
|
findRecursive
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function _findRecursive($pattern, $sort = false) {
list($dirs, $files) = $this->read($sort);
$found = array();
foreach ($files as $file) {
if (preg_match('/^' . $pattern . '$/i', $file)) {
$found[] = Folder::addPathElement($this->path, $file);
}
}
$start = $this->path;
foreach ($dirs as $dir) {
$this->cd(Folder::addPathElement($start, $dir));
$found = array_merge($found, $this->findRecursive($pattern, $sort));
}
return $found;
}
|
Private helper function for findRecursive.
@param string $pattern Pattern to match against
@param boolean $sort Whether results should be sorted.
@return array Files matching pattern
@access private
|
_findRecursive
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function isWindowsPath($path) {
return (preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) == '\\\\');
}
|
Returns true if given $path is a Windows path.
@param string $path Path to check
@return boolean true if windows path, false otherwise
@access public
@static
|
isWindowsPath
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function isAbsolute($path) {
return !empty($path) && ($path[0] === '/' || preg_match('/^[A-Z]:\\\\/i', $path) || substr($path, 0, 2) == '\\\\');
}
|
Returns true if given $path is an absolute path.
@param string $path Path to check
@return bool true if path is absolute.
@access public
@static
|
isAbsolute
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function normalizePath($path) {
return Folder::correctSlashFor($path);
}
|
Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.)
@param string $path Path to check
@return string Set of slashes ("\\" or "/")
@access public
@static
|
normalizePath
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function correctSlashFor($path) {
return (Folder::isWindowsPath($path)) ? '\\' : '/';
}
|
Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.)
@param string $path Path to check
@return string Set of slashes ("\\" or "/")
@access public
@static
|
correctSlashFor
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function slashTerm($path) {
if (Folder::isSlashTerm($path)) {
return $path;
}
return $path . Folder::correctSlashFor($path);
}
|
Returns $path with added terminating slash (corrected for Windows or other OS).
@param string $path Path to check
@return string Path with ending slash
@access public
@static
|
slashTerm
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function addPathElement($path, $element) {
return rtrim($path, DS) . DS . $element;
}
|
Returns $path with $element added, with correct slash in-between.
@param string $path Path
@param string $element Element to and at end of path
@return string Combined path
@access public
@static
|
addPathElement
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function inCakePath($path = '') {
$dir = substr(Folder::slashTerm(ROOT), 0, -1);
$newdir = $dir . $path;
return $this->inPath($newdir);
}
|
Returns true if the File is in a given CakePath.
@param string $path The path to check.
@return bool
@access public
|
inCakePath
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function inPath($path = '', $reverse = false) {
$dir = Folder::slashTerm($path);
$current = Folder::slashTerm($this->pwd());
if (!$reverse) {
$return = preg_match('/^(.*)' . preg_quote($dir, '/') . '(.*)/', $current);
} else {
$return = preg_match('/^(.*)' . preg_quote($current, '/') . '(.*)/', $dir);
}
return (bool)$return;
}
|
Returns true if the File is in given path.
@param string $path The path to check that the current pwd() resides with in.
@param boolean $reverse
@return bool
@access public
|
inPath
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function chmod($path, $mode = false, $recursive = true, $exceptions = array()) {
if (!$mode) {
$mode = $this->mode;
}
if ($recursive === false && is_dir($path)) {
if (@chmod($path, intval($mode, 8))) {
$this->__messages[] = sprintf(__('%s changed to %s', true), $path, $mode);
return true;
}
$this->__errors[] = sprintf(__('%s NOT changed to %s', true), $path, $mode);
return false;
}
if (is_dir($path)) {
$paths = $this->tree($path);
foreach ($paths as $type) {
foreach ($type as $key => $fullpath) {
$check = explode(DS, $fullpath);
$count = count($check);
if (in_array($check[$count - 1], $exceptions)) {
continue;
}
if (@chmod($fullpath, intval($mode, 8))) {
$this->__messages[] = sprintf(__('%s changed to %s', true), $fullpath, $mode);
} else {
$this->__errors[] = sprintf(__('%s NOT changed to %s', true), $fullpath, $mode);
}
}
}
if (empty($this->__errors)) {
return true;
}
}
return false;
}
|
Change the mode on a directory structure recursively. This includes changing the mode on files as well.
@param string $path The path to chmod
@param integer $mode octal value 0755
@param boolean $recursive chmod recursively, set to false to only change the current directory.
@param array $exceptions array of files, directories to skip
@return boolean Returns TRUE on success, FALSE on failure
@access public
|
chmod
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function tree($path, $exceptions = true, $type = null) {
$original = $this->path;
$path = rtrim($path, DS);
if (!$this->cd($path)) {
if ($type === null) {
return array(array(), array());
}
return array();
}
$this->__files = array();
$this->__directories = array($this->realpath($path));
$directories = array();
if ($exceptions === false) {
$exceptions = true;
}
while (!empty($this->__directories)) {
$dir = array_pop($this->__directories);
$this->__tree($dir, $exceptions);
$directories[] = $dir;
}
if ($type === null) {
return array($directories, $this->__files);
}
if ($type === 'dir') {
return $directories;
}
$this->cd($original);
return $this->__files;
}
|
Returns an array of nested directories and files in each directory
@param string $path the directory path to build the tree from
@param mixed $exceptions Array of files to exclude, defaults to excluding hidden files.
@param string $type either file or dir. null returns both files and directories
@return mixed array of nested directories and files in each directory
@access public
|
tree
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function __tree($path, $exceptions) {
$this->path = $path;
list($dirs, $files) = $this->read(false, $exceptions, true);
$this->__directories = array_merge($this->__directories, $dirs);
$this->__files = array_merge($this->__files, $files);
}
|
Private method to list directories and files in each directory
@param string $path The Path to read.
@param mixed $exceptions Array of files to exclude from the read that will be performed.
@access private
|
__tree
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function create($pathname, $mode = false) {
if (is_dir($pathname) || empty($pathname)) {
return true;
}
if (!$mode) {
$mode = $this->mode;
}
if (is_file($pathname)) {
$this->__errors[] = sprintf(__('%s is a file', true), $pathname);
return false;
}
$pathname = rtrim($pathname, DS);
$nextPathname = substr($pathname, 0, strrpos($pathname, DS));
if ($this->create($nextPathname, $mode)) {
if (!file_exists($pathname)) {
$old = umask(0);
if (mkdir($pathname, $mode)) {
umask($old);
$this->__messages[] = sprintf(__('%s created', true), $pathname);
return true;
} else {
umask($old);
$this->__errors[] = sprintf(__('%s NOT created', true), $pathname);
return false;
}
}
}
return false;
}
|
Create a directory structure recursively. Can be used to create
deep path structures like `/foo/bar/baz/shoe/horn`
@param string $pathname The directory structure to create
@param integer $mode octal value 0755
@return boolean Returns TRUE on success, FALSE on failure
@access public
|
create
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function dirsize() {
$size = 0;
$directory = Folder::slashTerm($this->path);
$stack = array($directory);
$count = count($stack);
for ($i = 0, $j = $count; $i < $j; ++$i) {
if (is_file($stack[$i])) {
$size += filesize($stack[$i]);
} elseif (is_dir($stack[$i])) {
$dir = dir($stack[$i]);
if ($dir) {
while (false !== ($entry = $dir->read())) {
if ($entry === '.' || $entry === '..') {
continue;
}
$add = $stack[$i] . $entry;
if (is_dir($stack[$i] . $entry)) {
$add = Folder::slashTerm($add);
}
$stack[] = $add;
}
$dir->close();
}
}
$j = count($stack);
}
return $size;
}
|
Returns the size in bytes of this Folder and its contents.
@param string $directory Path to directory
@return int size in bytes of current folder
@access public
|
dirsize
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function delete($path = null) {
if (!$path) {
$path = $this->pwd();
}
if (!$path) {
return null;
}
$path = Folder::slashTerm($path);
if (is_dir($path) === true) {
$normalFiles = glob($path . '*');
$hiddenFiles = glob($path . '\.?*');
$normalFiles = $normalFiles ? $normalFiles : array();
$hiddenFiles = $hiddenFiles ? $hiddenFiles : array();
$files = array_merge($normalFiles, $hiddenFiles);
if (is_array($files)) {
foreach ($files as $file) {
if (preg_match('/(\.|\.\.)$/', $file)) {
continue;
}
if (is_file($file) === true) {
if (@unlink($file)) {
$this->__messages[] = sprintf(__('%s removed', true), $file);
} else {
$this->__errors[] = sprintf(__('%s NOT removed', true), $file);
}
} elseif (is_dir($file) === true && $this->delete($file) === false) {
return false;
}
}
}
$path = substr($path, 0, strlen($path) - 1);
if (rmdir($path) === false) {
$this->__errors[] = sprintf(__('%s NOT removed', true), $path);
return false;
} else {
$this->__messages[] = sprintf(__('%s removed', true), $path);
}
}
return true;
}
|
Recursively Remove directories if the system allows.
@param string $path Path of directory to delete
@return boolean Success
@access public
|
delete
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function copy($options = array()) {
if (!$this->pwd()) {
return false;
}
$to = null;
if (is_string($options)) {
$to = $options;
$options = array();
}
$options = array_merge(array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array()), $options);
$fromDir = $options['from'];
$toDir = $options['to'];
$mode = $options['mode'];
if (!$this->cd($fromDir)) {
$this->__errors[] = sprintf(__('%s not found', true), $fromDir);
return false;
}
if (!is_dir($toDir)) {
$this->create($toDir, $mode);
}
if (!is_writable($toDir)) {
$this->__errors[] = sprintf(__('%s not writable', true), $toDir);
return false;
}
$exceptions = array_merge(array('.', '..', '.svn'), $options['skip']);
if ($handle = @opendir($fromDir)) {
while (false !== ($item = readdir($handle))) {
if (!in_array($item, $exceptions)) {
$from = Folder::addPathElement($fromDir, $item);
$to = Folder::addPathElement($toDir, $item);
if (is_file($from)) {
if (copy($from, $to)) {
chmod($to, intval($mode, 8));
touch($to, filemtime($from));
$this->__messages[] = sprintf(__('%s copied to %s', true), $from, $to);
} else {
$this->__errors[] = sprintf(__('%s NOT copied to %s', true), $from, $to);
}
}
if (is_dir($from) && !file_exists($to)) {
$old = umask(0);
if (mkdir($to, $mode)) {
umask($old);
$old = umask(0);
chmod($to, $mode);
umask($old);
$this->__messages[] = sprintf(__('%s created', true), $to);
$options = array_merge($options, array('to'=> $to, 'from'=> $from));
$this->copy($options);
} else {
$this->__errors[] = sprintf(__('%s not created', true), $to);
}
}
}
}
closedir($handle);
} else {
return false;
}
if (!empty($this->__errors)) {
return false;
}
return true;
}
|
Recursive directory copy.
### Options
- `to` The directory to copy to.
- `from` The directory to copy from, this will cause a cd() to occur, changing the results of pwd().
- `mode` The mode to copy the files/directories with.
- `skip` Files/directories to skip.
@param mixed $options Either an array of options (see above) or a string of the destination directory.
@return bool Success
@access public
|
copy
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function move($options) {
$to = null;
if (is_string($options)) {
$to = $options;
$options = (array)$options;
}
$options = array_merge(array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array()), $options);
if ($this->copy($options)) {
if ($this->delete($options['from'])) {
return $this->cd($options['to']);
}
}
return false;
}
|
Recursive directory move.
### Options
- `to` The directory to copy to.
- `from` The directory to copy from, this will cause a cd() to occur, changing the results of pwd().
- `chmod` The mode to copy the files/directories with.
- `skip` Files/directories to skip.
@param array $options (to, from, chmod, skip)
@return boolean Success
@access public
|
move
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function messages() {
return $this->__messages;
}
|
get messages from latest method
@return array
@access public
|
messages
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function errors() {
return $this->__errors;
}
|
get error from latest method
@return array
@access public
|
errors
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function realpath($path) {
$path = str_replace('/', DS, trim($path));
if (strpos($path, '..') === false) {
if (!Folder::isAbsolute($path)) {
$path = Folder::addPathElement($this->path, $path);
}
return $path;
}
$parts = explode(DS, $path);
$newparts = array();
$newpath = '';
if ($path[0] === DS) {
$newpath = DS;
}
while (($part = array_shift($parts)) !== NULL) {
if ($part === '.' || $part === '') {
continue;
}
if ($part === '..') {
if (!empty($newparts)) {
array_pop($newparts);
continue;
} else {
return false;
}
}
$newparts[] = $part;
}
$newpath .= implode(DS, $newparts);
return Folder::slashTerm($newpath);
}
|
Get the real path (taking ".." and such into account)
@param string $path Path to resolve
@return string The resolved path
|
realpath
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function isSlashTerm($path) {
$lastChar = $path[strlen($path) - 1];
return $lastChar === '/' || $lastChar === '\\';
}
|
Returns true if given $path ends in a slash (i.e. is slash-terminated).
@param string $path Path to check
@return boolean true if path ends with slash, false otherwise
@access public
@static
|
isSlashTerm
|
php
|
Datawalke/Coordino
|
cake/libs/folder.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/folder.php
|
MIT
|
function __construct($config = array()) {
if (is_string($config)) {
$this->_configUri($config);
} elseif (is_array($config)) {
if (isset($config['request']['uri']) && is_string($config['request']['uri'])) {
$this->_configUri($config['request']['uri']);
unset($config['request']['uri']);
}
$this->config = Set::merge($this->config, $config);
}
parent::__construct($this->config);
}
|
Build an HTTP Socket using the specified configuration.
You can use a url string to set the url and use default configurations for
all other options:
`$http =& new HttpSocket('http://cakephp.org/');`
Or use an array to configure multiple options:
{{{
$http =& new HttpSocket(array(
'host' => 'cakephp.org',
'timeout' => 20
));
}}}
See HttpSocket::$config for options that can be used.
@param mixed $config Configuration information, either a string url or an array of options.
@access public
|
__construct
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function request($request = array()) {
$this->reset(false);
if (is_string($request)) {
$request = array('uri' => $request);
} elseif (!is_array($request)) {
return false;
}
if (!isset($request['uri'])) {
$request['uri'] = null;
}
$uri = $this->_parseUri($request['uri']);
$hadAuth = false;
if (is_array($uri) && array_key_exists('user', $uri)) {
$hadAuth = true;
}
if (!isset($uri['host'])) {
$host = $this->config['host'];
}
if (isset($request['host'])) {
$host = $request['host'];
unset($request['host']);
}
$request['uri'] = $this->url($request['uri']);
$request['uri'] = $this->_parseUri($request['uri'], true);
$this->request = Set::merge($this->request, $this->config['request'], $request);
if (!$hadAuth && !empty($this->config['request']['auth']['user'])) {
$this->request['uri']['user'] = $this->config['request']['auth']['user'];
$this->request['uri']['pass'] = $this->config['request']['auth']['pass'];
}
$this->_configUri($this->request['uri']);
if (isset($host)) {
$this->config['host'] = $host;
}
$cookies = null;
if (is_array($this->request['header'])) {
$this->request['header'] = $this->_parseHeader($this->request['header']);
if (!empty($this->request['cookies'])) {
$cookies = $this->buildCookies($this->request['cookies']);
}
$Host = $this->request['uri']['host'];
$schema = '';
$port = 0;
if (isset($this->request['uri']['schema'])) {
$schema = $this->request['uri']['schema'];
}
if (isset($this->request['uri']['port'])) {
$port = $this->request['uri']['port'];
}
if (
($schema === 'http' && $port != 80) ||
($schema === 'https' && $port != 443) ||
($port != 80 && $port != 443)
) {
$Host .= ':' . $port;
}
$this->request['header'] = array_merge(compact('Host'), $this->request['header']);
}
if (isset($this->request['auth']['user']) && isset($this->request['auth']['pass'])) {
$this->request['header']['Authorization'] = $this->request['auth']['method'] . " " . base64_encode($this->request['auth']['user'] . ":" . $this->request['auth']['pass']);
}
if (isset($this->request['uri']['user']) && isset($this->request['uri']['pass'])) {
$this->request['header']['Authorization'] = $this->request['auth']['method'] . " " . base64_encode($this->request['uri']['user'] . ":" . $this->request['uri']['pass']);
}
if (is_array($this->request['body'])) {
$this->request['body'] = $this->_httpSerialize($this->request['body']);
}
if (!empty($this->request['body']) && !isset($this->request['header']['Content-Type'])) {
$this->request['header']['Content-Type'] = 'application/x-www-form-urlencoded';
}
if (!empty($this->request['body']) && !isset($this->request['header']['Content-Length'])) {
$this->request['header']['Content-Length'] = strlen($this->request['body']);
}
$connectionType = null;
if (isset($this->request['header']['Connection'])) {
$connectionType = $this->request['header']['Connection'];
}
$this->request['header'] = $this->_buildHeader($this->request['header']) . $cookies;
if (empty($this->request['line'])) {
$this->request['line'] = $this->_buildRequestLine($this->request);
}
if ($this->quirksMode === false && $this->request['line'] === false) {
return $this->response = false;
}
if ($this->request['line'] !== false) {
$this->request['raw'] = $this->request['line'];
}
if ($this->request['header'] !== false) {
$this->request['raw'] .= $this->request['header'];
}
$this->request['raw'] .= "\r\n";
$this->request['raw'] .= $this->request['body'];
$this->write($this->request['raw']);
$response = null;
while ($data = $this->read()) {
$response .= $data;
}
if ($connectionType == 'close') {
$this->disconnect();
}
$this->response = $this->_parseResponse($response);
if (!empty($this->response['cookies'])) {
$this->config['request']['cookies'] = array_merge($this->config['request']['cookies'], $this->response['cookies']);
}
return $this->response['body'];
}
|
Issue the specified request. HttpSocket::get() and HttpSocket::post() wrap this
method and provide a more granular interface.
@param mixed $request Either an URI string, or an array defining host/uri
@return mixed false on error, request body on success
@access public
|
request
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function get($uri = null, $query = array(), $request = array()) {
if (!empty($query)) {
$uri = $this->_parseUri($uri);
if (isset($uri['query'])) {
$uri['query'] = array_merge($uri['query'], $query);
} else {
$uri['query'] = $query;
}
$uri = $this->_buildUri($uri);
}
$request = Set::merge(array('method' => 'GET', 'uri' => $uri), $request);
return $this->request($request);
}
|
Issues a GET request to the specified URI, query, and request.
Using a string uri and an array of query string parameters:
`$response = $http->get('http://google.com/search', array('q' => 'cakephp', 'client' => 'safari'));`
Would do a GET request to `http://google.com/search?q=cakephp&client=safari`
You could express the same thing using a uri array and query string parameters:
{{{
$response = $http->get(
array('host' => 'google.com', 'path' => '/search'),
array('q' => 'cakephp', 'client' => 'safari')
);
}}}
@param mixed $uri URI to request. Either a string uri, or a uri array, see HttpSocket::_parseUri()
@param array $query Querystring parameters to append to URI
@param array $request An indexed array with indexes such as 'method' or uri
@return mixed Result of request, either false on failure or the response to the request.
@access public
|
get
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function post($uri = null, $data = array(), $request = array()) {
$request = Set::merge(array('method' => 'POST', 'uri' => $uri, 'body' => $data), $request);
return $this->request($request);
}
|
Issues a POST request to the specified URI, query, and request.
`post()` can be used to post simple data arrays to a url:
{{{
$response = $http->post('http://example.com', array(
'username' => 'batman',
'password' => 'bruce_w4yne'
));
}}}
@param mixed $uri URI to request. See HttpSocket::_parseUri()
@param array $data Array of POST data keys and values.
@param array $request An indexed array with indexes such as 'method' or uri
@return mixed Result of request, either false on failure or the response to the request.
@access public
|
post
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function put($uri = null, $data = array(), $request = array()) {
$request = Set::merge(array('method' => 'PUT', 'uri' => $uri, 'body' => $data), $request);
return $this->request($request);
}
|
Issues a PUT request to the specified URI, query, and request.
@param mixed $uri URI to request, See HttpSocket::_parseUri()
@param array $data Array of PUT data keys and values.
@param array $request An indexed array with indexes such as 'method' or uri
@return mixed Result of request
@access public
|
put
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function delete($uri = null, $data = array(), $request = array()) {
$request = Set::merge(array('method' => 'DELETE', 'uri' => $uri, 'body' => $data), $request);
return $this->request($request);
}
|
Issues a DELETE request to the specified URI, query, and request.
@param mixed $uri URI to request (see {@link _parseUri()})
@param array $data Query to append to URI
@param array $request An indexed array with indexes such as 'method' or uri
@return mixed Result of request
@access public
|
delete
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function url($url = null, $uriTemplate = null) {
if (is_null($url)) {
$url = '/';
}
if (is_string($url)) {
if ($url{0} == '/') {
$url = $this->config['request']['uri']['host'].':'.$this->config['request']['uri']['port'] . $url;
}
if (!preg_match('/^.+:\/\/|\*|^\//', $url)) {
$url = $this->config['request']['uri']['scheme'].'://'.$url;
}
} elseif (!is_array($url) && !empty($url)) {
return false;
}
$base = array_merge($this->config['request']['uri'], array('scheme' => array('http', 'https'), 'port' => array(80, 443)));
$url = $this->_parseUri($url, $base);
if (empty($url)) {
$url = $this->config['request']['uri'];
}
if (!empty($uriTemplate)) {
return $this->_buildUri($url, $uriTemplate);
}
return $this->_buildUri($url);
}
|
Normalizes urls into a $uriTemplate. If no template is provided
a default one will be used. Will generate the url using the
current config information.
### Usage:
After configuring part of the request parameters, you can use url() to generate
urls.
{{{
$http->configUri('http://www.cakephp.org');
$url = $http->url('/search?q=bar');
}}}
Would return `http://www.cakephp.org/search?q=bar`
url() can also be used with custom templates:
`$url = $http->url('http://www.cakephp/search?q=socket', '/%path?%query');`
Would return `/search?q=socket`.
@param mixed $url Either a string or array of url options to create a url with.
@param string $uriTemplate A template string to use for url formatting.
@return mixed Either false on failure or a string containing the composed url.
@access public
|
url
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _parseResponse($message) {
if (is_array($message)) {
return $message;
} elseif (!is_string($message)) {
return false;
}
static $responseTemplate;
if (empty($responseTemplate)) {
$classVars = get_class_vars(__CLASS__);
$responseTemplate = $classVars['response'];
}
$response = $responseTemplate;
if (!preg_match("/^(.+\r\n)(.*)(?<=\r\n)\r\n/Us", $message, $match)) {
return false;
}
list($null, $response['raw']['status-line'], $response['raw']['header']) = $match;
$response['raw']['response'] = $message;
$response['raw']['body'] = substr($message, strlen($match[0]));
if (preg_match("/(.+) ([0-9]{3}) (.+)\r\n/DU", $response['raw']['status-line'], $match)) {
$response['status']['http-version'] = $match[1];
$response['status']['code'] = (int)$match[2];
$response['status']['reason-phrase'] = $match[3];
}
$response['header'] = $this->_parseHeader($response['raw']['header']);
$transferEncoding = null;
if (isset($response['header']['Transfer-Encoding'])) {
$transferEncoding = $response['header']['Transfer-Encoding'];
}
$decoded = $this->_decodeBody($response['raw']['body'], $transferEncoding);
$response['body'] = $decoded['body'];
if (!empty($decoded['header'])) {
$response['header'] = $this->_parseHeader($this->_buildHeader($response['header']).$this->_buildHeader($decoded['header']));
}
if (!empty($response['header'])) {
$response['cookies'] = $this->parseCookies($response['header']);
}
foreach ($response['raw'] as $field => $val) {
if ($val === '') {
$response['raw'][$field] = null;
}
}
return $response;
}
|
Parses the given message and breaks it down in parts.
@param string $message Message to parse
@return array Parsed message (with indexed elements such as raw, status, header, body)
@access protected
|
_parseResponse
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _decodeBody($body, $encoding = 'chunked') {
if (!is_string($body)) {
return false;
}
if (empty($encoding)) {
return array('body' => $body, 'header' => false);
}
$decodeMethod = '_decode'.Inflector::camelize(str_replace('-', '_', $encoding)).'Body';
if (!is_callable(array(&$this, $decodeMethod))) {
if (!$this->quirksMode) {
trigger_error(sprintf(__('HttpSocket::_decodeBody - Unknown encoding: %s. Activate quirks mode to surpress error.', true), h($encoding)), E_USER_WARNING);
}
return array('body' => $body, 'header' => false);
}
return $this->{$decodeMethod}($body);
}
|
Generic function to decode a $body with a given $encoding. Returns either an array with the keys
'body' and 'header' or false on failure.
@param string $body A string continaing the body to decode.
@param mixed $encoding Can be false in case no encoding is being used, or a string representing the encoding.
@return mixed Array of response headers and body or false.
@access protected
|
_decodeBody
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _decodeChunkedBody($body) {
if (!is_string($body)) {
return false;
}
$decodedBody = null;
$chunkLength = null;
while ($chunkLength !== 0) {
if (!preg_match("/^([0-9a-f]+) *(?:;(.+)=(.+))?\r\n/iU", $body, $match)) {
if (!$this->quirksMode) {
trigger_error(__('HttpSocket::_decodeChunkedBody - Could not parse malformed chunk. Activate quirks mode to do this.', true), E_USER_WARNING);
return false;
}
break;
}
$chunkSize = 0;
$hexLength = 0;
$chunkExtensionName = '';
$chunkExtensionValue = '';
if (isset($match[0])) {
$chunkSize = $match[0];
}
if (isset($match[1])) {
$hexLength = $match[1];
}
if (isset($match[2])) {
$chunkExtensionName = $match[2];
}
if (isset($match[3])) {
$chunkExtensionValue = $match[3];
}
$body = substr($body, strlen($chunkSize));
$chunkLength = hexdec($hexLength);
$chunk = substr($body, 0, $chunkLength);
if (!empty($chunkExtensionName)) {
/**
* @todo See if there are popular chunk extensions we should implement
*/
}
$decodedBody .= $chunk;
if ($chunkLength !== 0) {
$body = substr($body, $chunkLength+strlen("\r\n"));
}
}
$entityHeader = false;
if (!empty($body)) {
$entityHeader = $this->_parseHeader($body);
}
return array('body' => $decodedBody, 'header' => $entityHeader);
}
|
Decodes a chunked message $body and returns either an array with the keys 'body' and 'header' or false as
a result.
@param string $body A string continaing the chunked body to decode.
@return mixed Array of response headers and body or false.
@access protected
|
_decodeChunkedBody
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _configUri($uri = null) {
if (empty($uri)) {
return false;
}
if (is_array($uri)) {
$uri = $this->_parseUri($uri);
} else {
$uri = $this->_parseUri($uri, true);
}
if (!isset($uri['host'])) {
return false;
}
$config = array(
'request' => array(
'uri' => array_intersect_key($uri, $this->config['request']['uri']),
'auth' => array_intersect_key($uri, $this->config['request']['auth'])
)
);
$this->config = Set::merge($this->config, $config);
$this->config = Set::merge($this->config, array_intersect_key($this->config['request']['uri'], $this->config));
return $this->config;
}
|
Parses and sets the specified URI into current request configuration.
@param mixed $uri URI, See HttpSocket::_parseUri()
@return array Current configuration settings
@access protected
|
_configUri
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _buildUri($uri = array(), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment') {
if (is_string($uri)) {
$uri = array('host' => $uri);
}
$uri = $this->_parseUri($uri, true);
if (!is_array($uri) || empty($uri)) {
return false;
}
$uri['path'] = preg_replace('/^\//', null, $uri['path']);
$uri['query'] = $this->_httpSerialize($uri['query']);
$stripIfEmpty = array(
'query' => '?%query',
'fragment' => '#%fragment',
'user' => '%user:%pass@',
'host' => '%host:%port/'
);
foreach ($stripIfEmpty as $key => $strip) {
if (empty($uri[$key])) {
$uriTemplate = str_replace($strip, null, $uriTemplate);
}
}
$defaultPorts = array('http' => 80, 'https' => 443);
if (array_key_exists($uri['scheme'], $defaultPorts) && $defaultPorts[$uri['scheme']] == $uri['port']) {
$uriTemplate = str_replace(':%port', null, $uriTemplate);
}
foreach ($uri as $property => $value) {
$uriTemplate = str_replace('%'.$property, $value, $uriTemplate);
}
if ($uriTemplate === '/*') {
$uriTemplate = '*';
}
return $uriTemplate;
}
|
Takes a $uri array and turns it into a fully qualified URL string
@param mixed $uri Either A $uri array, or a request string. Will use $this->config if left empty.
@param string $uriTemplate The Uri template/format to use.
@return mixed A fully qualified URL formated according to $uriTemplate, or false on failure
@access protected
|
_buildUri
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _parseUri($uri = null, $base = array()) {
$uriBase = array(
'scheme' => array('http', 'https'),
'host' => null,
'port' => array(80, 443),
'user' => null,
'pass' => null,
'path' => '/',
'query' => null,
'fragment' => null
);
if (is_string($uri)) {
$uri = parse_url($uri);
}
if (!is_array($uri) || empty($uri)) {
return false;
}
if ($base === true) {
$base = $uriBase;
}
if (isset($base['port'], $base['scheme']) && is_array($base['port']) && is_array($base['scheme'])) {
if (isset($uri['scheme']) && !isset($uri['port'])) {
$base['port'] = $base['port'][array_search($uri['scheme'], $base['scheme'])];
} elseif (isset($uri['port']) && !isset($uri['scheme'])) {
$base['scheme'] = $base['scheme'][array_search($uri['port'], $base['port'])];
}
}
if (is_array($base) && !empty($base)) {
$uri = array_merge($base, $uri);
}
if (isset($uri['scheme']) && is_array($uri['scheme'])) {
$uri['scheme'] = array_shift($uri['scheme']);
}
if (isset($uri['port']) && is_array($uri['port'])) {
$uri['port'] = array_shift($uri['port']);
}
if (array_key_exists('query', $uri)) {
$uri['query'] = $this->_parseQuery($uri['query']);
}
if (!array_intersect_key($uriBase, $uri)) {
return false;
}
return $uri;
}
|
Parses the given URI and breaks it down into pieces as an indexed array with elements
such as 'scheme', 'port', 'query'.
@param string $uri URI to parse
@param mixed $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc.
@return array Parsed URI
@access protected
|
_parseUri
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _parseQuery($query) {
if (is_array($query)) {
return $query;
}
$parsedQuery = array();
if (is_string($query) && !empty($query)) {
$query = preg_replace('/^\?/', '', $query);
$items = explode('&', $query);
foreach ($items as $item) {
if (strpos($item, '=') !== false) {
list($key, $value) = explode('=', $item, 2);
} else {
$key = $item;
$value = null;
}
$key = urldecode($key);
$value = urldecode($value);
if (preg_match_all('/\[([^\[\]]*)\]/iUs', $key, $matches)) {
$subKeys = $matches[1];
$rootKey = substr($key, 0, strpos($key, '['));
if (!empty($rootKey)) {
array_unshift($subKeys, $rootKey);
}
$queryNode =& $parsedQuery;
foreach ($subKeys as $subKey) {
if (!is_array($queryNode)) {
$queryNode = array();
}
if ($subKey === '') {
$queryNode[] = array();
end($queryNode);
$subKey = key($queryNode);
}
$queryNode =& $queryNode[$subKey];
}
$queryNode = $value;
} else {
$parsedQuery[$key] = $value;
}
}
}
return $parsedQuery;
}
|
This function can be thought of as a reverse to PHP5's http_build_query(). It takes a given query string and turns it into an array and
supports nesting by using the php bracket syntax. So this menas you can parse queries like:
- ?key[subKey]=value
- ?key[]=value1&key[]=value2
A leading '?' mark in $query is optional and does not effect the outcome of this function.
For the complete capabilities of this implementation take a look at HttpSocketTest::testparseQuery()
@param mixed $query A query string to parse into an array or an array to return directly "as is"
@return array The $query parsed into a possibly multi-level array. If an empty $query is
given, an empty array is returned.
@access protected
|
_parseQuery
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') {
$asteriskMethods = array('OPTIONS');
if (is_string($request)) {
$isValid = preg_match("/(.+) (.+) (.+)\r\n/U", $request, $match);
if (!$this->quirksMode && (!$isValid || ($match[2] == '*' && !in_array($match[3], $asteriskMethods)))) {
trigger_error(__('HttpSocket::_buildRequestLine - Passed an invalid request line string. Activate quirks mode to do this.', true), E_USER_WARNING);
return false;
}
return $request;
} elseif (!is_array($request)) {
return false;
} elseif (!array_key_exists('uri', $request)) {
return false;
}
$request['uri'] = $this->_parseUri($request['uri']);
$request = array_merge(array('method' => 'GET'), $request);
$request['uri'] = $this->_buildUri($request['uri'], '/%path?%query');
if (!$this->quirksMode && $request['uri'] === '*' && !in_array($request['method'], $asteriskMethods)) {
trigger_error(sprintf(__('HttpSocket::_buildRequestLine - The "*" asterisk character is only allowed for the following methods: %s. Activate quirks mode to work outside of HTTP/1.1 specs.', true), join(',', $asteriskMethods)), E_USER_WARNING);
return false;
}
return $request['method'].' '.$request['uri'].' '.$versionToken.$this->lineBreak;
}
|
Builds a request line according to HTTP/1.1 specs. Activate quirks mode to work outside specs.
@param array $request Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET.
@param string $versionToken The version token to use, defaults to HTTP/1.1
@return string Request line
@access protected
|
_buildRequestLine
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _httpSerialize($data = array()) {
if (is_string($data)) {
return $data;
}
if (empty($data) || !is_array($data)) {
return false;
}
return substr(Router::queryString($data), 1);
}
|
Serializes an array for transport.
@param array $data Data to serialize
@return string Serialized variable
@access protected
|
_httpSerialize
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _buildHeader($header, $mode = 'standard') {
if (is_string($header)) {
return $header;
} elseif (!is_array($header)) {
return false;
}
$returnHeader = '';
foreach ($header as $field => $contents) {
if (is_array($contents) && $mode == 'standard') {
$contents = implode(',', $contents);
}
foreach ((array)$contents as $content) {
$contents = preg_replace("/\r\n(?![\t ])/", "\r\n ", $content);
$field = $this->_escapeToken($field);
$returnHeader .= $field.': '.$contents.$this->lineBreak;
}
}
return $returnHeader;
}
|
Builds the header.
@param array $header Header to build
@return string Header built from array
@access protected
|
_buildHeader
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _parseHeader($header) {
if (is_array($header)) {
foreach ($header as $field => $value) {
unset($header[$field]);
$field = strtolower($field);
preg_match_all('/(?:^|(?<=-))[a-z]/U', $field, $offsets, PREG_OFFSET_CAPTURE);
foreach ($offsets[0] as $offset) {
$field = substr_replace($field, strtoupper($offset[0]), $offset[1], 1);
}
$header[$field] = $value;
}
return $header;
} elseif (!is_string($header)) {
return false;
}
preg_match_all("/(.+):(.+)(?:(?<![\t ])" . $this->lineBreak . "|\$)/Uis", $header, $matches, PREG_SET_ORDER);
$header = array();
foreach ($matches as $match) {
list(, $field, $value) = $match;
$value = trim($value);
$value = preg_replace("/[\t ]\r\n/", "\r\n", $value);
$field = $this->_unescapeToken($field);
$field = strtolower($field);
preg_match_all('/(?:^|(?<=-))[a-z]/U', $field, $offsets, PREG_OFFSET_CAPTURE);
foreach ($offsets[0] as $offset) {
$field = substr_replace($field, strtoupper($offset[0]), $offset[1], 1);
}
if (!isset($header[$field])) {
$header[$field] = $value;
} else {
$header[$field] = array_merge((array)$header[$field], (array)$value);
}
}
return $header;
}
|
Parses an array based header.
@param array $header Header as an indexed array (field => value)
@return array Parsed header
@access protected
|
_parseHeader
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function parseCookies($header) {
if (!isset($header['Set-Cookie'])) {
return false;
}
$cookies = array();
foreach ((array)$header['Set-Cookie'] as $cookie) {
if (strpos($cookie, '";"') !== false) {
$cookie = str_replace('";"', "{__cookie_replace__}", $cookie);
$parts = str_replace("{__cookie_replace__}", '";"', explode(';', $cookie));
} else {
$parts = preg_split('/\;[ \t]*/', $cookie);
}
list($name, $value) = explode('=', array_shift($parts), 2);
$cookies[$name] = compact('value');
foreach ($parts as $part) {
if (strpos($part, '=') !== false) {
list($key, $value) = explode('=', $part);
} else {
$key = $part;
$value = true;
}
$key = strtolower($key);
if (!isset($cookies[$name][$key])) {
$cookies[$name][$key] = $value;
}
}
}
return $cookies;
}
|
Parses cookies in response headers.
@param array $header Header array containing one ore more 'Set-Cookie' headers.
@return mixed Either false on no cookies, or an array of cookies received.
@access public
@todo Make this 100% RFC 2965 confirm
|
parseCookies
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function buildCookies($cookies) {
$header = array();
foreach ($cookies as $name => $cookie) {
$header[] = $name.'='.$this->_escapeToken($cookie['value'], array(';'));
}
$header = $this->_buildHeader(array('Cookie' => implode('; ', $header)), 'pragmatic');
return $header;
}
|
Builds cookie headers for a request.
@param array $cookies Array of cookies to send with the request.
@return string Cookie header string to be sent with the request.
@access public
@todo Refactor token escape mechanism to be configurable
|
buildCookies
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _unescapeToken($token, $chars = null) {
$regex = '/"(['.join('', $this->_tokenEscapeChars(true, $chars)).'])"/';
$token = preg_replace($regex, '\\1', $token);
return $token;
}
|
Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs)
@param string $token Token to unescape
@return string Unescaped token
@access protected
@todo Test $chars parameter
|
_unescapeToken
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _escapeToken($token, $chars = null) {
$regex = '/(['.join('', $this->_tokenEscapeChars(true, $chars)).'])/';
$token = preg_replace($regex, '"\\1"', $token);
return $token;
}
|
Escapes a given $token according to RFC 2616 (HTTP 1.1 specs)
@param string $token Token to escape
@return string Escaped token
@access protected
@todo Test $chars parameter
|
_escapeToken
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function _tokenEscapeChars($hex = true, $chars = null) {
if (!empty($chars)) {
$escape = $chars;
} else {
$escape = array('"', "(", ")", "<", ">", "@", ",", ";", ":", "\\", "/", "[", "]", "?", "=", "{", "}", " ");
for ($i = 0; $i <= 31; $i++) {
$escape[] = chr($i);
}
$escape[] = chr(127);
}
if ($hex == false) {
return $escape;
}
$regexChars = '';
foreach ($escape as $key => $char) {
$escape[$key] = '\\x'.str_pad(dechex(ord($char)), 2, '0', STR_PAD_LEFT);
}
return $escape;
}
|
Gets escape chars according to RFC 2616 (HTTP 1.1 specs).
@param boolean $hex true to get them as HEX values, false otherwise
@return array Escape chars
@access protected
@todo Test $chars parameter
|
_tokenEscapeChars
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function reset($full = true) {
static $initalState = array();
if (empty($initalState)) {
$initalState = get_class_vars(__CLASS__);
}
if ($full == false) {
$this->request = $initalState['request'];
$this->response = $initalState['response'];
return true;
}
parent::reset($initalState);
return true;
}
|
Resets the state of this HttpSocket instance to it's initial state (before Object::__construct got executed) or does
the same thing partially for the request and the response property only.
@param boolean $full If set to false only HttpSocket::response and HttpSocket::request are reseted
@return boolean True on success
@access public
|
reset
|
php
|
Datawalke/Coordino
|
cake/libs/http_socket.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/http_socket.php
|
MIT
|
function &getInstance() {
static $instance = array();
if (!$instance) {
$instance[0] =& new I18n();
$instance[0]->l10n =& new L10n();
}
return $instance[0];
}
|
Return a static instance of the I18n class
@return object I18n
@access public
|
getInstance
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function translate($singular, $plural = null, $domain = null, $category = 6, $count = null) {
$_this =& I18n::getInstance();
if (strpos($singular, "\r\n") !== false) {
$singular = str_replace("\r\n", "\n", $singular);
}
if ($plural !== null && strpos($plural, "\r\n") !== false) {
$plural = str_replace("\r\n", "\n", $plural);
}
if (is_numeric($category)) {
$_this->category = $_this->__categories[$category];
}
$language = Configure::read('Config.language');
if (!empty($_SESSION['Config']['language'])) {
$language = $_SESSION['Config']['language'];
}
if (($_this->__lang && $_this->__lang !== $language) || !$_this->__lang) {
$lang = $_this->l10n->get($language);
$_this->__lang = $lang;
}
if (is_null($domain)) {
$domain = 'default';
}
$_this->domain = $domain . '_' . $_this->l10n->lang;
if (!isset($_this->__domains[$domain][$_this->__lang])) {
$_this->__domains[$domain][$_this->__lang] = Cache::read($_this->domain, '_cake_core_');
}
if (!isset($_this->__domains[$domain][$_this->__lang][$_this->category])) {
$_this->__bindTextDomain($domain);
Cache::write($_this->domain, $_this->__domains[$domain][$_this->__lang], '_cake_core_');
}
if ($_this->category == 'LC_TIME') {
return $_this->__translateTime($singular,$domain);
}
if (!isset($count)) {
$plurals = 0;
} elseif (!empty($_this->__domains[$domain][$_this->__lang][$_this->category]["%plural-c"]) && $_this->__noLocale === false) {
$header = $_this->__domains[$domain][$_this->__lang][$_this->category]["%plural-c"];
$plurals = $_this->__pluralGuess($header, $count);
} else {
if ($count != 1) {
$plurals = 1;
} else {
$plurals = 0;
}
}
if (!empty($_this->__domains[$domain][$_this->__lang][$_this->category][$singular])) {
if (($trans = $_this->__domains[$domain][$_this->__lang][$_this->category][$singular]) || ($plurals) && ($trans = $_this->__domains[$domain][$_this->__lang][$_this->category][$plural])) {
if (is_array($trans)) {
if (isset($trans[$plurals])) {
$trans = $trans[$plurals];
}
}
if (strlen($trans)) {
return $trans;
}
}
}
if (!empty($plurals)) {
return $plural;
}
return $singular;
}
|
Used by the translation functions in basics.php
Can also be used like I18n::translate(); but only if the App::import('I18n'); has been used to load the class.
@param string $singular String to translate
@param string $plural Plural string (if any)
@param string $domain Domain The domain of the translation. Domains are often used by plugin translations
@param string $category Category The integer value of the category to use.
@param integer $count Count Count is used with $plural to choose the correct plural form.
@return string translated string.
@access public
|
translate
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function clear() {
$self =& I18n::getInstance();
$self->__domains = array();
}
|
Clears the domains internal data array. Useful for testing i18n.
@return void
|
clear
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function __pluralGuess($header, $n) {
if (!is_string($header) || $header === "nplurals=1;plural=0;" || !isset($header[0])) {
return 0;
}
if ($header === "nplurals=2;plural=n!=1;") {
return $n != 1 ? 1 : 0;
} elseif ($header === "nplurals=2;plural=n>1;") {
return $n > 1 ? 1 : 0;
}
if (strpos($header, "plurals=3")) {
if (strpos($header, "100!=11")) {
if (strpos($header, "10<=4")) {
return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
} elseif (strpos($header, "100<10")) {
return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
}
return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n != 0 ? 1 : 2);
} elseif (strpos($header, "n==2")) {
return $n == 1 ? 0 : ($n == 2 ? 1 : 2);
} elseif (strpos($header, "n==0")) {
return $n == 1 ? 0 : ($n == 0 || ($n % 100 > 0 && $n % 100 < 20) ? 1 : 2);
} elseif (strpos($header, "n>=2")) {
return $n == 1 ? 0 : ($n >= 2 && $n <= 4 ? 1 : 2);
} elseif (strpos($header, "10>=2")) {
return $n == 1 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
}
return $n % 10 == 1 ? 0 : ($n % 10 == 2 ? 1 : 2);
} elseif (strpos($header, "plurals=4")) {
if (strpos($header, "100==2")) {
return $n % 100 == 1 ? 0 : ($n % 100 == 2 ? 1 : ($n % 100 == 3 || $n % 100 == 4 ? 2 : 3));
} elseif (strpos($header, "n>=3")) {
return $n == 1 ? 0 : ($n == 2 ? 1 : ($n == 0 || ($n >= 3 && $n <= 10) ? 2 : 3));
} elseif (strpos($header, "100>=1")) {
return $n == 1 ? 0 : ($n == 0 || ($n % 100 >= 1 && $n % 100 <= 10) ? 1 : ($n % 100 >= 11 && $n % 100 <= 20 ? 2 : 3));
}
} elseif (strpos($header, "plurals=5")) {
return $n == 1 ? 0 : ($n == 2 ? 1 : ($n >= 3 && $n <= 6 ? 2 : ($n >= 7 && $n <= 10 ? 3 : 4)));
}
}
|
Attempts to find the plural form of a string.
@param string $header Type
@param integrer $n Number
@return integer plural match
@access private
|
__pluralGuess
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function __bindTextDomain($domain) {
$this->__noLocale = true;
$core = true;
$merge = array();
$searchPaths = App::path('locales');
$plugins = App::objects('plugin');
if (!empty($plugins)) {
foreach ($plugins as $plugin) {
$plugin = Inflector::underscore($plugin);
if ($plugin === $domain) {
$searchPaths[] = App::pluginPath($plugin) . DS . 'locale' . DS;
$searchPaths = array_reverse($searchPaths);
break;
}
}
}
foreach ($searchPaths as $directory) {
foreach ($this->l10n->languagePath as $lang) {
$file = $directory . $lang . DS . $this->category . DS . $domain;
$localeDef = $directory . $lang . DS . $this->category;
if ($core) {
$app = $directory . $lang . DS . $this->category . DS . 'core';
if (file_exists($fn = "$app.mo")) {
$this->__loadMo($fn, $domain);
$this->__noLocale = false;
$merge[$domain][$this->__lang][$this->category] = $this->__domains[$domain][$this->__lang][$this->category];
$core = null;
} elseif (file_exists($fn = "$app.po") && ($f = fopen($fn, "r"))) {
$this->__loadPo($f, $domain);
$this->__noLocale = false;
$merge[$domain][$this->__lang][$this->category] = $this->__domains[$domain][$this->__lang][$this->category];
$core = null;
}
}
if (file_exists($fn = "$file.mo")) {
$this->__loadMo($fn, $domain);
$this->__noLocale = false;
break 2;
} elseif (file_exists($fn = "$file.po") && ($f = fopen($fn, "r"))) {
$this->__loadPo($f, $domain);
$this->__noLocale = false;
break 2;
} elseif (is_file($localeDef) && ($f = fopen($localeDef, "r"))) {
$this->__loadLocaleDefinition($f, $domain);
$this->__noLocale = false;
return $domain;
}
}
}
if (empty($this->__domains[$domain][$this->__lang][$this->category])) {
$this->__domains[$domain][$this->__lang][$this->category] = array();
return $domain;
}
if (isset($this->__domains[$domain][$this->__lang][$this->category][""])) {
$head = $this->__domains[$domain][$this->__lang][$this->category][""];
foreach (explode("\n", $head) as $line) {
$header = strtok($line,":");
$line = trim(strtok("\n"));
$this->__domains[$domain][$this->__lang][$this->category]["%po-header"][strtolower($header)] = $line;
}
if (isset($this->__domains[$domain][$this->__lang][$this->category]["%po-header"]["plural-forms"])) {
$switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->__domains[$domain][$this->__lang][$this->category]["%po-header"]["plural-forms"]);
$this->__domains[$domain][$this->__lang][$this->category]["%plural-c"] = $switch;
unset($this->__domains[$domain][$this->__lang][$this->category]["%po-header"]);
}
$this->__domains = Set::pushDiff($this->__domains, $merge);
if (isset($this->__domains[$domain][$this->__lang][$this->category][null])) {
unset($this->__domains[$domain][$this->__lang][$this->category][null]);
}
}
return $domain;
}
|
Binds the given domain to a file in the specified directory.
@param string $domain Domain to bind
@return string Domain binded
@access private
|
__bindTextDomain
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function __loadMo($file, $domain) {
$data = file_get_contents($file);
if ($data) {
$header = substr($data, 0, 20);
$header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
extract($header);
if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && $version == 0) {
for ($n = 0; $n < $count; $n++) {
$r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
$msgid = substr($data, $r["offs"], $r["len"]);
unset($msgid_plural);
if (strpos($msgid, "\000")) {
list($msgid, $msgid_plural) = explode("\000", $msgid);
}
$r = unpack("L1len/L1offs", substr($data, $o_trn + $n * 8, 8));
$msgstr = substr($data, $r["offs"], $r["len"]);
if (strpos($msgstr, "\000")) {
$msgstr = explode("\000", $msgstr);
}
$this->__domains[$domain][$this->__lang][$this->category][$msgid] = $msgstr;
if (isset($msgid_plural)) {
$this->__domains[$domain][$this->__lang][$this->category][$msgid_plural] =& $this->__domains[$domain][$this->__lang][$this->category][$msgid];
}
}
}
}
}
|
Loads the binary .mo file for translation and sets the values for this translation in the var I18n::__domains
@param resource $file Binary .mo file to load
@param string $domain Domain where to load file in
@access private
|
__loadMo
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function __loadPo($file, $domain) {
$type = 0;
$translations = array();
$translationKey = "";
$plural = 0;
$header = "";
do {
$line = trim(fgets($file));
if ($line == "" || $line[0] == "#") {
continue;
}
if (preg_match("/msgid[[:space:]]+\"(.+)\"$/i", $line, $regs)) {
$type = 1;
$translationKey = stripcslashes($regs[1]);
} elseif (preg_match("/msgid[[:space:]]+\"\"$/i", $line, $regs)) {
$type = 2;
$translationKey = "";
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && ($type == 1 || $type == 2 || $type == 3)) {
$type = 3;
$translationKey .= stripcslashes($regs[1]);
} elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
$translations[$translationKey] = stripcslashes($regs[1]);
$type = 4;
} elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && ($type == 1 || $type == 3) && $translationKey) {
$type = 4;
$translations[$translationKey] = "";
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 4 && $translationKey) {
$translations[$translationKey] .= stripcslashes($regs[1]);
} elseif (preg_match("/msgid_plural[[:space:]]+\".*\"$/i", $line, $regs)) {
$type = 6;
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 6 && $translationKey) {
$type = 6;
} elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"(.+)\"$/i", $line, $regs) && ($type == 6 || $type == 7) && $translationKey) {
$plural = $regs[1];
$translations[$translationKey][$plural] = stripcslashes($regs[2]);
$type = 7;
} elseif (preg_match("/msgstr\[(\d+)\][[:space:]]+\"\"$/i", $line, $regs) && ($type == 6 || $type == 7) && $translationKey) {
$plural = $regs[1];
$translations[$translationKey][$plural] = "";
$type = 7;
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 7 && $translationKey) {
$translations[$translationKey][$plural] .= stripcslashes($regs[1]);
} elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && $type == 2 && !$translationKey) {
$header .= stripcslashes($regs[1]);
$type = 5;
} elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && !$translationKey) {
$header = "";
$type = 5;
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 5) {
$header .= stripcslashes($regs[1]);
} else {
unset($translations[$translationKey]);
$type = 0;
$translationKey = "";
$plural = 0;
}
} while (!feof($file));
fclose($file);
$merge[""] = $header;
return $this->__domains[$domain][$this->__lang][$this->category] = array_merge($merge ,$translations);
}
|
Loads the text .po file for translation and sets the values for this translation in the var I18n::__domains
@param resource $file Text .po file to load
@param string $domain Domain to load file in
@return array Binded domain elements
@access private
|
__loadPo
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function __loadLocaleDefinition($file, $domain = null) {
$comment = '#';
$escape = '\\';
$currentToken = false;
$value = '';
while ($line = fgets($file)) {
$line = trim($line);
if (empty($line) || $line[0] === $comment) {
continue;
}
$parts = preg_split("/[[:space:]]+/",$line);
if ($parts[0] === 'comment_char') {
$comment = $parts[1];
continue;
}
if ($parts[0] === 'escape_char') {
$escape = $parts[1];
continue;
}
$count = count($parts);
if ($count == 2) {
$currentToken = $parts[0];
$value = $parts[1];
} elseif ($count == 1) {
$value .= $parts[0];
} else {
continue;
}
$len = strlen($value) - 1;
if ($value[$len] === $escape) {
$value = substr($value, 0, $len);
continue;
}
$mustEscape = array($escape . ',' , $escape . ';', $escape . '<', $escape . '>', $escape . $escape);
$replacements = array_map('crc32', $mustEscape);
$value = str_replace($mustEscape, $replacements, $value);
$value = explode(';', $value);
$this->__escape = $escape;
foreach ($value as $i => $val) {
$val = trim($val, '"');
$val = preg_replace_callback('/(?:<)?(.[^>]*)(?:>)?/', array(&$this, '__parseLiteralValue'), $val);
$val = str_replace($replacements, $mustEscape, $val);
$value[$i] = $val;
}
if (count($value) == 1) {
$this->__domains[$domain][$this->__lang][$this->category][$currentToken] = array_pop($value);
} else {
$this->__domains[$domain][$this->__lang][$this->category][$currentToken] = $value;
}
}
}
|
Parses a locale definition file following the POSIX standard
@param resource $file file handler
@param string $domain Domain where locale definitions will be stored
@return void
@access private
|
__loadLocaleDefinition
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function __parseLiteralValue($string) {
$string = $string[1];
if (substr($string, 0, 2) === $this->__escape . 'x') {
$delimiter = $this->__escape . 'x';
return join('', array_map('chr', array_map('hexdec',array_filter(explode($delimiter, $string)))));
}
if (substr($string, 0, 2) === $this->__escape . 'd') {
$delimiter = $this->__escape . 'd';
return join('', array_map('chr', array_filter(explode($delimiter, $string))));
}
if ($string[0] === $this->__escape && isset($string[1]) && is_numeric($string[1])) {
$delimiter = $this->__escape;
return join('', array_map('chr', array_filter(explode($delimiter, $string))));
}
if (substr($string, 0, 3) === 'U00') {
$delimiter = 'U00';
return join('', array_map('chr', array_map('hexdec', array_filter(explode($delimiter, $string)))));
}
if (preg_match('/U([0-9a-fA-F]{4})/', $string, $match)) {
return Multibyte::ascii(array(hexdec($match[1])));
}
return $string;
}
|
Auxiliary function to parse a symbol from a locale definition file
@param string $string Symbol to be parsed
@return string parsed symbol
@access private
|
__parseLiteralValue
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function __translateTime($format, $domain) {
if (!empty($this->__domains[$domain][$this->__lang]['LC_TIME'][$format])) {
if (($trans = $this->__domains[$domain][$this->__lang][$this->category][$format])) {
return $trans;
}
}
return $format;
}
|
Returns a Time format definition from corresponding domain
@param string $format Format to be translated
@param string $domain Domain where format is stored
@return mixed translated format string if only value or array of translated strings for corresponding format.
@access private
|
__translateTime
|
php
|
Datawalke/Coordino
|
cake/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/i18n.php
|
MIT
|
function &getInstance() {
static $instance = array();
if (!$instance) {
$instance[0] =& new Inflector();
}
return $instance[0];
}
|
Gets a reference to the Inflector object instance
@return object
@access public
|
getInstance
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function _cache($type, $key, $value = false) {
$key = '_' . $key;
$type = '_' . $type;
if ($value !== false) {
$this->{$type}[$key] = $value;
return $value;
}
if (!isset($this->{$type}[$key])) {
return false;
}
return $this->{$type}[$key];
}
|
Cache inflected values, and return if already available
@param string $type Inflection type
@param string $key Original value
@param string $value Inflected value
@return string Inflected value, from cache
@access protected
|
_cache
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function pluralize($word) {
$_this =& Inflector::getInstance();
if (isset($_this->_pluralized[$word])) {
return $_this->_pluralized[$word];
}
if (!isset($_this->_plural['merged']['irregular'])) {
$_this->_plural['merged']['irregular'] = $_this->_plural['irregular'];
}
if (!isset($_this->plural['merged']['uninflected'])) {
$_this->_plural['merged']['uninflected'] = array_merge($_this->_plural['uninflected'], $_this->_uninflected);
}
if (!isset($_this->_plural['cacheUninflected']) || !isset($_this->_plural['cacheIrregular'])) {
$_this->_plural['cacheUninflected'] = '(?:' . implode('|', $_this->_plural['merged']['uninflected']) . ')';
$_this->_plural['cacheIrregular'] = '(?:' . implode('|', array_keys($_this->_plural['merged']['irregular'])) . ')';
}
if (preg_match('/(.*)\\b(' . $_this->_plural['cacheIrregular'] . ')$/i', $word, $regs)) {
$_this->_pluralized[$word] = $regs[1] . substr($word, 0, 1) . substr($_this->_plural['merged']['irregular'][strtolower($regs[2])], 1);
return $_this->_pluralized[$word];
}
if (preg_match('/^(' . $_this->_plural['cacheUninflected'] . ')$/i', $word, $regs)) {
$_this->_pluralized[$word] = $word;
return $word;
}
foreach ($_this->_plural['rules'] as $rule => $replacement) {
if (preg_match($rule, $word)) {
$_this->_pluralized[$word] = preg_replace($rule, $replacement, $word);
return $_this->_pluralized[$word];
}
}
}
|
Return $word in plural form.
@param string $word Word in singular
@return string Word in plural
@access public
@static
@link http://book.cakephp.org/view/1479/Class-methods
|
pluralize
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function singularize($word) {
$_this =& Inflector::getInstance();
if (isset($_this->_singularized[$word])) {
return $_this->_singularized[$word];
}
if (!isset($_this->_singular['merged']['uninflected'])) {
$_this->_singular['merged']['uninflected'] = array_merge($_this->_singular['uninflected'], $_this->_uninflected);
}
if (!isset($_this->_singular['merged']['irregular'])) {
$_this->_singular['merged']['irregular'] = array_merge($_this->_singular['irregular'], array_flip($_this->_plural['irregular']));
}
if (!isset($_this->_singular['cacheUninflected']) || !isset($_this->_singular['cacheIrregular'])) {
$_this->_singular['cacheUninflected'] = '(?:' . join( '|', $_this->_singular['merged']['uninflected']) . ')';
$_this->_singular['cacheIrregular'] = '(?:' . join( '|', array_keys($_this->_singular['merged']['irregular'])) . ')';
}
if (preg_match('/(.*)\\b(' . $_this->_singular['cacheIrregular'] . ')$/i', $word, $regs)) {
$_this->_singularized[$word] = $regs[1] . substr($word, 0, 1) . substr($_this->_singular['merged']['irregular'][strtolower($regs[2])], 1);
return $_this->_singularized[$word];
}
if (preg_match('/^(' . $_this->_singular['cacheUninflected'] . ')$/i', $word, $regs)) {
$_this->_singularized[$word] = $word;
return $word;
}
foreach ($_this->_singular['rules'] as $rule => $replacement) {
if (preg_match($rule, $word)) {
$_this->_singularized[$word] = preg_replace($rule, $replacement, $word);
return $_this->_singularized[$word];
}
}
$_this->_singularized[$word] = $word;
return $word;
}
|
Return $word in singular form.
@param string $word Word in plural
@return string Word in singular
@access public
@static
@link http://book.cakephp.org/view/1479/Class-methods
|
singularize
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function camelize($lowerCaseAndUnderscoredWord) {
$_this =& Inflector::getInstance();
if (!($result = $_this->_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
$result = str_replace(' ', '', Inflector::humanize($lowerCaseAndUnderscoredWord));
$_this->_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
}
return $result;
}
|
Returns the given lower_case_and_underscored_word as a CamelCased word.
@param string $lower_case_and_underscored_word Word to camelize
@return string Camelized word. LikeThis.
@access public
@static
@link http://book.cakephp.org/view/1479/Class-methods
|
camelize
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function underscore($camelCasedWord) {
$_this =& Inflector::getInstance();
if (!($result = $_this->_cache(__FUNCTION__, $camelCasedWord))) {
$result = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
$_this->_cache(__FUNCTION__, $camelCasedWord, $result);
}
return $result;
}
|
Returns the given camelCasedWord as an underscored_word.
@param string $camelCasedWord Camel-cased word to be "underscorized"
@return string Underscore-syntaxed version of the $camelCasedWord
@access public
@static
@link http://book.cakephp.org/view/1479/Class-methods
|
underscore
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function humanize($lowerCaseAndUnderscoredWord) {
$_this =& Inflector::getInstance();
if (!($result = $_this->_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord))) {
$result = ucwords(str_replace('_', ' ', $lowerCaseAndUnderscoredWord));
$_this->_cache(__FUNCTION__, $lowerCaseAndUnderscoredWord, $result);
}
return $result;
}
|
Returns the given underscored_word_group as a Human Readable Word Group.
(Underscores are replaced by spaces and capitalized following words.)
@param string $lower_case_and_underscored_word String to be made more readable
@return string Human-readable string
@access public
@static
@link http://book.cakephp.org/view/1479/Class-methods
|
humanize
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function tableize($className) {
$_this =& Inflector::getInstance();
if (!($result = $_this->_cache(__FUNCTION__, $className))) {
$result = Inflector::pluralize(Inflector::underscore($className));
$_this->_cache(__FUNCTION__, $className, $result);
}
return $result;
}
|
Returns corresponding table name for given model $className. ("people" for the model class "Person").
@param string $className Name of class to get database table name for
@return string Name of the database table for given class
@access public
@static
@link http://book.cakephp.org/view/1479/Class-methods
|
tableize
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function classify($tableName) {
$_this =& Inflector::getInstance();
if (!($result = $_this->_cache(__FUNCTION__, $tableName))) {
$result = Inflector::camelize(Inflector::singularize($tableName));
$_this->_cache(__FUNCTION__, $tableName, $result);
}
return $result;
}
|
Returns Cake model class name ("Person" for the database table "people".) for given database table.
@param string $tableName Name of database table to get class name for
@return string Class name
@access public
@static
@link http://book.cakephp.org/view/1479/Class-methods
|
classify
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function variable($string) {
$_this =& Inflector::getInstance();
if (!($result = $_this->_cache(__FUNCTION__, $string))) {
$string2 = Inflector::camelize(Inflector::underscore($string));
$replace = strtolower(substr($string2, 0, 1));
$result = preg_replace('/\\w/', $replace, $string2, 1);
$_this->_cache(__FUNCTION__, $string, $result);
}
return $result;
}
|
Returns camelBacked version of an underscored string.
@param string $string
@return string in variable form
@access public
@static
@link http://book.cakephp.org/view/1479/Class-methods
|
variable
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function slug($string, $replacement = '_', $map = array()) {
$_this =& Inflector::getInstance();
if (is_array($replacement)) {
$map = $replacement;
$replacement = '_';
}
$quotedReplacement = preg_quote($replacement, '/');
$merge = array(
'/[^\s\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]/mu' => ' ',
'/\\s+/' => $replacement,
sprintf('/^[%s]+|[%s]+$/', $quotedReplacement, $quotedReplacement) => '',
);
$map = $map + $_this->_transliteration + $merge;
return preg_replace(array_keys($map), array_values($map), $string);
}
|
Returns a string with all spaces converted to underscores (by default), accented
characters converted to non-accented characters, and non word characters removed.
@param string $string the string you want to slug
@param string $replacement will replace keys in map
@param array $map extra elements to map to the replacement
@deprecated $map param will be removed in future versions. Use Inflector::rules() instead
@return string
@access public
@static
@link http://book.cakephp.org/view/1479/Class-methods
|
slug
|
php
|
Datawalke/Coordino
|
cake/libs/inflector.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/inflector.php
|
MIT
|
function get($language = null) {
if ($language !== null) {
return $this->__setLanguage($language);
} elseif ($this->__autoLanguage() === false) {
return $this->__setLanguage();
}
}
|
Gets the settings for $language.
If $language is null it attempt to get settings from L10n::__autoLanguage(); if this fails
the method will get the settings from L10n::__setLanguage();
@param string $language Language (if null will use DEFAULT_LANGUAGE if defined)
@access public
|
get
|
php
|
Datawalke/Coordino
|
cake/libs/l10n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/libs/l10n.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.