mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Added reponse object as property of View class View::$response. Refactored HtmlHelper::media() a bit.
This commit is contained in:
parent
c57275636c
commit
c0690a3eff
4 changed files with 42 additions and 35 deletions
|
@ -324,6 +324,7 @@ object(View) {
|
||||||
hasRendered => false
|
hasRendered => false
|
||||||
uuids => array()
|
uuids => array()
|
||||||
request => null
|
request => null
|
||||||
|
response => object(CakeResponse) {}
|
||||||
elementCache => 'default'
|
elementCache => 'default'
|
||||||
int => (int) 2
|
int => (int) 2
|
||||||
float => (float) 1.333
|
float => (float) 1.333
|
||||||
|
|
|
@ -30,6 +30,13 @@ App::uses('CakeResponse', 'Network');
|
||||||
*/
|
*/
|
||||||
class HtmlHelper extends AppHelper {
|
class HtmlHelper extends AppHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the Response object
|
||||||
|
*
|
||||||
|
* @var CakeResponse
|
||||||
|
*/
|
||||||
|
public $response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* html tags used by this helper.
|
* html tags used by this helper.
|
||||||
*
|
*
|
||||||
|
@ -174,6 +181,11 @@ class HtmlHelper extends AppHelper {
|
||||||
*/
|
*/
|
||||||
public function __construct(View $View, $settings = array()) {
|
public function __construct(View $View, $settings = array()) {
|
||||||
parent::__construct($View, $settings);
|
parent::__construct($View, $settings);
|
||||||
|
if (is_object($this->_View->response)) {
|
||||||
|
$this->response = $this->_View->response;
|
||||||
|
} else {
|
||||||
|
$this->response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
|
||||||
|
}
|
||||||
if (!empty($settings['configFile'])) {
|
if (!empty($settings['configFile'])) {
|
||||||
$this->loadConfig($settings['configFile']);
|
$this->loadConfig($settings['configFile']);
|
||||||
}
|
}
|
||||||
|
@ -1029,46 +1041,39 @@ class HtmlHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($path)) {
|
if (is_array($path)) {
|
||||||
$response = null;
|
|
||||||
$sourceTags = '';
|
$sourceTags = '';
|
||||||
foreach ($path as $source) {
|
foreach ($path as &$source) {
|
||||||
if (is_string($source)) {
|
if (is_string($source)) {
|
||||||
$source = array(
|
$source = array(
|
||||||
'src' => $source,
|
'src' => $source,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!isset($source['type'])) {
|
if (!isset($source['type'])) {
|
||||||
if ($response === null) {
|
|
||||||
$response = new CakeResponse();
|
|
||||||
}
|
|
||||||
$ext = pathinfo($source['src'], PATHINFO_EXTENSION);
|
$ext = pathinfo($source['src'], PATHINFO_EXTENSION);
|
||||||
$source['type'] = $response->getMimeType($ext);
|
$source['type'] = $this->response->getMimeType($ext);
|
||||||
}
|
|
||||||
if ($type === null) {
|
|
||||||
if (preg_match('#^video/#', $source['type'])) {
|
|
||||||
$type = 'video';
|
|
||||||
} else {
|
|
||||||
$type = 'audio';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$source['src'] = $this->assetUrl($source['src'], $options);
|
$source['src'] = $this->assetUrl($source['src'], $options);
|
||||||
$sourceTags .= $this->useTag('tagselfclosing', 'source', $source);
|
$sourceTags .= $this->useTag('tagselfclosing', 'source', $source);
|
||||||
}
|
}
|
||||||
|
unset($source);
|
||||||
$options['text'] = $sourceTags . $options['text'];
|
$options['text'] = $sourceTags . $options['text'];
|
||||||
unset($options['fullBase']);
|
unset($options['fullBase']);
|
||||||
} else {
|
} else {
|
||||||
|
$options['src'] = $this->assetUrl($path, $options);
|
||||||
|
}
|
||||||
|
|
||||||
if ($type === null) {
|
if ($type === null) {
|
||||||
$response = new CakeResponse();
|
if (is_array($path)) {
|
||||||
$mimeType = $response->getMimeType(pathinfo($path, PATHINFO_EXTENSION));
|
$mimeType = $path[0]['type'];
|
||||||
|
} else {
|
||||||
|
$mimeType = $this->response->getMimeType(pathinfo($path, PATHINFO_EXTENSION));
|
||||||
|
}
|
||||||
if (preg_match('#^video/#', $mimeType)) {
|
if (preg_match('#^video/#', $mimeType)) {
|
||||||
$type = 'video';
|
$type = 'video';
|
||||||
} else {
|
} else {
|
||||||
$type = 'audio';
|
$type = 'audio';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$path = $this->assetUrl($path, $options);
|
|
||||||
$options['src'] = $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($options['poster'])) {
|
if (isset($options['poster'])) {
|
||||||
$options['poster'] = $this->assetUrl($options['poster'], array('pathPrefix' => IMAGES_URL) + $options);
|
$options['poster'] = $this->assetUrl($options['poster'], array('pathPrefix' => IMAGES_URL) + $options);
|
||||||
|
|
|
@ -63,13 +63,6 @@ class MediaView extends View {
|
||||||
*/
|
*/
|
||||||
protected $_compressionEnabled = false;
|
protected $_compressionEnabled = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Reference to the Response object responsible for sending the headers
|
|
||||||
*
|
|
||||||
* @var CakeResponse
|
|
||||||
*/
|
|
||||||
public $response = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
@ -77,11 +70,6 @@ class MediaView extends View {
|
||||||
*/
|
*/
|
||||||
public function __construct($controller = null) {
|
public function __construct($controller = null) {
|
||||||
parent::__construct($controller);
|
parent::__construct($controller);
|
||||||
if (is_object($controller) && isset($controller->response)) {
|
|
||||||
$this->response = $controller->response;
|
|
||||||
} else {
|
|
||||||
$this->response = new CakeResponse;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,6 +23,7 @@ App::uses('Router', 'Routing');
|
||||||
App::uses('ViewBlock', 'View');
|
App::uses('ViewBlock', 'View');
|
||||||
App::uses('CakeEvent', 'Event');
|
App::uses('CakeEvent', 'Event');
|
||||||
App::uses('CakeEventManager', 'Event');
|
App::uses('CakeEventManager', 'Event');
|
||||||
|
App::uses('CakeResponse', 'Network');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View, the V in the MVC triad. View interacts with Helpers and view variables passed
|
* View, the V in the MVC triad. View interacts with Helpers and view variables passed
|
||||||
|
@ -201,6 +202,13 @@ class View extends Object {
|
||||||
*/
|
*/
|
||||||
public $request;
|
public $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reference to the Response object
|
||||||
|
*
|
||||||
|
* @var CakeResponse
|
||||||
|
*/
|
||||||
|
public $response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Cache configuration View will use to store cached elements. Changing this will change
|
* The Cache configuration View will use to store cached elements. Changing this will change
|
||||||
* the default configuration elements are stored under. You can also choose a cache config
|
* the default configuration elements are stored under. You can also choose a cache config
|
||||||
|
@ -306,6 +314,11 @@ class View extends Object {
|
||||||
}
|
}
|
||||||
$this->_eventManager = $controller->getEventManager();
|
$this->_eventManager = $controller->getEventManager();
|
||||||
}
|
}
|
||||||
|
if (is_object($controller) && isset($controller->response)) {
|
||||||
|
$this->response = $controller->response;
|
||||||
|
} else {
|
||||||
|
$this->response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
|
||||||
|
}
|
||||||
$this->Helpers = new HelperCollection($this);
|
$this->Helpers = new HelperCollection($this);
|
||||||
$this->Blocks = new ViewBlock();
|
$this->Blocks = new ViewBlock();
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
Loading…
Add table
Reference in a new issue