Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -1,18 +1,20 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('View', 'View');
App::uses('Xml', 'Utility');
App::uses('Hash', 'Utility');
/**
* A view class that is used for creating XML responses.
@ -31,19 +33,19 @@ App::uses('Xml', 'Utility');
*
* **Note** The view variable you specify must be compatible with Xml::fromArray().
*
* You can also define `'_serialize'` as an array. This will create an additional
* You can also define `'_serialize'` as an array. This will create an additional
* top level element named `<response>` containing all the named view variables:
*
* {{{
* ```
* $this->set(compact('posts', 'users', 'stuff'));
* $this->set('_serialize', array('posts', 'users'));
* }}}
* ```
*
* The above would generate a XML object that looks like:
*
* `<response><posts>...</posts><users>...</users></response>`
*
* If you don't use the `_serialize` key, you will need a view. You can use extended
* If you don't use the `_serialize` key, you will need a view. You can use extended
* views to provide layout like functionality.
*
* @package Cake.View
@ -52,7 +54,7 @@ App::uses('Xml', 'Utility');
class XmlView extends View {
/**
* The subdirectory. XML views are always in xml.
* The subdirectory. XML views are always in xml.
*
* @var string
*/
@ -61,7 +63,7 @@ class XmlView extends View {
/**
* Constructor
*
* @param Controller $controller
* @param Controller $controller Controller instance.
*/
public function __construct(Controller $controller = null) {
parent::__construct($controller);
@ -71,12 +73,24 @@ class XmlView extends View {
}
}
/**
* Skip loading helpers if this is a _serialize based view.
*
* @return void
*/
public function loadHelpers() {
if (isset($this->viewVars['_serialize'])) {
return;
}
parent::loadHelpers();
}
/**
* Render a XML view.
*
* Uses the special '_serialize' parameter to convert a set of
* view variables into a XML response. Makes generating simple
* XML responses very easy. You can omit the '_serialize' parameter,
* view variables into a XML response. Makes generating simple
* XML responses very easy. You can omit the '_serialize' parameter,
* and use a normal view + layout as well.
*
* @param string $view The view being rendered.
@ -85,29 +99,53 @@ class XmlView extends View {
*/
public function render($view = null, $layout = null) {
if (isset($this->viewVars['_serialize'])) {
$serialize = $this->viewVars['_serialize'];
if (is_array($serialize)) {
$data = array('response' => array());
foreach ($serialize as $key) {
$data['response'][$key] = $this->viewVars[$key];
}
} else {
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
if (is_array($data) && Set::numeric(array_keys($data))) {
$data = array('response' => array($serialize => $data));
}
}
$content = Xml::fromArray($data)->asXML();
return $content;
return $this->_serialize($this->viewVars['_serialize']);
}
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
if (!$this->_helpersLoaded) {
$this->loadHelpers();
}
$content = $this->_render($viewFileName);
$this->Blocks->set('content', (string)$content);
return $content;
if ($view !== false && $this->_getViewFileName($view)) {
return parent::render($view, false);
}
}
/**
* Serialize view vars.
*
* ### Special parameters
* `_xmlOptions` You can set an array of custom options for Xml::fromArray() this way, e.g.
* 'format' as 'attributes' instead of 'tags'.
*
* @param array $serialize The viewVars that need to be serialized.
* @return string The serialized data
*/
protected function _serialize($serialize) {
$rootNode = isset($this->viewVars['_rootNode']) ? $this->viewVars['_rootNode'] : 'response';
if (is_array($serialize)) {
$data = array($rootNode => array());
foreach ($serialize as $alias => $key) {
if (is_numeric($alias)) {
$alias = $key;
}
$data[$rootNode][$alias] = $this->viewVars[$key];
}
} else {
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
if (is_array($data) && Hash::numeric(array_keys($data))) {
$data = array($rootNode => array($serialize => $data));
}
}
$options = array();
if (isset($this->viewVars['_xmlOptions'])) {
$options = $this->viewVars['_xmlOptions'];
}
if (Configure::read('debug')) {
$options['pretty'] = true;
}
if (isset($options['return']) && strtolower($options['return']) === 'domdocument') {
return Xml::fromArray($data, $options)->saveXML();
}
return Xml::fromArray($data, $options)->asXML();
}
}