Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requested JsHelper buffer #156

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions 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();

}

}
2 changes: 1 addition & 1 deletion cake/libs/model/datasources/datasource.php
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this break a pile of backwards compatibility?

if ($this->cacheSources === false) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions cake/libs/model/datasources/dbo/dbo_mssql.php
Expand Up @@ -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;
Expand All @@ -217,7 +217,7 @@ function listSources() {
$tables[] = $table[0]['TABLE_NAME'];
}

parent::listSources($tables);
$this->cachedListSources($tables);
return $tables;
}
}
Expand Down
14 changes: 12 additions & 2 deletions cake/libs/model/datasources/dbo/dbo_mysql.php
Expand Up @@ -513,6 +513,9 @@ function column($real) {
if (strpos($col, 'enum') !== false) {
return "enum($vals)";
}
if (strpos($col, 'bit') !== false) {
return 'bit';
}
return 'text';
}
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -629,7 +632,7 @@ function listSources() {
while ($line = mysql_fetch_row($result)) {
$tables[] = $line[0];
}
parent::listSources($tables);
$this->cachedListSources($tables);
return $tables;
}
}
Expand Down Expand Up @@ -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 === '') {
Expand Down
4 changes: 2 additions & 2 deletions cake/libs/model/datasources/dbo/dbo_mysqli.php
Expand Up @@ -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;
}
Expand All @@ -148,7 +148,7 @@ function listSources() {
while ($line = mysqli_fetch_row($result)) {
$tables[] = $line[0];
}
parent::listSources($tables);
$this->cachedListSources($tables);
return $tables;
}

Expand Down
4 changes: 2 additions & 2 deletions cake/libs/model/datasources/dbo/dbo_oracle.php
Expand Up @@ -463,7 +463,7 @@ function createTrigger($table) {
* @access public
*/
function listSources() {
$cache = parent::listSources();
$cache = $this->cachedListSources();
if ($cache != null) {
return $cache;
}
Expand All @@ -477,7 +477,7 @@ function listSources() {
while($r = $this->fetchRow()) {
$sources[] = strtolower($r[0]['name']);
}
parent::listSources($sources);
$this->cachedListSources($sources);
return $sources;
}

Expand Down
4 changes: 2 additions & 2 deletions cake/libs/model/datasources/dbo/dbo_postgres.php
Expand Up @@ -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;
Expand All @@ -192,7 +192,7 @@ function listSources() {
$tables[] = $item[0]['name'];
}

parent::listSources($tables);
$this->cachedListSources($tables);
return $tables;
}
}
Expand Down
4 changes: 2 additions & 2 deletions cake/libs/model/datasources/dbo/dbo_sqlite.php
Expand Up @@ -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;
Expand All @@ -206,7 +206,7 @@ function listSources() {
foreach ($result as $table) {
$tables[] = $table[0]['name'];
}
parent::listSources($tables);
$this->cachedListSources($tables);
return $tables;
}
return array();
Expand Down
13 changes: 13 additions & 0 deletions cake/libs/view/helpers/js.php
Expand Up @@ -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()));
}
}

}

/**
Expand Down
12 changes: 12 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down