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 pluginSplit($name, $dotAppend = false, $plugin = null) {
if (strpos($name, '.') !== false) {
$parts = explode('.', $name, 2);
if ($dotAppend) {
$parts[0] .= '.';
}
return $parts;
}
return array($plugin, $name);
}
|
Splits a dot syntax plugin name into its plugin and classname.
If $name does not have a dot, then index 0 will be null.
Commonly used like `list($plugin, $name) = pluginSplit($name);`
@param string $name The name you want to plugin split.
@param boolean $dotAppend Set to true if you want the plugin to have a '.' appended to it.
@param string $plugin Optional default plugin to use if no plugin is found. Defaults to null.
@return array Array with 2 indexes. 0 => plugin name, 1 => classname
|
pluginSplit
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function a() {
$args = func_get_args();
return $args;
}
|
Returns an array of all the given parameters.
Example:
`a('a', 'b')`
Would return:
`array('a', 'b')`
@return array Array of given parameters
@link http://book.cakephp.org/view/1122/a
@deprecated Will be removed in 2.0
|
a
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function aa() {
$args = func_get_args();
$argc = count($args);
for ($i = 0; $i < $argc; $i++) {
if ($i + 1 < $argc) {
$a[$args[$i]] = $args[$i + 1];
} else {
$a[$args[$i]] = null;
}
$i++;
}
return $a;
}
|
Constructs associative array from pairs of arguments.
Example:
`aa('a','b')`
Would return:
`array('a'=>'b')`
@return array Associative array
@link http://book.cakephp.org/view/1123/aa
@deprecated Will be removed in 2.0
|
aa
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function e($text) {
echo $text;
}
|
Convenience method for echo().
@param string $text String to echo
@link http://book.cakephp.org/view/1129/e
@deprecated Will be removed in 2.0
|
e
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function low($str) {
return strtolower($str);
}
|
Convenience method for strtolower().
@param string $str String to lowercase
@return string Lowercased string
@link http://book.cakephp.org/view/1134/low
@deprecated Will be removed in 2.0
|
low
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function up($str) {
return strtoupper($str);
}
|
Convenience method for strtoupper().
@param string $str String to uppercase
@return string Uppercased string
@link http://book.cakephp.org/view/1139/up
@deprecated Will be removed in 2.0
|
up
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function r($search, $replace, $subject) {
return str_replace($search, $replace, $subject);
}
|
Convenience method for str_replace().
@param string $search String to be replaced
@param string $replace String to insert
@param string $subject String to search
@return string Replaced string
@link http://book.cakephp.org/view/1137/r
@deprecated Will be removed in 2.0
|
r
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function pr($var) {
if (Configure::read() > 0) {
echo '<pre>';
print_r($var);
echo '</pre>';
}
}
|
Print_r convenience function, which prints out <PRE> tags around
the output of given array. Similar to debug().
@see debug()
@param array $var Variable to print out
@link http://book.cakephp.org/view/1136/pr
|
pr
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function params($p) {
if (!is_array($p) || count($p) == 0) {
return null;
}
if (is_array($p[0]) && count($p) == 1) {
return $p[0];
}
return $p;
}
|
Display parameters.
@param mixed $p Parameter as string or array
@return string
@deprecated Will be removed in 2.0
|
params
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function am() {
$r = array();
$args = func_get_args();
foreach ($args as $a) {
if (!is_array($a)) {
$a = array($a);
}
$r = array_merge($r, $a);
}
return $r;
}
|
Merge a group of arrays
@param array First array
@param array Second array
@param array Third array
@param array Etc...
@return array All array parameters merged into one
@link http://book.cakephp.org/view/1124/am
|
am
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function env($key) {
if ($key == 'HTTPS') {
if (isset($_SERVER['HTTPS'])) {
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
}
return (strpos(env('SCRIPT_URI'), 'https://') === 0);
}
if ($key == 'SCRIPT_NAME') {
if (env('CGI_MODE') && isset($_ENV['SCRIPT_URL'])) {
$key = 'SCRIPT_URL';
}
}
$val = null;
if (isset($_SERVER[$key])) {
$val = $_SERVER[$key];
} elseif (isset($_ENV[$key])) {
$val = $_ENV[$key];
} elseif (getenv($key) !== false) {
$val = getenv($key);
}
if ($key === 'REMOTE_ADDR' && $val === env('SERVER_ADDR')) {
$addr = env('HTTP_PC_REMOTE_ADDR');
if ($addr !== null) {
$val = $addr;
}
}
if ($val !== null) {
return $val;
}
switch ($key) {
case 'SCRIPT_FILENAME':
if (defined('SERVER_IIS') && SERVER_IIS === true) {
return str_replace('\\\\', '\\', env('PATH_TRANSLATED'));
}
break;
case 'DOCUMENT_ROOT':
$name = env('SCRIPT_NAME');
$filename = env('SCRIPT_FILENAME');
$offset = 0;
if (!strpos($name, '.php')) {
$offset = 4;
}
return substr($filename, 0, strlen($filename) - (strlen($name) + $offset));
break;
case 'PHP_SELF':
return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
break;
case 'CGI_MODE':
return (PHP_SAPI === 'cgi');
break;
case 'HTTP_BASE':
$host = env('HTTP_HOST');
$parts = explode('.', $host);
$count = count($parts);
if ($count === 1) {
return '.' . $host;
} elseif ($count === 2) {
return '.' . $host;
} elseif ($count === 3) {
$gTLD = array('aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi', 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'xxx');
if (in_array($parts[1], $gTLD)) {
return '.' . $host;
}
}
array_shift($parts);
return '.' . implode('.', $parts);
break;
}
return null;
}
|
Gets an environment variable from available sources, and provides emulation
for unsupported or inconsistent environment variables (i.e. DOCUMENT_ROOT on
IIS, or SCRIPT_NAME in CGI mode). Also exposes some additional custom
environment information.
@param string $key Environment variable name.
@return string Environment variable setting.
@link http://book.cakephp.org/view/1130/env
|
env
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function file_put_contents($fileName, $data) {
if (is_array($data)) {
$data = implode('', $data);
}
$res = @fopen($fileName, 'w+b');
if ($res) {
$write = @fwrite($res, $data);
if ($write === false) {
return false;
} else {
@fclose($res);
return $write;
}
}
return false;
}
|
Writes data into file.
If file exists, it will be overwritten. If data is an array, it will be implode()ed with an empty string.
@param string $fileName File name.
@param mixed $data String or array.
@return boolean Success
@deprecated Will be removed in 2.0
|
file_put_contents
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
if (Configure::read('Cache.disable')) {
return null;
}
$now = time();
if (!is_numeric($expires)) {
$expires = strtotime($expires, $now);
}
switch (strtolower($target)) {
case 'cache':
$filename = CACHE . $path;
break;
case 'public':
$filename = WWW_ROOT . $path;
break;
case 'tmp':
$filename = TMP . $path;
break;
}
$timediff = $expires - $now;
$filetime = false;
if (file_exists($filename)) {
$filetime = @filemtime($filename);
}
if ($data === null) {
if (file_exists($filename) && $filetime !== false) {
if ($filetime + $timediff < $now) {
@unlink($filename);
} else {
$data = @file_get_contents($filename);
}
}
} elseif (is_writable(dirname($filename))) {
@file_put_contents($filename, $data);
}
return $data;
}
|
Reads/writes temporary data to cache files or session.
@param string $path File path within /tmp to save the file.
@param mixed $data The data to save to the temporary file.
@param mixed $expires A valid strtotime string when the data expires.
@param string $target The target of the cached data; either 'cache' or 'public'.
@return mixed The contents of the temporary file.
@deprecated Please use Cache::write() instead
|
cache
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function clearCache($params = null, $type = 'views', $ext = '.php') {
if (is_string($params) || $params === null) {
$params = preg_replace('/\/\//', '/', $params);
$cache = CACHE . $type . DS . $params;
if (is_file($cache . $ext)) {
@unlink($cache . $ext);
return true;
} elseif (is_dir($cache)) {
$files = glob($cache . '*');
if ($files === false) {
return false;
}
foreach ($files as $file) {
if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
@unlink($file);
}
}
return true;
} else {
$cache = array(
CACHE . $type . DS . '*' . $params . $ext,
CACHE . $type . DS . '*' . $params . '_*' . $ext
);
$files = array();
while ($search = array_shift($cache)) {
$results = glob($search);
if ($results !== false) {
$files = array_merge($files, $results);
}
}
if (empty($files)) {
return false;
}
foreach ($files as $file) {
if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) {
@unlink($file);
}
}
return true;
}
} elseif (is_array($params)) {
foreach ($params as $file) {
clearCache($file, $type, $ext);
}
return true;
}
return false;
}
|
Used to delete files in the cache directories, or clear contents of cache directories
@param mixed $params As String name to be searched for deletion, if name is a directory all files in
directory will be deleted. If array, names to be searched for deletion. If clearCache() without params,
all files in app/tmp/cache/views will be deleted
@param string $type Directory in tmp/cache defaults to view directory
@param string $ext The file extension you are deleting
@return true if files found and deleted false otherwise
|
clearCache
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function stripslashes_deep($values) {
if (is_array($values)) {
foreach ($values as $key => $value) {
$values[$key] = stripslashes_deep($value);
}
} else {
$values = stripslashes($values);
}
return $values;
}
|
Recursively strips slashes from all values in an array
@param array $values Array of values to strip slashes
@return mixed What is returned from calling stripslashes
@link http://book.cakephp.org/view/1138/stripslashes_deep
|
stripslashes_deep
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function __n($singular, $plural, $count, $return = false) {
if (!$singular) {
return;
}
if (!class_exists('I18n')) {
App::import('Core', 'i18n');
}
if ($return === false) {
echo I18n::translate($singular, $plural, null, 6, $count);
} else {
return I18n::translate($singular, $plural, null, 6, $count);
}
}
|
Returns correct plural form of message identified by $singular and $plural for count $count.
Some languages have more than one form for plural messages dependent on the count.
@param string $singular Singular text to translate
@param string $plural Plural text
@param integer $count Count
@param boolean $return true to return, false to echo
@return mixed plural form of translated string if $return is false string will be echoed
|
__n
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function __d($domain, $msg, $return = false) {
if (!$msg) {
return;
}
if (!class_exists('I18n')) {
App::import('Core', 'i18n');
}
if ($return === false) {
echo I18n::translate($msg, null, $domain);
} else {
return I18n::translate($msg, null, $domain);
}
}
|
Allows you to override the current domain for a single message lookup.
@param string $domain Domain
@param string $msg String to translate
@param string $return true to return, false to echo
@return translated string if $return is false string will be echoed
|
__d
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function __dn($domain, $singular, $plural, $count, $return = false) {
if (!$singular) {
return;
}
if (!class_exists('I18n')) {
App::import('Core', 'i18n');
}
if ($return === false) {
echo I18n::translate($singular, $plural, $domain, 6, $count);
} else {
return I18n::translate($singular, $plural, $domain, 6, $count);
}
}
|
Allows you to override the current domain for a single plural message lookup.
Returns correct plural form of message identified by $singular and $plural for count $count
from domain $domain.
@param string $domain Domain
@param string $singular Singular string to translate
@param string $plural Plural
@param integer $count Count
@param boolean $return true to return, false to echo
@return plural form of translated string if $return is false string will be echoed
|
__dn
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function __dc($domain, $msg, $category, $return = false) {
if (!$msg) {
return;
}
if (!class_exists('I18n')) {
App::import('Core', 'i18n');
}
if ($return === false) {
echo I18n::translate($msg, null, $domain, $category);
} else {
return I18n::translate($msg, null, $domain, $category);
}
}
|
Allows you to override the current domain for a single message lookup.
It also allows you to specify a category.
The category argument allows a specific category of the locale settings to be used for fetching a message.
Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
Note that the category must be specified with a numeric value, instead of the constant name. The values are:
- LC_ALL 0
- LC_COLLATE 1
- LC_CTYPE 2
- LC_MONETARY 3
- LC_NUMERIC 4
- LC_TIME 5
- LC_MESSAGES 6
@param string $domain Domain
@param string $msg Message to translate
@param integer $category Category
@param boolean $return true to return, false to echo
@return translated string if $return is false string will be echoed
|
__dc
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function __dcn($domain, $singular, $plural, $count, $category, $return = false) {
if (!$singular) {
return;
}
if (!class_exists('I18n')) {
App::import('Core', 'i18n');
}
if ($return === false) {
echo I18n::translate($singular, $plural, $domain, $category, $count);
} else {
return I18n::translate($singular, $plural, $domain, $category, $count);
}
}
|
Allows you to override the current domain for a single plural message lookup.
It also allows you to specify a category.
Returns correct plural form of message identified by $singular and $plural for count $count
from domain $domain.
The category argument allows a specific category of the locale settings to be used for fetching a message.
Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
Note that the category must be specified with a numeric value, instead of the constant name. The values are:
- LC_ALL 0
- LC_COLLATE 1
- LC_CTYPE 2
- LC_MONETARY 3
- LC_NUMERIC 4
- LC_TIME 5
- LC_MESSAGES 6
@param string $domain Domain
@param string $singular Singular string to translate
@param string $plural Plural
@param integer $count Count
@param integer $category Category
@param boolean $return true to return, false to echo
@return plural form of translated string if $return is false string will be echoed
|
__dcn
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function __c($msg, $category, $return = false) {
if (!$msg) {
return;
}
if (!class_exists('I18n')) {
App::import('Core', 'i18n');
}
if ($return === false) {
echo I18n::translate($msg, null, null, $category);
} else {
return I18n::translate($msg, null, null, $category);
}
}
|
The category argument allows a specific category of the locale settings to be used for fetching a message.
Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
Note that the category must be specified with a numeric value, instead of the constant name. The values are:
- LC_ALL 0
- LC_COLLATE 1
- LC_CTYPE 2
- LC_MONETARY 3
- LC_NUMERIC 4
- LC_TIME 5
- LC_MESSAGES 6
@param string $msg String to translate
@param integer $category Category
@param string $return true to return, false to echo
@return translated string if $return is false string will be echoed
|
__c
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function LogError($message) {
if (!class_exists('CakeLog')) {
App::import('Core', 'CakeLog');
}
$bad = array("\n", "\r", "\t");
$good = ' ';
CakeLog::write('error', str_replace($bad, $good, $message));
}
|
Shortcut to Log::write.
@param string $message Message to write to log
|
LogError
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function fileExistsInPath($file) {
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach ($paths as $path) {
$fullPath = $path . DS . $file;
if (file_exists($fullPath)) {
return $fullPath;
} elseif (file_exists($file)) {
return $file;
}
}
return false;
}
|
Searches include path for files.
@param string $file File to look for
@return Full path to file if exists, otherwise false
@link http://book.cakephp.org/view/1131/fileExistsInPath
|
fileExistsInPath
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function convertSlash($string) {
$string = trim($string, '/');
$string = preg_replace('/\/\//', '/', $string);
$string = str_replace('/', '_', $string);
return $string;
}
|
Convert forward slashes to underscores and removes first and last underscores in a string
@param string String to convert
@return string with underscore remove from start and end of string
@link http://book.cakephp.org/view/1126/convertSlash
|
convertSlash
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function ife($condition, $val1 = null, $val2 = null) {
if (!empty($condition)) {
return $val1;
}
return $val2;
}
|
Wraps ternary operations. If $condition is a non-empty value, $val1 is returned, otherwise $val2.
Don't use for isset() conditions, or wrap your variable with @ operator:
Example:
`ife(isset($variable), @$variable, 'default');`
@param mixed $condition Conditional expression
@param mixed $val1 Value to return in case condition matches
@param mixed $val2 Value to return if condition doesn't match
@return mixed $val1 or $val2, depending on whether $condition evaluates to a non-empty expression.
@link http://book.cakephp.org/view/1133/ife
@deprecated Will be removed in 2.0
|
ife
|
php
|
Datawalke/Coordino
|
cake/basics.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/basics.php
|
MIT
|
function dispatch($url = null, $additionalParams = array()) {
if ($this->base === false) {
$this->base = $this->baseUrl();
}
if (is_array($url)) {
$url = $this->__extractParams($url, $additionalParams);
} else {
if ($url) {
$_GET['url'] = $url;
}
$url = $this->getUrl();
$this->params = array_merge($this->parseParams($url), $additionalParams);
}
$this->here = $this->base . '/' . $url;
if ($this->asset($url) || $this->cached($url)) {
return;
}
$controller =& $this->__getController();
if (!is_object($controller)) {
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot)));
return $this->cakeError('missingController', array(array(
'className' => Inflector::camelize($this->params['controller']) . 'Controller',
'webroot' => $this->webroot,
'url' => $url,
'base' => $this->base
)));
}
$privateAction = $this->params['action'][0] === '_';
$prefixes = Router::prefixes();
if (!empty($prefixes)) {
if (isset($this->params['prefix'])) {
$this->params['action'] = $this->params['prefix'] . '_' . $this->params['action'];
} elseif (strpos($this->params['action'], '_') > 0) {
list($prefix, $action) = explode('_', $this->params['action']);
$privateAction = in_array($prefix, $prefixes);
}
}
Router::setRequestInfo(array(
$this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot)
));
if ($privateAction) {
return $this->cakeError('privateAction', array(array(
'className' => Inflector::camelize($this->params['controller'] . "Controller"),
'action' => $this->params['action'],
'webroot' => $this->webroot,
'url' => $url,
'base' => $this->base
)));
}
$controller->base = $this->base;
$controller->here = $this->here;
$controller->webroot = $this->webroot;
$controller->plugin = isset($this->params['plugin']) ? $this->params['plugin'] : null;
$controller->params =& $this->params;
$controller->action =& $this->params['action'];
$controller->passedArgs = array_merge($this->params['pass'], $this->params['named']);
if (!empty($this->params['data'])) {
$controller->data =& $this->params['data'];
} else {
$controller->data = null;
}
if (isset($this->params['return']) && $this->params['return'] == 1) {
$controller->autoRender = false;
}
if (!empty($this->params['bare'])) {
$controller->autoLayout = false;
}
return $this->_invoke($controller, $this->params);
}
|
Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the
results (if autoRender is set).
If no controller of given name can be found, invoke() shows error messages in
the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called
Actions).
@param string $url URL information to work on
@param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
@return boolean Success
@access public
|
dispatch
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function _invoke(&$controller, $params) {
$controller->constructClasses();
$controller->startupProcess();
$methods = array_flip($controller->methods);
if (!isset($methods[strtolower($params['action'])])) {
if ($controller->scaffold !== false) {
App::import('Controller', 'Scaffold', false);
return new Scaffold($controller, $params);
}
return $this->cakeError('missingAction', array(array(
'className' => Inflector::camelize($params['controller']."Controller"),
'action' => $params['action'],
'webroot' => $this->webroot,
'url' => $this->here,
'base' => $this->base
)));
}
$output = call_user_func_array(array(&$controller, $params['action']), $params['pass']);
if ($controller->autoRender) {
$controller->output = $controller->render();
} elseif (empty($controller->output)) {
$controller->output = $output;
}
$controller->shutdownProcess();
if (isset($params['return'])) {
return $controller->output;
}
echo($controller->output);
}
|
Initializes the components and models a controller will be using.
Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
Otherwise the return value of the controller action are returned.
@param object $controller Controller to invoke
@param array $params Parameters with at least the 'action' to invoke
@param boolean $missingAction Set to true if missing action should be rendered, false otherwise
@return string Output as sent by controller
@access protected
|
_invoke
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function __extractParams($url, $additionalParams = array()) {
$defaults = array('pass' => array(), 'named' => array(), 'form' => array());
$params = array_merge($defaults, $url, $additionalParams);
$this->params = $params;
$params += array('base' => false, 'url' => array());
return ltrim(Router::reverse($params), '/');
}
|
Sets the params when $url is passed as an array to Object::requestAction();
Merges the $url and $additionalParams and creates a string url.
@param array $url Array or request parameters
@param array $additionalParams Array of additional parameters.
@return string $url The generated url string.
@access private
|
__extractParams
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function parseParams($fromUrl) {
$params = array();
if (isset($_POST)) {
$params['form'] = $_POST;
if (ini_get('magic_quotes_gpc') === '1') {
$params['form'] = stripslashes_deep($params['form']);
}
if (env('HTTP_X_HTTP_METHOD_OVERRIDE')) {
$params['form']['_method'] = env('HTTP_X_HTTP_METHOD_OVERRIDE');
}
if (isset($params['form']['_method'])) {
if (!empty($_SERVER)) {
$_SERVER['REQUEST_METHOD'] = $params['form']['_method'];
} else {
$_ENV['REQUEST_METHOD'] = $params['form']['_method'];
}
unset($params['form']['_method']);
}
}
$namedExpressions = Router::getNamedExpressions();
extract($namedExpressions);
include CONFIGS . 'routes.php';
$params = array_merge(array('controller' => '', 'action' => ''), Router::parse($fromUrl), $params);
if (empty($params['action'])) {
$params['action'] = 'index';
}
if (isset($params['form']['data'])) {
$params['data'] = $params['form']['data'];
unset($params['form']['data']);
}
if (isset($_GET)) {
if (ini_get('magic_quotes_gpc') === '1') {
$url = stripslashes_deep($_GET);
} else {
$url = $_GET;
}
if (isset($params['url'])) {
$params['url'] = array_merge($params['url'], $url);
} else {
$params['url'] = $url;
}
}
foreach ($_FILES as $name => $data) {
if ($name != 'data') {
$params['form'][$name] = $data;
}
}
if (isset($_FILES['data'])) {
foreach ($_FILES['data'] as $key => $data) {
foreach ($data as $model => $fields) {
if (is_array($fields)) {
foreach ($fields as $field => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$params['data'][$model][$field][$k][$key] = $v;
}
} else {
$params['data'][$model][$field][$key] = $value;
}
}
} else {
$params['data'][$model][$key] = $fields;
}
}
}
}
return $params;
}
|
Returns array of GET and POST parameters. GET parameters are taken from given URL.
@param string $fromUrl URL to mine for parameter information.
@return array Parameters found in POST and GET.
@access public
|
parseParams
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function baseUrl() {
$dir = $webroot = null;
$config = Configure::read('App');
extract($config);
if (!$base) {
$base = $this->base;
}
if ($base !== false) {
$this->webroot = $base . '/';
return $this->base = $base;
}
if (!$baseUrl) {
$replace = array('<', '>', '*', '\'', '"');
$base = str_replace($replace, '', dirname(env('PHP_SELF')));
if ($webroot === 'webroot' && $webroot === basename($base)) {
$base = dirname($base);
}
if ($dir === 'app' && $dir === basename($base)) {
$base = dirname($base);
}
if ($base === DS || $base === '.') {
$base = '';
}
$this->webroot = $base .'/';
return $base;
}
$file = '/' . basename($baseUrl);
$base = dirname($baseUrl);
if ($base === DS || $base === '.') {
$base = '';
}
$this->webroot = $base . '/';
$docRoot = realpath(env('DOCUMENT_ROOT'));
$docRootContainsWebroot = strpos($docRoot, $dir . '/' . $webroot);
if (!empty($base) || !$docRootContainsWebroot) {
if (strpos($this->webroot, '/' . $dir . '/') === false) {
$this->webroot .= $dir . '/' ;
}
if (strpos($this->webroot, '/' . $webroot . '/') === false) {
$this->webroot .= $webroot . '/';
}
}
return $base . $file;
}
|
Returns a base URL and sets the proper webroot
@return string Base URL
@access public
|
baseUrl
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function &__getController() {
$controller = false;
$ctrlClass = $this->__loadController($this->params);
if (!$ctrlClass) {
return $controller;
}
$ctrlClass .= 'Controller';
if (class_exists($ctrlClass)) {
$controller =& new $ctrlClass();
}
return $controller;
}
|
Get controller to use, either plugin controller or application controller
@param array $params Array of parameters
@return mixed name of controller if not loaded, or object if loaded
@access private
|
__getController
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function __loadController($params) {
$pluginName = $pluginPath = $controller = null;
if (!empty($params['plugin'])) {
$pluginName = $controller = Inflector::camelize($params['plugin']);
$pluginPath = $pluginName . '.';
}
if (!empty($params['controller'])) {
$controller = Inflector::camelize($params['controller']);
}
if ($pluginPath . $controller) {
if (App::import('Controller', $pluginPath . $controller)) {
return $controller;
}
}
return false;
}
|
Load controller and return controller classname
@param array $params Array of parameters
@return string|bool Name of controller class name
@access private
|
__loadController
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function uri() {
foreach (array('HTTP_X_REWRITE_URL', 'REQUEST_URI', 'argv') as $var) {
if ($uri = env($var)) {
if ($var == 'argv') {
$uri = $uri[0];
}
break;
}
}
$base = preg_replace('/^\//', '', '' . Configure::read('App.baseUrl'));
if ($base) {
$uri = preg_replace('/^(?:\/)?(?:' . preg_quote($base, '/') . ')?(?:url=)?/', '', $uri);
}
if (PHP_SAPI == 'isapi') {
$uri = preg_replace('/^(?:\/)?(?:\/)?(?:\?)?(?:url=)?/', '', $uri);
}
if (!empty($uri)) {
if (key($_GET) && strpos(key($_GET), '?') !== false) {
unset($_GET[key($_GET)]);
}
$uri = explode('?', $uri, 2);
if (isset($uri[1])) {
parse_str($uri[1], $_GET);
}
$uri = $uri[0];
} else {
$uri = env('QUERY_STRING');
}
if (is_string($uri) && strpos($uri, 'index.php') !== false) {
list(, $uri) = explode('index.php', $uri, 2);
}
if (empty($uri) || $uri == '/' || $uri == '//') {
return '';
}
return str_replace('//', '/', '/' . $uri);
}
|
Returns the REQUEST_URI from the server environment, or, failing that,
constructs a new one, using the PHP_SELF constant and other variables.
@return string URI
@access public
|
uri
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function getUrl($uri = null, $base = null) {
if (empty($_GET['url'])) {
if ($uri == null) {
$uri = $this->uri();
}
if ($base == null) {
$base = $this->base;
}
$url = null;
$tmpUri = preg_replace('/^(?:\?)?(?:\/)?/', '', $uri);
$baseDir = preg_replace('/^\//', '', dirname($base)) . '/';
if ($tmpUri === '/' || $tmpUri == $baseDir || $tmpUri == $base) {
$url = $_GET['url'] = '/';
} else {
if ($base && strpos($uri, $base) === 0) {
$elements = explode($base, $uri, 2);
} elseif (preg_match('/^[\/\?\/|\/\?|\?\/]/', $uri)) {
$elements = array(1 => preg_replace('/^[\/\?\/|\/\?|\?\/]/', '', $uri));
} else {
$elements = array();
}
if (!empty($elements[1])) {
$_GET['url'] = $elements[1];
$url = $elements[1];
} else {
$url = $_GET['url'] = '/';
}
if (strpos($url, '/') === 0 && $url != '/') {
$url = $_GET['url'] = substr($url, 1);
}
}
} else {
$url = $_GET['url'];
}
if ($url{0} == '/') {
$url = substr($url, 1);
}
return $url;
}
|
Returns and sets the $_GET[url] derived from the REQUEST_URI
@param string $uri Request URI
@param string $base Base path
@return string URL
@access public
|
getUrl
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function cached($url) {
if (Configure::read('Cache.check') === true) {
$path = $this->here;
if ($this->here == '/') {
$path = 'home';
}
$path = strtolower(Inflector::slug($path));
$filename = CACHE . 'views' . DS . $path . '.php';
if (!file_exists($filename)) {
$filename = CACHE . 'views' . DS . $path . '_index.php';
}
if (file_exists($filename)) {
if (!class_exists('View')) {
App::import('View', 'View', false);
}
$controller = null;
$view =& new View($controller);
$return = $view->renderCache($filename, getMicrotime());
if (!$return) {
ClassRegistry::removeObject('view');
}
return $return;
}
}
return false;
}
|
Outputs cached dispatch view cache
@param string $url Requested URL
@access public
|
cached
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function asset($url) {
if (strpos($url, '..') !== false || strpos($url, '.') === false) {
return false;
}
$filters = Configure::read('Asset.filter');
$isCss = (
strpos($url, 'ccss/') === 0 ||
preg_match('#^(theme/([^/]+)/ccss/)|(([^/]+)(?<!css)/ccss)/#i', $url)
);
$isJs = (
strpos($url, 'cjs/') === 0 ||
preg_match('#^/((theme/[^/]+)/cjs/)|(([^/]+)(?<!js)/cjs)/#i', $url)
);
if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) {
header('HTTP/1.1 404 Not Found');
return $this->_stop();
} elseif ($isCss) {
include WWW_ROOT . DS . $filters['css'];
$this->_stop();
} elseif ($isJs) {
include WWW_ROOT . DS . $filters['js'];
$this->_stop();
}
$controller = null;
$ext = array_pop(explode('.', $url));
$parts = explode('/', $url);
$assetFile = null;
if ($parts[0] === 'theme') {
$themeName = $parts[1];
unset($parts[0], $parts[1]);
$fileFragment = implode(DS, $parts);
$path = App::themePath($themeName) . 'webroot' . DS;
if (file_exists($path . $fileFragment)) {
$assetFile = $path . $fileFragment;
}
} else {
$plugin = $parts[0];
unset($parts[0]);
$fileFragment = implode(DS, $parts);
$pluginWebroot = App::pluginPath($plugin) . 'webroot' . DS;
if (file_exists($pluginWebroot . $fileFragment)) {
$assetFile = $pluginWebroot . $fileFragment;
}
}
if ($assetFile !== null) {
$this->_deliverAsset($assetFile, $ext);
return true;
}
return false;
}
|
Checks if a requested asset exists and sends it to the browser
@param $url string $url Requested URL
@return boolean True on success if the asset file was found and sent
@access public
|
asset
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function _deliverAsset($assetFile, $ext) {
$ob = @ini_get("zlib.output_compression") !== '1' && extension_loaded("zlib") && (strpos(env('HTTP_ACCEPT_ENCODING'), 'gzip') !== false);
$compressionEnabled = $ob && Configure::read('Asset.compress');
if ($compressionEnabled) {
ob_start();
ob_start('ob_gzhandler');
}
App::import('View', 'Media');
$controller = null;
$Media = new MediaView($controller);
if (isset($Media->mimeType[$ext])) {
$contentType = $Media->mimeType[$ext];
} else {
$contentType = 'application/octet-stream';
$agent = env('HTTP_USER_AGENT');
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
$contentType = 'application/octetstream';
}
}
header("Date: " . date("D, j M Y G:i:s ", filemtime($assetFile)) . 'GMT');
header('Content-type: ' . $contentType);
header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT");
header("Cache-Control: cache");
header("Pragma: cache");
if ($ext === 'css' || $ext === 'js') {
include($assetFile);
} else {
if ($compressionEnabled) {
ob_clean();
}
readfile($assetFile);
}
if ($compressionEnabled) {
ob_end_flush();
}
}
|
Sends an asset file to the client
@param string $assetFile Path to the asset file in the file system
@param string $ext The extension of the file to determine its mime type
@return void
@access protected
|
_deliverAsset
|
php
|
Datawalke/Coordino
|
cake/dispatcher.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/dispatcher.php
|
MIT
|
function ShellDispatcher($args = array()) {
set_time_limit(0);
$this->__initConstants();
$this->parseParams($args);
$this->_initEnvironment();
$this->__buildPaths();
$this->_stop($this->dispatch() === false ? 1 : 0);
}
|
Constructor
The execution of the script is stopped after dispatching the request with
a status code of either 0 or 1 according to the result of the dispatch.
@param array $args the argv
@return void
@access public
|
ShellDispatcher
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function _initEnvironment() {
$this->stdin = fopen('php://stdin', 'r');
$this->stdout = fopen('php://stdout', 'w');
$this->stderr = fopen('php://stderr', 'w');
if (!$this->__bootstrap()) {
$this->stderr("\nCakePHP Console: ");
$this->stderr("\nUnable to load Cake core:");
$this->stderr("\tMake sure " . DS . 'cake' . DS . 'libs exists in ' . CAKE_CORE_INCLUDE_PATH);
$this->_stop();
}
if (!isset($this->args[0]) || !isset($this->params['working'])) {
$this->stderr("\nCakePHP Console: ");
$this->stderr('This file has been loaded incorrectly and cannot continue.');
$this->stderr('Please make sure that ' . DIRECTORY_SEPARATOR . 'cake' . DIRECTORY_SEPARATOR . 'console is in your system path,');
$this->stderr('and check the manual for the correct usage of this command.');
$this->stderr('(http://manual.cakephp.org/)');
$this->_stop();
}
if (basename(__FILE__) != basename($this->args[0])) {
$this->stderr("\nCakePHP Console: ");
$this->stderr('Warning: the dispatcher may have been loaded incorrectly, which could lead to unexpected results...');
if ($this->getInput('Continue anyway?', array('y', 'n'), 'y') == 'n') {
$this->_stop();
}
}
$this->shiftArgs();
}
|
Defines current working environment.
@access protected
|
_initEnvironment
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function __buildPaths() {
$paths = array();
if (!class_exists('Folder')) {
require LIBS . 'folder.php';
}
$plugins = App::objects('plugin', null, false);
foreach ((array)$plugins as $plugin) {
$pluginPath = App::pluginPath($plugin);
$path = $pluginPath . 'vendors' . DS . 'shells' . DS;
if (file_exists($path)) {
$paths[] = $path;
}
}
$vendorPaths = array_values(App::path('vendors'));
foreach ($vendorPaths as $vendorPath) {
$path = rtrim($vendorPath, DS) . DS . 'shells' . DS;
if (file_exists($path)) {
$paths[] = $path;
}
}
$this->shellPaths = array_values(array_unique(array_merge($paths, App::path('shells'))));
}
|
Builds the shell paths.
@access private
@return void
|
__buildPaths
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function __bootstrap() {
define('ROOT', $this->params['root']);
define('APP_DIR', $this->params['app']);
define('APP_PATH', $this->params['working'] . DS);
define('WWW_ROOT', APP_PATH . $this->params['webroot'] . DS);
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
define('TMP', CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'tmp' . DS);
}
$includes = array(
CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'object.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'inflector.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'configure.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'file.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'cache.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'string.php',
CORE_PATH . 'cake' . DS . 'libs' . DS . 'class_registry.php',
CORE_PATH . 'cake' . DS . 'console' . DS . 'error.php'
);
foreach ($includes as $inc) {
if (!require($inc)) {
$this->stderr("Failed to load Cake core file {$inc}");
return false;
}
}
Configure::getInstance(file_exists(CONFIGS . 'bootstrap.php'));
if (!file_exists(APP_PATH . 'config' . DS . 'core.php')) {
include_once CORE_PATH . 'cake' . DS . 'console' . DS . 'templates' . DS . 'skel' . DS . 'config' . DS . 'core.php';
App::build();
}
return true;
}
|
Initializes the environment and loads the Cake core.
@return boolean Success.
@access private
|
__bootstrap
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function clear() {
if (empty($this->params['noclear'])) {
if ( DS === '/') {
passthru('clear');
} else {
passthru('cls');
}
}
}
|
Clear the console
@return void
@access public
|
clear
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function dispatch() {
$arg = $this->shiftArgs();
if (!$arg) {
$this->help();
return false;
}
if ($arg == 'help') {
$this->help();
return true;
}
list($plugin, $shell) = pluginSplit($arg);
$this->shell = $shell;
$this->shellName = Inflector::camelize($shell);
$this->shellClass = $this->shellName . 'Shell';
$arg = null;
if (isset($this->args[0])) {
$arg = $this->args[0];
$this->shellCommand = Inflector::variable($arg);
}
$Shell = $this->_getShell($plugin);
if (!$Shell) {
$title = sprintf(__('Error: Class %s could not be loaded.', true), $this->shellClass);
$this->stderr($title . "\n");
return false;
}
$methods = array();
if (is_a($Shell, 'Shell')) {
$Shell->initialize();
$Shell->loadTasks();
foreach ($Shell->taskNames as $task) {
if (is_a($Shell->{$task}, 'Shell')) {
$Shell->{$task}->initialize();
$Shell->{$task}->loadTasks();
}
}
$task = Inflector::camelize($arg);
if (in_array($task, $Shell->taskNames)) {
$this->shiftArgs();
$Shell->{$task}->startup();
if (isset($this->args[0]) && $this->args[0] == 'help') {
if (method_exists($Shell->{$task}, 'help')) {
$Shell->{$task}->help();
} else {
$this->help();
}
return true;
}
return $Shell->{$task}->execute();
}
$methods = array_diff(get_class_methods('Shell'), array('help'));
}
$methods = array_diff(get_class_methods($Shell), $methods);
$added = in_array(strtolower($arg), array_map('strtolower', $methods));
$private = $arg[0] == '_' && method_exists($Shell, $arg);
if (!$private) {
if ($added) {
$this->shiftArgs();
$Shell->startup();
return $Shell->{$arg}();
}
if (method_exists($Shell, 'main')) {
$Shell->startup();
return $Shell->main();
}
}
$title = sprintf(__('Error: Unknown %1$s command %2$s.', true), $this->shellName, $arg);
$message = sprintf(__('For usage try `cake %s help`', true), $this->shell);
$this->stderr($title . "\n" . $message . "\n");
return false;
}
|
Dispatches a CLI request
@return boolean
@access public
|
dispatch
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function _getShell($plugin = null) {
foreach ($this->shellPaths as $path) {
$this->shellPath = $path . $this->shell . '.php';
$pluginShellPath = DS . $plugin . DS . 'vendors' . DS . 'shells' . DS;
if ((strpos($path, $pluginShellPath) !== false || !$plugin) && file_exists($this->shellPath)) {
$loaded = true;
break;
}
}
if (!isset($loaded)) {
return false;
}
if (!class_exists('Shell')) {
require CONSOLE_LIBS . 'shell.php';
}
if (!class_exists($this->shellClass)) {
require $this->shellPath;
}
if (!class_exists($this->shellClass)) {
return false;
}
$Shell = new $this->shellClass($this);
return $Shell;
}
|
Get shell to use, either plugin shell or application shell
All paths in the shellPaths property are searched.
shell, shellPath and shellClass properties are taken into account.
@param string $plugin Optionally the name of a plugin
@return mixed False if no shell could be found or an object on success
@access protected
|
_getShell
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function getInput($prompt, $options = null, $default = null) {
if (!is_array($options)) {
$printOptions = '';
} else {
$printOptions = '(' . implode('/', $options) . ')';
}
if ($default === null) {
$this->stdout($prompt . " $printOptions \n" . '> ', false);
} else {
$this->stdout($prompt . " $printOptions \n" . "[$default] > ", false);
}
$result = fgets($this->stdin);
if ($result === false) {
exit;
}
$result = trim($result);
if ($default !== null && ($result === '' || $result === null)) {
return $default;
}
return $result;
}
|
Prompts the user for input, and returns it.
@param string $prompt Prompt text.
@param mixed $options Array or string of options.
@param string $default Default input value.
@return Either the default value, or the user-provided input.
@access public
|
getInput
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function stdout($string, $newline = true) {
if ($newline) {
return fwrite($this->stdout, $string . "\n");
} else {
return fwrite($this->stdout, $string);
}
}
|
Outputs to the stdout filehandle.
@param string $string String to output.
@param boolean $newline If true, the outputs gets an added newline.
@return integer Returns the number of bytes output to stdout.
@access public
|
stdout
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function stderr($string) {
fwrite($this->stderr, $string);
}
|
Outputs to the stderr filehandle.
@param string $string Error text to output.
@access public
|
stderr
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function parseParams($params) {
$this->__parseParams($params);
$defaults = array('app' => 'app', 'root' => dirname(dirname(dirname(__FILE__))), 'working' => null, 'webroot' => 'webroot');
$params = array_merge($defaults, array_intersect_key($this->params, $defaults));
$isWin = false;
foreach ($defaults as $default => $value) {
if (strpos($params[$default], '\\') !== false) {
$isWin = true;
break;
}
}
$params = str_replace('\\', '/', $params);
if (isset($params['working'])) {
$params['working'] = trim($params['working']);
}
if (!empty($params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0]{0} !== '.')) {
if (empty($this->params['app']) && $params['working'] != $params['root']) {
$params['root'] = dirname($params['working']);
$params['app'] = basename($params['working']);
} else {
$params['root'] = $params['working'];
}
}
if ($params['app'][0] == '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) {
$params['root'] = dirname($params['app']);
} elseif (strpos($params['app'], '/')) {
$params['root'] .= '/' . dirname($params['app']);
}
$params['app'] = basename($params['app']);
$params['working'] = rtrim($params['root'], '/');
if (!$isWin || !preg_match('/^[A-Z]:$/i', $params['app'])) {
$params['working'] .= '/' . $params['app'];
}
if (!empty($matches[0]) || !empty($isWin)) {
$params = str_replace('/', '\\', $params);
}
$this->params = array_merge($this->params, $params);
}
|
Parses command line options
@param array $params Parameters to parse
@access public
|
parseParams
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function __parseParams($params) {
$count = count($params);
for ($i = 0; $i < $count; $i++) {
if (isset($params[$i])) {
if ($params[$i]{0} === '-') {
$key = substr($params[$i], 1);
$this->params[$key] = true;
unset($params[$i]);
if (isset($params[++$i])) {
if ($params[$i]{0} !== '-') {
$this->params[$key] = str_replace('"', '', $params[$i]);
unset($params[$i]);
} else {
$i--;
$this->__parseParams($params);
}
}
} else {
$this->args[] = $params[$i];
unset($params[$i]);
}
}
}
}
|
Helper for recursively parsing params
@return array params
@access private
|
__parseParams
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function shiftArgs() {
return array_shift($this->args);
}
|
Removes first argument and shifts other arguments up
@return mixed Null if there are no arguments otherwise the shifted argument
@access public
|
shiftArgs
|
php
|
Datawalke/Coordino
|
cake/console/cake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/cake.php
|
MIT
|
function __construct($method, $messages) {
$this->stdout = fopen('php://stdout', 'w');
$this->stderr = fopen('php://stderr', 'w');
call_user_func_array(array(&$this, $method), $messages);
}
|
Class constructor.
@param string $method Method dispatching an error
@param array $messages Error messages
|
__construct
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function error($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr($code . $name . $message."\n");
$this->_stop(1);
}
|
Displays an error page (e.g. 404 Not found).
@param array $params Parameters (code, name, and message)
@access public
|
error
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function error404($params) {
extract($params, EXTR_OVERWRITE);
$this->error(array(
'code' => '404',
'name' => 'Not found',
'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message)
));
$this->_stop(1);
}
|
Convenience method to display a 404 page.
@param array $params Parameters (url, message)
@access public
|
error404
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingController($params) {
extract($params, EXTR_OVERWRITE);
$controllerName = str_replace('Controller', '', $className);
$this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName));
$this->_stop(1);
}
|
Renders the Missing Controller web page.
@param array $params Parameters (className)
@access public
|
missingController
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingAction($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className));
$this->_stop(1);
}
|
Renders the Missing Action web page.
@param array $params Parameters (action, className)
@access public
|
missingAction
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function privateAction($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className));
$this->_stop(1);
}
|
Renders the Private Action web page.
@param array $params Parameters (action, className)
@access public
|
privateAction
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingTable($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className));
$this->_stop(1);
}
|
Renders the Missing Table web page.
@param array $params Parameters (table, className)
@access public
|
missingTable
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingDatabase($params = array()) {
$this->stderr(__("Missing Database", true));
$this->_stop(1);
}
|
Renders the Missing Database web page.
@param array $params Parameters
@access public
|
missingDatabase
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingView($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className));
$this->_stop(1);
}
|
Renders the Missing View web page.
@param array $params Parameters (file, action, className)
@access public
|
missingView
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingLayout($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Layout '%s'", true), $file));
$this->_stop(1);
}
|
Renders the Missing Layout web page.
@param array $params Parameters (file)
@access public
|
missingLayout
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingConnection($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(__("Missing Database Connection. Try 'cake bake'", true));
$this->_stop(1);
}
|
Renders the Database Connection web page.
@param array $params Parameters
@access public
|
missingConnection
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingHelperFile($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector::camelize($helper)));
$this->_stop(1);
}
|
Renders the Missing Helper file web page.
@param array $params Parameters (file, helper)
@access public
|
missingHelperFile
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingHelperClass($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector::camelize($helper), $file));
$this->_stop(1);
}
|
Renders the Missing Helper class web page.
@param array $params Parameters (file, helper)
@access public
|
missingHelperClass
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingComponentFile($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector::camelize($component)));
$this->_stop(1);
}
|
Renders the Missing Component file web page.
@param array $params Parameters (file, component)
@access public
|
missingComponentFile
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingComponentClass($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector::camelize($component), $file));
$this->_stop(1);
}
|
Renders the Missing Component class web page.
@param array $params Parameters (file, component)
@access public
|
missingComponentClass
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function missingModel($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing model '%s'", true), $className));
$this->_stop(1);
}
|
Renders the Missing Model class web page.
@param array $params Parameters (className)
@access public
|
missingModel
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function stdout($string, $newline = true) {
if ($newline) {
fwrite($this->stdout, $string . "\n");
} else {
fwrite($this->stdout, $string);
}
}
|
Outputs to the stdout filehandle.
@param string $string String to output.
@param boolean $newline If true, the outputs gets an added newline.
@access public
|
stdout
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function stderr($string) {
fwrite($this->stderr, "Error: ". $string . "\n");
}
|
Outputs to the stderr filehandle.
@param string $string Error text to output.
@access public
|
stderr
|
php
|
Datawalke/Coordino
|
cake/console/error.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/error.php
|
MIT
|
function startup() {
if (isset($this->params['connection'])) {
$this->connection = $this->params['connection'];
}
if (!in_array(Configure::read('Acl.classname'), array('DbAcl', 'DB_ACL'))) {
$out = "--------------------------------------------------\n";
$out .= __("Error: Your current Cake configuration is set to", true) . "\n";
$out .= __("an ACL implementation other than DB. Please change", true) . "\n";
$out .= __("your core config to reflect your decision to use", true) . "\n";
$out .= __("DbAcl before attempting to use this script", true) . ".\n";
$out .= "--------------------------------------------------\n";
$out .= sprintf(__("Current ACL Classname: %s", true), Configure::read('Acl.classname')) . "\n";
$out .= "--------------------------------------------------\n";
$this->err($out);
$this->_stop();
}
if ($this->command && !in_array($this->command, array('help'))) {
if (!config('database')) {
$this->out(__("Your database configuration was not found. Take a moment to create one.", true), true);
$this->args = null;
return $this->DbConfig->execute();
}
require_once (CONFIGS.'database.php');
if (!in_array($this->command, array('initdb'))) {
$this->Acl =& new AclComponent();
$controller = null;
$this->Acl->startup($controller);
}
}
}
|
Override startup of the Shell
@access public
|
startup
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function main() {
$out = __("Available ACL commands:", true) . "\n";
$out .= "\t - create\n";
$out .= "\t - delete\n";
$out .= "\t - setParent\n";
$out .= "\t - getPath\n";
$out .= "\t - check\n";
$out .= "\t - grant\n";
$out .= "\t - deny\n";
$out .= "\t - inherit\n";
$out .= "\t - view\n";
$out .= "\t - initdb\n";
$out .= "\t - help\n\n";
$out .= __("For help, run the 'help' command. For help on a specific command, run 'help <command>'", true);
$this->out($out);
}
|
Override main() for help message hook
@access public
|
main
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function create() {
$this->_checkArgs(3, 'create');
$this->checkNodeType();
extract($this->__dataVars());
$class = ucfirst($this->args[0]);
$parent = $this->parseIdentifier($this->args[1]);
if (!empty($parent) && $parent != '/' && $parent != 'root') {
$parent = $this->_getNodeId($class, $parent);
} else {
$parent = null;
}
$data = $this->parseIdentifier($this->args[2]);
if (is_string($data) && $data != '/') {
$data = array('alias' => $data);
} elseif (is_string($data)) {
$this->error(__('/ can not be used as an alias!', true), __("\t/ is the root, please supply a sub alias", true));
}
$data['parent_id'] = $parent;
$this->Acl->{$class}->create();
if ($this->Acl->{$class}->save($data)) {
$this->out(sprintf(__("New %s '%s' created.\n", true), $class, $this->args[2]), true);
} else {
$this->err(sprintf(__("There was a problem creating a new %s '%s'.", true), $class, $this->args[2]));
}
}
|
Creates an ARO/ACO node
@access public
|
create
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function delete() {
$this->_checkArgs(2, 'delete');
$this->checkNodeType();
extract($this->__dataVars());
$identifier = $this->parseIdentifier($this->args[1]);
$nodeId = $this->_getNodeId($class, $identifier);
if (!$this->Acl->{$class}->delete($nodeId)) {
$this->error(__("Node Not Deleted", true), sprintf(__("There was an error deleting the %s. Check that the node exists", true), $class) . ".\n");
}
$this->out(sprintf(__("%s deleted", true), $class) . ".\n", true);
}
|
Delete an ARO/ACO node.
@access public
|
delete
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function setParent() {
$this->_checkArgs(3, 'setParent');
$this->checkNodeType();
extract($this->__dataVars());
$target = $this->parseIdentifier($this->args[1]);
$parent = $this->parseIdentifier($this->args[2]);
$data = array(
$class => array(
'id' => $this->_getNodeId($class, $target),
'parent_id' => $this->_getNodeId($class, $parent)
)
);
$this->Acl->{$class}->create();
if (!$this->Acl->{$class}->save($data)) {
$this->out(__("Error in setting new parent. Please make sure the parent node exists, and is not a descendant of the node specified.", true), true);
} else {
$this->out(sprintf(__("Node parent set to %s", true), $this->args[2]) . "\n", true);
}
}
|
Set parent for an ARO/ACO node.
@access public
|
setParent
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function getPath() {
$this->_checkArgs(2, 'getPath');
$this->checkNodeType();
extract($this->__dataVars());
$identifier = $this->parseIdentifier($this->args[1]);
$id = $this->_getNodeId($class, $identifier);
$nodes = $this->Acl->{$class}->getPath($id);
if (empty($nodes)) {
$this->error(
sprintf(__("Supplied Node '%s' not found", true), $this->args[1]),
__("No tree returned.", true)
);
}
$this->out(__('Path:', true));
$this->hr();
for ($i = 0; $i < count($nodes); $i++) {
$this->_outputNode($class, $nodes[$i], $i);
}
}
|
Get path to specified ARO/ACO node.
@access public
|
getPath
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function _outputNode($class, $node, $indent) {
$indent = str_repeat(' ', $indent);
$data = $node[$class];
if ($data['alias']) {
$this->out($indent . "[" . $data['id'] . "] " . $data['alias']);
} else {
$this->out($indent . "[" . $data['id'] . "] " . $data['model'] . '.' . $data['foreign_key']);
}
}
|
Outputs a single node, Either using the alias or Model.key
@param string $class Class name that is being used.
@param array $node Array of node information.
@param integer $indent indent level.
@return void
@access protected
|
_outputNode
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function check() {
$this->_checkArgs(3, 'check');
extract($this->__getParams());
if ($this->Acl->check($aro, $aco, $action)) {
$this->out(sprintf(__("%s is allowed.", true), $aroName), true);
} else {
$this->out(sprintf(__("%s is not allowed.", true), $aroName), true);
}
}
|
Check permission for a given ARO to a given ACO.
@access public
|
check
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function grant() {
$this->_checkArgs(3, 'grant');
extract($this->__getParams());
if ($this->Acl->allow($aro, $aco, $action)) {
$this->out(__("Permission granted.", true), true);
} else {
$this->out(__("Permission was not granted.", true), true);
}
}
|
Grant permission for a given ARO to a given ACO.
@access public
|
grant
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function deny() {
$this->_checkArgs(3, 'deny');
extract($this->__getParams());
if ($this->Acl->deny($aro, $aco, $action)) {
$this->out(__("Permission denied.", true), true);
} else {
$this->out(__("Permission was not denied.", true), true);
}
}
|
Deny access for an ARO to an ACO.
@access public
|
deny
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function view() {
$this->_checkArgs(1, 'view');
$this->checkNodeType();
extract($this->__dataVars());
if (isset($this->args[1])) {
$identity = $this->parseIdentifier($this->args[1]);
$topNode = $this->Acl->{$class}->find('first', array(
'conditions' => array($class . '.id' => $this->_getNodeId($class, $identity))
));
$nodes = $this->Acl->{$class}->find('all', array(
'conditions' => array(
$class . '.lft >=' => $topNode[$class]['lft'],
$class . '.lft <=' => $topNode[$class]['rght']
),
'order' => $class . '.lft ASC'
));
} else {
$nodes = $this->Acl->{$class}->find('all', array('order' => $class . '.lft ASC'));
}
if (empty($nodes)) {
if (isset($this->args[1])) {
$this->error(sprintf(__("%s not found", true), $this->args[1]), __("No tree returned.", true));
} elseif (isset($this->args[0])) {
$this->error(sprintf(__("%s not found", true), $this->args[0]), __("No tree returned.", true));
}
}
$this->out($class . " tree:");
$this->hr();
$stack = array();
$last = null;
foreach ($nodes as $n) {
$stack[] = $n;
if (!empty($last)) {
$end = end($stack);
if ($end[$class]['rght'] > $last) {
foreach ($stack as $k => $v) {
$end = end($stack);
if ($v[$class]['rght'] < $end[$class]['rght']) {
unset($stack[$k]);
}
}
}
}
$last = $n[$class]['rght'];
$count = count($stack);
$this->_outputNode($class, $n, $count);
}
$this->hr();
}
|
Show a specific ARO/ACO node.
@access public
|
view
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function checkNodeType() {
if (!isset($this->args[0])) {
return false;
}
if ($this->args[0] != 'aco' && $this->args[0] != 'aro') {
$this->error(sprintf(__("Missing/Unknown node type: '%s'", true), $this->args[0]), __('Please specify which ACL object type you wish to create. Either "aro" or "aco"', true));
}
}
|
Check that first argument specifies a valid Node type (ARO/ACO)
@access public
|
checkNodeType
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function nodeExists() {
if (!$this->checkNodeType() && !isset($this->args[1])) {
return false;
}
extract($this->__dataVars($this->args[0]));
$key = is_numeric($this->args[1]) ? $secondary_id : 'alias';
$conditions = array($class . '.' . $key => $this->args[1]);
$possibility = $this->Acl->{$class}->find('all', compact('conditions'));
if (empty($possibility)) {
$this->error(sprintf(__("%s not found", true), $this->args[1]), __("No tree returned.", true));
}
return $possibility;
}
|
Checks that given node exists
@param string $type Node type (ARO/ACO)
@param integer $id Node id
@return boolean Success
@access public
|
nodeExists
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function parseIdentifier($identifier) {
if (preg_match('/^([\w]+)\.(.*)$/', $identifier, $matches)) {
return array(
'model' => $matches[1],
'foreign_key' => $matches[2],
);
}
return $identifier;
}
|
Parse an identifier into Model.foriegnKey or an alias.
Takes an identifier determines its type and returns the result as used by other methods.
@param string $identifier Identifier to parse
@return mixed a string for aliases, and an array for model.foreignKey
|
parseIdentifier
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function _getNodeId($class, $identifier) {
$node = $this->Acl->{$class}->node($identifier);
if (empty($node)) {
if (is_array($identifier)) {
$identifier = var_export($identifier, true);
}
$this->error(sprintf(__('Could not find node using reference "%s"', true), $identifier));
}
return Set::extract($node, "0.{$class}.id");
}
|
Get the node for a given identifier. $identifier can either be a string alias
or an array of properties to use in AcoNode::node()
@param string $class Class type you want (Aro/Aco)
@param mixed $identifier A mixed identifier for finding the node.
@return int Integer of NodeId. Will trigger an error if nothing is found.
|
_getNodeId
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function __getParams() {
$aro = is_numeric($this->args[0]) ? intval($this->args[0]) : $this->args[0];
$aco = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1];
$aroName = $aro;
$acoName = $aco;
if (is_string($aro)) {
$aro = $this->parseIdentifier($aro);
}
if (is_string($aco)) {
$aco = $this->parseIdentifier($aco);
}
$action = null;
if (isset($this->args[2])) {
$action = $this->args[2];
if ($action == '' || $action == 'all') {
$action = '*';
}
}
return compact('aro', 'aco', 'action', 'aroName', 'acoName');
}
|
get params for standard Acl methods
@return array aro, aco, action
@access private
|
__getParams
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function __dataVars($type = null) {
if ($type == null) {
$type = $this->args[0];
}
$vars = array();
$class = ucwords($type);
$vars['secondary_id'] = (strtolower($class) == 'aro') ? 'foreign_key' : 'object_id';
$vars['data_name'] = $type;
$vars['table_name'] = $type . 's';
$vars['class'] = $class;
return $vars;
}
|
Build data parameters based on node type
@param string $type Node type (ARO/ACO)
@return array Variables
@access private
|
__dataVars
|
php
|
Datawalke/Coordino
|
cake/console/libs/acl.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/acl.php
|
MIT
|
function initialize() {
$this->paths = array_merge($this->paths, array(
'behavior' => LIBS . 'model' . DS . 'behaviors' . DS,
'cache' => LIBS . 'cache' . DS,
'controller' => LIBS . 'controller' . DS,
'component' => LIBS . 'controller' . DS . 'components' . DS,
'helper' => LIBS . 'view' . DS . 'helpers' . DS,
'model' => LIBS . 'model' . DS,
'view' => LIBS . 'view' . DS,
'core' => LIBS
));
}
|
Override intialize of the Shell
@access public
|
initialize
|
php
|
Datawalke/Coordino
|
cake/console/libs/api.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/api.php
|
MIT
|
function main() {
if (empty($this->args)) {
return $this->help();
}
$type = strtolower($this->args[0]);
if (isset($this->paths[$type])) {
$path = $this->paths[$type];
} else {
$path = $this->paths['core'];
}
if (count($this->args) == 1) {
$file = $type;
$class = Inflector::camelize($type);
} elseif (count($this->args) > 1) {
$file = Inflector::underscore($this->args[1]);
$class = Inflector::camelize($file);
}
$objects = App::objects('class', $path);
if (in_array($class, $objects)) {
if (in_array($type, array('behavior', 'component', 'helper')) && $type !== $file) {
if (!preg_match('/' . Inflector::camelize($type) . '$/', $class)) {
$class .= Inflector::camelize($type);
}
}
} else {
$this->err(sprintf(__("%s not found", true), $class));
$this->_stop();
}
$parsed = $this->__parseClass($path . $file .'.php');
if (!empty($parsed)) {
if (isset($this->params['m'])) {
if (!isset($parsed[$this->params['m']])) {
$this->err(sprintf(__("%s::%s() could not be found", true), $class, $this->params['m']));
$this->_stop();
}
$method = $parsed[$this->params['m']];
$this->out($class .'::'.$method['method'] . $method['parameters']);
$this->hr();
$this->out($method['comment'], true);
} else {
$this->out(ucwords($class));
$this->hr();
$i = 0;
foreach ($parsed as $method) {
$list[] = ++$i . ". " . $method['method'] . $method['parameters'];
}
$this->out($list);
$methods = array_keys($parsed);
while ($number = strtolower($this->in(__('Select a number to see the more information about a specific method. q to quit. l to list.', true), null, 'q'))) {
if ($number === 'q') {
$this->out(__('Done', true));
$this->_stop();
}
if ($number === 'l') {
$this->out($list);
}
if (isset($methods[--$number])) {
$method = $parsed[$methods[$number]];
$this->hr();
$this->out($class .'::'.$method['method'] . $method['parameters']);
$this->hr();
$this->out($method['comment'], true);
}
}
}
}
}
|
Override main() to handle action
@access public
|
main
|
php
|
Datawalke/Coordino
|
cake/console/libs/api.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/api.php
|
MIT
|
function help() {
$head = "Usage: cake api [<type>] <className> [-m <method>]\n";
$head .= "-----------------------------------------------\n";
$head .= "Parameters:\n\n";
$commands = array(
'path' => "\t<type>\n" .
"\t\tEither a full path or type of class (model, behavior, controller, component, view, helper).\n".
"\t\tAvailable values:\n\n".
"\t\tbehavior\tLook for class in CakePHP behavior path\n".
"\t\tcache\tLook for class in CakePHP cache path\n".
"\t\tcontroller\tLook for class in CakePHP controller path\n".
"\t\tcomponent\tLook for class in CakePHP component path\n".
"\t\thelper\tLook for class in CakePHP helper path\n".
"\t\tmodel\tLook for class in CakePHP model path\n".
"\t\tview\tLook for class in CakePHP view path\n",
'className' => "\t<className>\n" .
"\t\tA CakePHP core class name (e.g: Component, HtmlHelper).\n"
);
$this->out($head);
if (!isset($this->args[1])) {
foreach ($commands as $cmd) {
$this->out("{$cmd}\n\n");
}
} elseif (isset($commands[strtolower($this->args[1])])) {
$this->out($commands[strtolower($this->args[1])] . "\n\n");
} else {
$this->out("Command '" . $this->args[1] . "' not found");
}
}
|
Show help for this shell.
@access public
|
help
|
php
|
Datawalke/Coordino
|
cake/console/libs/api.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/api.php
|
MIT
|
function __parseClass($path) {
$parsed = array();
$File = new File($path);
if (!$File->exists()) {
$this->err(sprintf(__("%s could not be found", true), $File->name));
$this->_stop();
}
$contents = $File->read();
if (preg_match_all('%(/\\*\\*[\\s\\S]*?\\*/)(\\s+function\\s+\\w+)(\\(.*\\))%', $contents, $result, PREG_PATTERN_ORDER)) {
foreach ($result[2] as $key => $method) {
$method = str_replace('function ', '', trim($method));
if (strpos($method, '__') === false && $method[0] != '_') {
$parsed[$method] = array(
'comment' => str_replace(array('/*', '*/', '*'), '', trim($result[1][$key])),
'method' => $method,
'parameters' => trim($result[3][$key])
);
}
}
}
ksort($parsed);
return $parsed;
}
|
Parse a given class (located on given file) and get public methods and their
signatures.
@param object $File File object
@param string $class Class name
@return array Methods and signatures indexed by method name
@access private
|
__parseClass
|
php
|
Datawalke/Coordino
|
cake/console/libs/api.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/api.php
|
MIT
|
function loadTasks() {
parent::loadTasks();
$task = Inflector::classify($this->command);
if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
if (isset($this->params['connection'])) {
$this->{$task}->connection = $this->params['connection'];
}
foreach($this->args as $i => $arg) {
if (strpos($arg, '.')) {
list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
break;
}
}
if (isset($this->params['plugin'])) {
$this->{$task}->plugin = $this->params['plugin'];
}
}
}
|
Override loadTasks() to handle paths
@access public
|
loadTasks
|
php
|
Datawalke/Coordino
|
cake/console/libs/bake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/bake.php
|
MIT
|
function main() {
Configure::write('Cache.disable', 1);
if (!is_dir($this->DbConfig->path)) {
if ($this->Project->execute()) {
$this->DbConfig->path = $this->params['working'] . DS . 'config' . DS;
} else {
return false;
}
}
if (!config('database')) {
$this->out(__("Your database configuration was not found. Take a moment to create one.", true));
$this->args = null;
return $this->DbConfig->execute();
}
$this->out('Interactive Bake Shell');
$this->hr();
$this->out('[D]atabase Configuration');
$this->out('[M]odel');
$this->out('[V]iew');
$this->out('[C]ontroller');
$this->out('[P]roject');
$this->out('[F]ixture');
$this->out('[T]est case');
$this->out('[Q]uit');
$classToBake = strtoupper($this->in(__('What would you like to Bake?', true), array('D', 'M', 'V', 'C', 'P', 'F', 'T', 'Q')));
switch ($classToBake) {
case 'D':
$this->DbConfig->execute();
break;
case 'M':
$this->Model->execute();
break;
case 'V':
$this->View->execute();
break;
case 'C':
$this->Controller->execute();
break;
case 'P':
$this->Project->execute();
break;
case 'F':
$this->Fixture->execute();
break;
case 'T':
$this->Test->execute();
break;
case 'Q':
exit(0);
break;
default:
$this->out(__('You have made an invalid selection. Please choose a type of class to Bake by entering D, M, V, F, T, or C.', true));
}
$this->hr();
$this->main();
}
|
Override main() to handle action
@access public
|
main
|
php
|
Datawalke/Coordino
|
cake/console/libs/bake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/bake.php
|
MIT
|
function all() {
$this->hr();
$this->out('Bake All');
$this->hr();
if (!isset($this->params['connection']) && empty($this->connection)) {
$this->connection = $this->DbConfig->getConfig();
}
if (empty($this->args)) {
$this->Model->interactive = true;
$name = $this->Model->getName($this->connection);
}
foreach (array('Model', 'Controller', 'View') as $task) {
$this->{$task}->connection = $this->connection;
$this->{$task}->interactive = false;
}
if (!empty($this->args[0])) {
$name = $this->args[0];
}
$modelExists = false;
$model = $this->_modelName($name);
if (App::import('Model', $model)) {
$object = new $model();
$modelExists = true;
} else {
App::import('Model', 'Model', false);
$object = new Model(array('name' => $name, 'ds' => $this->connection));
}
$modelBaked = $this->Model->bake($object, false);
if ($modelBaked && $modelExists === false) {
$this->out(sprintf(__('%s Model was baked.', true), $model));
if ($this->_checkUnitTest()) {
$this->Model->bakeFixture($model);
$this->Model->bakeTest($model);
}
$modelExists = true;
}
if ($modelExists === true) {
$controller = $this->_controllerName($name);
if ($this->Controller->bake($controller, $this->Controller->bakeActions($controller))) {
$this->out(sprintf(__('%s Controller was baked.', true), $name));
if ($this->_checkUnitTest()) {
$this->Controller->bakeTest($controller);
}
}
if (App::import('Controller', $controller)) {
$this->View->args = array($controller);
$this->View->execute();
$this->out(sprintf(__('%s Views were baked.', true), $name));
}
$this->out(__('Bake All complete', true));
array_shift($this->args);
} else {
$this->err(__('Bake All could not continue without a valid model', true));
}
$this->_stop();
}
|
Quickly bake the MVC
@access public
|
all
|
php
|
Datawalke/Coordino
|
cake/console/libs/bake.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/bake.php
|
MIT
|
function initialize() {
require_once CAKE . 'dispatcher.php';
$this->Dispatcher = new Dispatcher();
$this->models = App::objects('model');
App::import('Model', $this->models);
foreach ($this->models as $model) {
$class = Inflector::camelize(str_replace('.php', '', $model));
$this->models[$model] = $class;
$this->{$class} =& new $class();
}
$this->out('Model classes:');
$this->out('--------------');
foreach ($this->models as $model) {
$this->out(" - {$model}");
}
$this->_loadRoutes();
}
|
Override intialize of the Shell
@access public
|
initialize
|
php
|
Datawalke/Coordino
|
cake/console/libs/console.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/console.php
|
MIT
|
function help() {
$out = 'Console help:';
$out .= '-------------';
$out .= 'The interactive console is a tool for testing parts of your app before you';
$out .= 'write code.';
$out .= "\n";
$out .= 'Model testing:';
$out .= 'To test model results, use the name of your model without a leading $';
$out .= 'e.g. Foo->find("all")';
$out .= "\n";
$out .= 'To dynamically set associations, you can do the following:';
$out .= "\tModelA bind <association> ModelB";
$out .= "where the supported assocations are hasOne, hasMany, belongsTo, hasAndBelongsToMany";
$out .= "\n";
$out .= 'To dynamically remove associations, you can do the following:';
$out .= "\t ModelA unbind <association> ModelB";
$out .= "where the supported associations are the same as above";
$out .= "\n";
$out .= "To save a new field in a model, you can do the following:";
$out .= "\tModelA->save(array('foo' => 'bar', 'baz' => 0))";
$out .= "where you are passing a hash of data to be saved in the format";
$out .= "of field => value pairs";
$out .= "\n";
$out .= "To get column information for a model, use the following:";
$out .= "\tModelA columns";
$out .= "which returns a list of columns and their type";
$out .= "\n";
$out .= "\n";
$out .= 'Route testing:';
$out .= "\n";
$out .= 'To test URLs against your app\'s route configuration, type:';
$out .= "\n";
$out .= "\tRoute <url>";
$out .= "\n";
$out .= "where url is the path to your your action plus any query parameters,";
$out .= "minus the application's base path. For example:";
$out .= "\n";
$out .= "\tRoute /posts/view/1";
$out .= "\n";
$out .= "will return something like the following:";
$out .= "\n";
$out .= "\tarray (";
$out .= "\t [...]";
$out .= "\t 'controller' => 'posts',";
$out .= "\t 'action' => 'view',";
$out .= "\t [...]";
$out .= "\t)";
$out .= "\n";
$out .= 'Alternatively, you can use simple array syntax to test reverse';
$out .= 'To reload your routes config (config/routes.php), do the following:';
$out .= "\n";
$out .= "\tRoutes reload";
$out .= "\n";
$out .= 'To show all connected routes, do the following:';
$out .= "\tRoutes show";
$this->out($out);
}
|
Prints the help message
@access public
|
help
|
php
|
Datawalke/Coordino
|
cake/console/libs/console.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/console.php
|
MIT
|
function main($command = null) {
while (true) {
if (empty($command)) {
$command = trim($this->in(''));
}
switch ($command) {
case 'help':
$this->help();
break;
case 'quit':
case 'exit':
return true;
break;
case 'models':
$this->out('Model classes:');
$this->hr();
foreach ($this->models as $model) {
$this->out(" - {$model}");
}
break;
case (preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp) == true):
foreach ($tmp as $data) {
$data = strip_tags($data);
$data = str_replace($this->badCommandChars, "", $data);
}
$modelA = $tmp[1];
$association = $tmp[2];
$modelB = $tmp[3];
if ($this->_isValidModel($modelA) && $this->_isValidModel($modelB) && in_array($association, $this->associations)) {
$this->{$modelA}->bindModel(array($association => array($modelB => array('className' => $modelB))), false);
$this->out("Created $association association between $modelA and $modelB");
} else {
$this->out("Please verify you are using valid models and association types");
}
break;
case (preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp) == true):
foreach ($tmp as $data) {
$data = strip_tags($data);
$data = str_replace($this->badCommandChars, "", $data);
}
$modelA = $tmp[1];
$association = $tmp[2];
$modelB = $tmp[3];
// Verify that there is actually an association to unbind
$currentAssociations = $this->{$modelA}->getAssociated();
$validCurrentAssociation = false;
foreach ($currentAssociations as $model => $currentAssociation) {
if ($model == $modelB && $association == $currentAssociation) {
$validCurrentAssociation = true;
}
}
if ($this->_isValidModel($modelA) && $this->_isValidModel($modelB) && in_array($association, $this->associations) && $validCurrentAssociation) {
$this->{$modelA}->unbindModel(array($association => array($modelB)));
$this->out("Removed $association association between $modelA and $modelB");
} else {
$this->out("Please verify you are using valid models, valid current association, and valid association types");
}
break;
case (strpos($command, "->find") > 0):
// Remove any bad info
$command = strip_tags($command);
$command = str_replace($this->badCommandChars, "", $command);
// Do we have a valid model?
list($modelToCheck, $tmp) = explode('->', $command);
if ($this->_isValidModel($modelToCheck)) {
$findCommand = "\$data = \$this->$command;";
@eval($findCommand);
if (is_array($data)) {
foreach ($data as $idx => $results) {
if (is_numeric($idx)) { // findAll() output
foreach ($results as $modelName => $result) {
$this->out("$modelName");
foreach ($result as $field => $value) {
if (is_array($value)) {
foreach ($value as $field2 => $value2) {
$this->out("\t$field2: $value2");
}
$this->out();
} else {
$this->out("\t$field: $value");
}
}
}
} else { // find() output
$this->out($idx);
foreach ($results as $field => $value) {
if (is_array($value)) {
foreach ($value as $field2 => $value2) {
$this->out("\t$field2: $value2");
}
$this->out();
} else {
$this->out("\t$field: $value");
}
}
}
}
} else {
$this->out("\nNo result set found");
}
} else {
$this->out("$modelToCheck is not a valid model");
}
break;
case (strpos($command, '->save') > 0):
// Validate the model we're trying to save here
$command = strip_tags($command);
$command = str_replace($this->badCommandChars, "", $command);
list($modelToSave, $tmp) = explode("->", $command);
if ($this->_isValidModel($modelToSave)) {
// Extract the array of data we are trying to build
list($foo, $data) = explode("->save", $command);
$data = preg_replace('/^\(*(array)?\(*(.+?)\)*$/i', '\\2', $data);
$saveCommand = "\$this->{$modelToSave}->save(array('{$modelToSave}' => array({$data})));";
@eval($saveCommand);
$this->out('Saved record for ' . $modelToSave);
}
break;
case (preg_match("/^(\w+) columns/", $command, $tmp) == true):
$modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1]));
if ($this->_isValidModel($modelToCheck)) {
// Get the column info for this model
$fieldsCommand = "\$data = \$this->{$modelToCheck}->getColumnTypes();";
@eval($fieldsCommand);
if (is_array($data)) {
foreach ($data as $field => $type) {
$this->out("\t{$field}: {$type}");
}
}
} else {
$this->out("Please verify that you selected a valid model");
}
break;
case (preg_match("/^routes\s+reload/i", $command, $tmp) == true):
$router =& Router::getInstance();
if (!$this->_loadRoutes()) {
$this->out("There was an error loading the routes config. Please check that the file");
$this->out("exists and is free of parse errors.");
break;
}
$this->out("Routes configuration reloaded, " . count($router->routes) . " routes connected");
break;
case (preg_match("/^routes\s+show/i", $command, $tmp) == true):
$router =& Router::getInstance();
$this->out(implode("\n", Set::extract($router->routes, '{n}.0')));
break;
case (preg_match("/^route\s+(\(.*\))$/i", $command, $tmp) == true):
if ($url = eval('return array' . $tmp[1] . ';')) {
$this->out(Router::url($url));
}
break;
case (preg_match("/^route\s+(.*)/i", $command, $tmp) == true):
$this->out(var_export(Router::parse($tmp[1]), true));
break;
default:
$this->out("Invalid command\n");
break;
}
$command = '';
}
}
|
Override main() to handle action
@access public
|
main
|
php
|
Datawalke/Coordino
|
cake/console/libs/console.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/console.php
|
MIT
|
function _isValidModel($modelToCheck) {
return in_array($modelToCheck, $this->models);
}
|
Tells if the specified model is included in the list of available models
@param string $modelToCheck
@return boolean true if is an available model, false otherwise
@access protected
|
_isValidModel
|
php
|
Datawalke/Coordino
|
cake/console/libs/console.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/console.php
|
MIT
|
function _loadRoutes() {
$router =& Router::getInstance();
$router->reload();
extract($router->getNamedExpressions());
if (!@include(CONFIGS . 'routes.php')) {
return false;
}
$router->parse('/');
foreach (array_keys($router->getNamedExpressions()) as $var) {
unset(${$var});
}
for ($i = 0, $len = count($router->routes); $i < $len; $i++) {
$router->routes[$i]->compile();
}
return true;
}
|
Reloads the routes configuration from config/routes.php, and compiles
all routes found
@return boolean True if config reload was a success, otherwise false
@access protected
|
_loadRoutes
|
php
|
Datawalke/Coordino
|
cake/console/libs/console.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/console.php
|
MIT
|
function startup() {
$this->_welcome();
if (isset($this->params['datasource'])) {
$this->dataSource = $this->params['datasource'];
}
if ($this->command && !in_array($this->command, array('help'))) {
if (!config('database')) {
$this->out(__('Your database configuration was not found. Take a moment to create one.', true), true);
return $this->DbConfig->execute();
}
}
}
|
Override startup of the Shell
@access public
|
startup
|
php
|
Datawalke/Coordino
|
cake/console/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/i18n.php
|
MIT
|
function main() {
$this->out(__('I18n Shell', true));
$this->hr();
$this->out(__('[E]xtract POT file from sources', true));
$this->out(__('[I]nitialize i18n database table', true));
$this->out(__('[H]elp', true));
$this->out(__('[Q]uit', true));
$choice = strtolower($this->in(__('What would you like to do?', true), array('E', 'I', 'H', 'Q')));
switch ($choice) {
case 'e':
$this->Extract->execute();
break;
case 'i':
$this->initdb();
break;
case 'h':
$this->help();
break;
case 'q':
exit(0);
break;
default:
$this->out(__('You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.', true));
}
$this->hr();
$this->main();
}
|
Override main() for help message hook
@access public
|
main
|
php
|
Datawalke/Coordino
|
cake/console/libs/i18n.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/i18n.php
|
MIT
|
function view() {
$File = new File($this->Schema->path . DS . $this->params['file']);
if ($File->exists()) {
$this->out($File->read());
$this->_stop();
} else {
$file = $this->Schema->path . DS . $this->params['file'];
$this->err(sprintf(__('Schema file (%s) could not be found.', true), $file));
$this->_stop();
}
}
|
Read and output contents of schema object
path to read as second arg
@access public
|
view
|
php
|
Datawalke/Coordino
|
cake/console/libs/schema.php
|
https://github.com/Datawalke/Coordino/blob/master/cake/console/libs/schema.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.