mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merging fixes and enhancements into trunk
Revision: [1953] Added @ before session_destroy() in CakeSession::_destroyInvalid() to suppress warning Revision: [1952] Fixing Ticket #380, and adding JSON object generator to JavascriptHelper Revision: [1951] Removing code that is not used in Inflector class git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1954 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
e51b3d4915
commit
40f3a01d1e
5 changed files with 50 additions and 87 deletions
|
@ -6,4 +6,4 @@
|
|||
// +---------------------------------------------------------------------------------------------------+ //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
0.10.8.1949 RC 4
|
||||
0.10.8.1954
|
|
@ -261,11 +261,9 @@ class AclNode extends AppModel
|
|||
*/
|
||||
function _syncTable($table, $dir, $lft, $rght)
|
||||
{
|
||||
pr('...Syncing...');
|
||||
$shift = ($dir == 2 ? 1 : 2);
|
||||
$this->db->query("UPDATE $table SET rght = rght " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE rght > " . $rght);
|
||||
$this->db->query("UPDATE $table SET lft = lft " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE lft > " . $lft);
|
||||
pr('...Done Syncing...');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -308,83 +308,6 @@ class Inflector extends Object
|
|||
{
|
||||
return Inflector::camelize(Inflector::singularize($tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns $class_name in underscored form, with "_id" tacked on at the end.
|
||||
* This is for use in dealing with foreign keys in the database.
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return string
|
||||
*/
|
||||
function foreignKey($className)
|
||||
{
|
||||
return Inflector::underscore($className) . "_id";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns filename for given Cake controller name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
function toControllerFilename($name)
|
||||
{
|
||||
return CONTROLLERS.Inflector::underscore($name).'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns filename for given Cake helper name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
function toHelperFilename($name)
|
||||
{
|
||||
return HELPERS.Inflector::underscore($name).'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns given name as camelized.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $correct
|
||||
* @return string
|
||||
* @todo Explain this method
|
||||
*/
|
||||
function toFullName($name, $correct)
|
||||
{
|
||||
if (strstr($name, '_') && (strtolower($name) == $name))
|
||||
{
|
||||
return Inflector::camelize($name);
|
||||
}
|
||||
|
||||
if (preg_match("/^(.*)({$correct})$/i", $name, $reg))
|
||||
{
|
||||
if ($reg[2] == $correct)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ucfirst($reg[1].$correct);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ucfirst($name.$correct);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns filename for given Cake library name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
function toLibraryFilename ($name)
|
||||
{
|
||||
return LIBS.Inflector::underscore($name).'.php';
|
||||
}
|
||||
}
|
||||
|
||||
function __enclose($string)
|
||||
|
|
|
@ -321,7 +321,7 @@ class CakeSession extends Object
|
|||
setcookie(CAKE_SESSION_COOKIE, '', time()-42000, $this->path);
|
||||
}
|
||||
$file = $sessionpath.DS."sess_".session_id();
|
||||
session_destroy();
|
||||
@session_destroy();
|
||||
@unlink($file);
|
||||
$this->__construct($this->path);
|
||||
}
|
||||
|
|
|
@ -153,11 +153,11 @@ class JavascriptHelper extends Helper
|
|||
*
|
||||
* @return null
|
||||
*/
|
||||
function cacheEvents ()
|
||||
{
|
||||
$this->_cacheEvents = true;
|
||||
}
|
||||
|
||||
function cacheEvents ()
|
||||
{
|
||||
$this->_cacheEvents = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write cached JavaScript events
|
||||
|
@ -170,7 +170,6 @@ class JavascriptHelper extends Helper
|
|||
return $this->codeBlock("\n" . implode("\n", $this->_cachedEvents) . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Includes the Prototype Javascript library (and anything else) inside a single script tag.
|
||||
*
|
||||
|
@ -201,6 +200,49 @@ class JavascriptHelper extends Helper
|
|||
return $this->codeBlock("\n\n" . $javascript);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a JavaScript object in JavaScript Object Notation (JSON)
|
||||
* from an array
|
||||
*
|
||||
* @param array $data Data to be converted
|
||||
* @param boolean $block Wraps return value in a <script /> block if true
|
||||
* @param string $prefix Prepends the string to the returned data
|
||||
* @param string $postfix Appends the string to the returned data
|
||||
* @param array $stringKeys A list of array keys to be treated as a string
|
||||
* @param boolean $quoteKeys If false, treats $stringKey as a list of keys *not* to be quoted
|
||||
* @param string $q The type of quote to use
|
||||
* @return string A JSON code block
|
||||
*/
|
||||
function object ($data = array(), $block = false, $prefix = '', $postfix = '', $stringKeys = array(), $quoteKeys = true, $q = "'")
|
||||
{
|
||||
$out = array();
|
||||
foreach($data as $key => $val)
|
||||
{
|
||||
if (is_array($val))
|
||||
{
|
||||
$out[] = $key.':'.$this->object($val, false, '', '', $stringKeys, $quoteKeys, $q);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((!count($stringKeys) && !is_numeric($val) && !is_bool($val)) || ($quoteKeys && in_array($key, $stringKeys)) || (!$quoteKeys && !in_array($key, $stringKeys)))
|
||||
{
|
||||
$val = $q.$val.$q;
|
||||
}
|
||||
if (trim($val) == '')
|
||||
{
|
||||
$val = 'null';
|
||||
}
|
||||
|
||||
$out[] = $key.':'.$val;
|
||||
}
|
||||
}
|
||||
$rt = $prefix.'{'.join(', ', $out).'}'.$postfix;
|
||||
if ($block)
|
||||
{
|
||||
return $this->codeBlock($rt);
|
||||
}
|
||||
return $rt;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue