Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Requested JsHelper buffer #156

Closed
wants to merge 20 commits into from

2 participants

@challet

hello CakePHP team.

While switching to the JsHelper, which is great to optimize the javascript code.
I had a problem with string bufferised from a requested action : the two requests (main one [http] and second one [requested] ) have each their buffer and it's not shared.
So some Js strings from requested ones are not in the main output.

I guess it's a known beahvior (each request have their own helpers). But if you consider to change this (at least for the Js Helper buffer), here is a patch to do this :

  • the "main" JsHelper register itself when beforeRender
  • the "requested" ones transmit their buffer to the "main" one, on their own afterRender

At the end, the "main" JsHelper collected all the buffers in one and can output it.

@challet

Sorry, only the last commit is to be taken into account : PathMotion@4d9afe8

I don't know how to put only this one here :/

@markstory markstory commented on the diff
cake/libs/model/datasources/datasource.php
@@ -223,7 +223,7 @@ class DataSource extends Object {
* @return array Array of sources available in this datasource.
* @access public
*/
- function listSources($data = null) {
+ function cachedListSources($data = null) {
@markstory Owner

Won't this break a pile of backwards compatibility?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@markstory
Owner

Seems like there are a bunch of other changes that are not part of the original pull request in here as well. Putting things on separate branches makes the pull requests work better.

@markstory markstory closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2011
  1. allow to disable cache gc

    Clément Hallet authored
  2. disabling gc doesn't require an explicit null value

    Clément Hallet authored
Commits on Mar 4, 2011
  1. handling bit type column

    Clément Hallet authored
  2. fix dbo_mysql.testQuoting test

    Clément Hallet authored
  3. add bit column related tests

    Clément Hallet authored
Commits on Mar 22, 2011
  1. Merge commit '1.3.8'

    Clément Hallet authored
  2. Merge commit '1.3.8' into 1.3

    Clément Hallet authored
  3. Merge branch '1.3'

    Clément Hallet authored
  4. Merge branch 'dbo-mysql-bit'

    Clément Hallet authored
Commits on Mar 31, 2011
  1. Merge branch 'upstream' into 1.3

    Clément Hallet authored
  2. use an other mehod name to get cached list sources

    Clément Hallet authored
  3. fix uppercase issue

    Clément Hallet authored
Commits on Jul 21, 2011
  1. Merge branch 'upstream' into 1.3

    Clément Hallet authored
  2. Merge branch '1.3'

    Clément Hallet authored
  3. Merge branch 'cached-list-sources'

    Clément Hallet authored
  4. add cache hash file engine

    Clément Hallet authored
  5. Merge branch 'hashfile-cacheengine'

    Clément Hallet authored
  6. fix wrong function name

    Clément Hallet authored
  7. Merge branch 'dbo-mysql-bit'

    Clément Hallet authored
Commits on Jul 22, 2011
  1. merge requested js buffer to the main one

    Clément Hallet authored
This page is out of date. Refresh to see the latest.
View
36 cake/libs/cache/hashfile.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ *
+ * @author Clément Hallet
+ * @link http://twitter.com/challet
+ * @license MIT license
+ *
+ */
+
+if (!class_exists('FileEngine')) {
+ require LIBS . 'cache/file.php';
+}
+
+class HashFileEngine extends FileEngine {
+
+ const HASH_DIGITS_NUMBER = 3;
+
+ function _setKey($key) {
+
+ parent::_setKey($key);
+
+ $intermediate_key = substr(md5($this->_File->name), 0, self::HASH_DIGITS_NUMBER);
+
+ $this->_File->Folder->create(
+ $this->_File->Folder->addPathElement(
+ $this->_File->Folder->pwd(),
+ $intermediate_key
+ )
+ );
+ $this->_File->Folder->cd($intermediate_key);
+ $this->_File->path = null;
+ $this->_File->pwd();
+
+ }
+
+}
View
2  cake/libs/model/datasources/datasource.php
@@ -223,7 +223,7 @@ function __construct($config = array()) {
* @return array Array of sources available in this datasource.
* @access public
*/
- function listSources($data = null) {
+ function cachedListSources($data = null) {
@markstory Owner

Won't this break a pile of backwards compatibility?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if ($this->cacheSources === false) {
return null;
}
View
4 cake/libs/model/datasources/dbo/dbo_mssql.php
@@ -201,7 +201,7 @@ function _execute($sql) {
* @return array Array of tablenames in the database
*/
function listSources() {
- $cache = parent::listSources();
+ $cache = $this->cachedListSources();
if ($cache != null) {
return $cache;
@@ -217,7 +217,7 @@ function listSources() {
$tables[] = $table[0]['TABLE_NAME'];
}
- parent::listSources($tables);
+ $this->cachedListSources($tables);
return $tables;
}
}
View
14 cake/libs/model/datasources/dbo/dbo_mysql.php
@@ -513,6 +513,9 @@ function column($real) {
if (strpos($col, 'enum') !== false) {
return "enum($vals)";
}
+ if (strpos($col, 'bit') !== false) {
+ return 'bit';
+ }
return 'text';
}
}
@@ -615,7 +618,7 @@ function _execute($sql) {
* @return array Array of tablenames in the database
*/
function listSources() {
- $cache = parent::listSources();
+ $cache = $this->cachedListSources();
if ($cache != null) {
return $cache;
}
@@ -629,7 +632,7 @@ function listSources() {
while ($line = mysql_fetch_row($result)) {
$tables[] = $line[0];
}
- parent::listSources($tables);
+ $this->cachedListSources($tables);
return $tables;
}
}
@@ -662,6 +665,13 @@ function value($data, $column = null, $safe = false) {
case 'boolean':
return $this->boolean((bool)$data);
break;
+ case 'bit':
+ if(is_int($data)) {
+ return "b'" . decbin($data) . "'";
+ } else {
+ return "b'" . $data . "'";
+ }
+ break;
case 'integer':
case 'float':
if ($data === '') {
View
4 cake/libs/model/datasources/dbo/dbo_mysqli.php
@@ -133,7 +133,7 @@ function _executeProcedure($sql) {
* @return array Array of tablenames in the database
*/
function listSources() {
- $cache = parent::listSources();
+ $cache = $this->cachedListSources();
if ($cache !== null) {
return $cache;
}
@@ -148,7 +148,7 @@ function listSources() {
while ($line = mysqli_fetch_row($result)) {
$tables[] = $line[0];
}
- parent::listSources($tables);
+ $this->cachedListSources($tables);
return $tables;
}
View
4 cake/libs/model/datasources/dbo/dbo_oracle.php
@@ -463,7 +463,7 @@ function createTrigger($table) {
* @access public
*/
function listSources() {
- $cache = parent::listSources();
+ $cache = $this->cachedListSources();
if ($cache != null) {
return $cache;
}
@@ -477,7 +477,7 @@ function listSources() {
while($r = $this->fetchRow()) {
$sources[] = strtolower($r[0]['name']);
}
- parent::listSources($sources);
+ $this->cachedListSources($sources);
return $sources;
}
View
4 cake/libs/model/datasources/dbo/dbo_postgres.php
@@ -173,7 +173,7 @@ function _execute($sql) {
* @return array Array of tablenames in the database
*/
function listSources() {
- $cache = parent::listSources();
+ $cache = $this->cachedListSources();
if ($cache != null) {
return $cache;
@@ -192,7 +192,7 @@ function listSources() {
$tables[] = $item[0]['name'];
}
- parent::listSources($tables);
+ $this->cachedListSources($tables);
return $tables;
}
}
View
4 cake/libs/model/datasources/dbo/dbo_sqlite.php
@@ -192,7 +192,7 @@ function execute($sql) {
* @return array Array of tablenames in the database
*/
function listSources() {
- $cache = parent::listSources();
+ $cache = $this->cachedListSources();
if ($cache != null) {
return $cache;
@@ -206,7 +206,7 @@ function listSources() {
foreach ($result as $table) {
$tables[] = $table[0]['name'];
}
- parent::listSources($tables);
+ $this->cachedListSources($tables);
return $tables;
}
return array();
View
13 cake/libs/view/helpers/js.php
@@ -445,6 +445,19 @@ function _getHtmlOptions($options, $additional = array()) {
}
return array($options, $htmlOptions);
}
+
+ function beforeRender() {
+ if(!isset($this->params['requested'])) {
+ ClassRegistry::addObject('main_js_helper', $this);
+ }
+ }
+
+ function afterRender() {
+ if(isset($this->params['requested']) && ClassRegistry::isKeySet('main_js_helper')) {
+ ClassRegistry::getObject('main_js_helper')->buffer(implode("\n", $this->getBuffer()));
+ }
+ }
+
}
/**
View
12 cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php
@@ -227,6 +227,14 @@ function testQuoting() {
$expected = "'00010010001'";
$result = $this->db->value('00010010001');
$this->assertEqual($expected, $result);
+
+ $expected = "b'00010010001'";
+ $result = $this->db->value('00010010001', 'bit');
+ $this->assertEqual($expected, $result);
+
+ $expected = "b'1101'";
+ $result = $this->db->value(13, 'bit');
+ $this->assertEqual($expected, $result);
}
/**
@@ -525,6 +533,10 @@ function testColumn() {
$result = $this->db->column('decimal(14,7) unsigned');
$expected = 'float';
$this->assertEqual($result, $expected);
+
+ $result = $this->db->column('bit(3)');
+ $expected = 'bit';
+ $this->assertEqual($result, $expected);
}
/**
Something went wrong with that request. Please try again.