Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closure now works with Curl. Url plugin has free. Bootstrap supports …

…caching. Exceptor uses vardump. Core has isRecord.
  • Loading branch information...
commit da14b3b68d99782d8cfcdc658f08e09fb9badfb7 1 parent 47be2a1
@balupton balupton authored
View
24 lib/Bal/Bootstrap.php
@@ -59,9 +59,7 @@ protected function _initMail ( ) {
$smtp_config = delve($applicationConfig, 'mail.transport.smtp.config');
if ( empty($smtp_config) )
$smtp_config = array();
-
- var_dump($smtp_host, $smtp_config);
-
+
# Apply
$Transport = new Zend_Mail_Transport_Smtp($smtp_host, $smtp_config);
Zend_Mail::setDefaultTransport($Transport);
@@ -411,6 +409,8 @@ protected function _initDoctrine ( ) {
$autoloader = $applicationConfig['data']['autoloader'];
$baseClassPrefix = $applicationConfig['data']['models']['options']['baseClassPrefix'];
$compile_use = $applicationConfig['data']['compile']['use'];
+ $cache_dsn = $applicationConfig['data']['cache_dsn'];
+ $cache_lifespan = $applicationConfig['data']['cache_lifespan'];
# Load
if ( !$compile_use ) {
@@ -468,6 +468,24 @@ protected function _initDoctrine ( ) {
# Get Manager
$Manager = Doctrine_Manager::getInstance();
+ # Use Cache?
+ if ( $cache_dsn ) {
+ # Open Cache Connection
+ $CacheConnection = $Manager->openConnection('sqlite:///'.CACHE_PATH.'/cache.db');
+
+ # Apply Query Cache
+ $QueryCacheDriver = new Doctrine_Cache_Db(array('connection' => $CacheConnection, 'tableName' =>'query'));
+ try { $QueryCacheDriver->createTable(); } catch ( Exception $Exception ) { }
+ $Manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $QueryCacheDriver);
+
+ # Apply Result Cache
+ $ResultCacheDriver = new Doctrine_Cache_Db(array('connection' => $CacheConnection, 'tableName' =>'result'));
+ try { $ResultCacheDriver->createTable(); } catch ( Exception $Exception ) { }
+ $Manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE, $ResultCacheDriver);
+ $Manager->setAttribute(Doctrine_Core::ATTR_RESULT_CACHE_LIFESPAN, $cache_lifespan);
+
+ }
+
# Apply Config
$Manager->setAttribute(Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_EMPTY_TO_NULL | Doctrine_Core::PORTABILITY_RTRIM);
$Manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);
View
46 lib/Bal/Controller/Plugin/Url.php
@@ -10,6 +10,7 @@ class Bal_Controller_Plugin_Url extends Zend_Controller_Plugin_Abstract {
protected $_encode = true;
protected $_url = null;
protected $_mode = null;
+ protected $_free = array();
/**
* A set of paths to look through for the file
@@ -85,7 +86,7 @@ static public function getInstance ( ) {
* @return boolean
*/
public function isCleared ( ) {
- return !$this->_params && !$this->_route && $this->_reset && $this->_encode && !$this->_url && !$this->_mode && empty($this->_paths);
+ return !$this->_params && !$this->_route && $this->_reset && $this->_encode && !$this->_url && !$this->_mode && empty($this->_paths) && empty($this->_free);
}
/**
@@ -93,6 +94,7 @@ public function isCleared ( ) {
* @return this
*/
public function clear ( ) {
+ $this->free();
$this->_params = array();
$this->_route = null;
$this->_reset = true;
@@ -279,6 +281,16 @@ public function hard ( $value ) {
}
/**
+ * Free anything that needs cleaning/freeling
+ */
+ public function free ( ) {
+ foreach ( $this->_free as $Item ) {
+ $Item->free(true);
+ }
+ $this->_free = array();
+ }
+
+ /**
* Will assemble the URL
* @return {string} url
*/
@@ -446,7 +458,7 @@ public function item ( $Item, $param = null, $error = true ) {
# Ensure Item
$code = $id = null;
if ( is_numeric($Item) ) {
- $id = $itItemem;
+ $id = $Item;
}
elseif ( is_string($Item) ) {
$code = $Item;
@@ -479,10 +491,9 @@ public function item ( $Item, $param = null, $error = true ) {
*/
public function content ( $input ) {
# Prepare
- $clean = false;
if ( is_string($input) ) {
$Item = $this->getItem('Content',$input);
- $clean = true;
+ $this->_free[] = $Item;
}
else {
$Item = $input;
@@ -497,9 +508,6 @@ public function content ( $input ) {
}
$result = $this->map($Item);
- # Clean
- if ( $clean ) $Item->free(true);
-
# Return result
return $result;
}
@@ -518,14 +526,13 @@ public function media ( $Item ) {
*/
public function file ( $Item ) {
# Prepare
- $clean = false;
if ( is_string($Item) && strstr($Item,'/') ) {
$url = $this->getFileUrl($Item);
}
else {
if ( is_string($Item) ) {
$Item = $this->getItem('File',$Item);
- $clean = true;
+ $this->_free[] = $Item;
}
$url = delve($Item,'url',false);
}
@@ -533,9 +540,6 @@ public function file ( $Item ) {
# Fetch
$result = $this->hard($url);
- # Clean
- if ( $clean ) $Item->free(true);
-
# Return result
return $result;
}
@@ -547,18 +551,14 @@ public function file ( $Item ) {
*/
public function user ( $Item ) {
# Prepare
- $clean = false;
if ( is_string($Item) ) {
$Item = $this->getItem('User',$Item);
- $clean = true;
+ $this->_free[] = $Item;
}
# Fetch
$result = $this->route('default')->action('user')->item($Item);
- # Clean
- if ( $clean ) $Item->free(true);
-
# Return result
return $result;
}
@@ -570,18 +570,14 @@ public function user ( $Item ) {
*/
public function userActivate ( $Item ) {
# Prepare
- $clean = false;
if ( is_string($Item) ) {
$Item = $this->getItem('User',$Item);
- $clean = true;
+ $this->_free[] = $Item;
}
# Fetch
$result = $this->route('default')->action('user-activate')->item($Item)->param('uid',delve($Item,'uid'));
- # Clean
- if ( $clean ) $Item->free(true);
-
# Return result
return $result;
}
@@ -593,18 +589,14 @@ public function userActivate ( $Item ) {
*/
public function message ( $Item ) {
# Prepare
- $clean = false;
if ( is_string($Item) ) {
$Item = $this->getItem('Message',$Item);
- $clean = true;
+ $this->_free[] = $Item;
}
# Fetch
$result = $this->route('default')->action('message')->item($Item);
- # Clean
- if ( $clean ) $Item->free(true);
-
# Return result
return $result;
}
View
14 lib/Bal/Doctrine/Core.php
@@ -761,6 +761,20 @@ public static function getRecord ( $tableComponentName, $record, array $options
/**
* Get a Record determined by the series of passed arguments
+ * @version 1.0, November 15, 2010
+ * @since 1.0, November 15, 2010
+ * @param string $tableComponentName The table/type of the record
+ * @param mixed $input Hopefully the Doctrine_Record we want to compare
+ * @return boolean
+ */
+ public static function isRecord ( $tableComponentName, $input ) {
+ $tableComponentName = self::getTableComponentName($tableComponentName);
+ $result = $input instanceof $tableComponentName;
+ return $result;
+ }
+
+ /**
+ * Get a Record determined by the series of passed arguments
* @version 1.1, April 12, 2010
* @param string $tableComponentName The table/type of the record
* @param array $inputs The input used to determine the record
View
7 lib/Bal/Exceptor.php
@@ -209,7 +209,12 @@ public function toArray() {
}
public function toString ( ) {
- return var_export($this->toArray(), true);
+ ob_start();
+ var_dump($this->toArray(true));
+ $result = ob_get_contents();
+ ob_end_clean();
+ return $result;
+ // return var_export($this->toArray(), true);
}
public function __toString ( ) {
View
88 lib/Bal/Service/GoogleClosure.php
@@ -67,6 +67,66 @@ protected function _getSourceGroups ( ) {
return $requests;
}
+ protected function _sendRequestFsock ( $data ) {
+ $fp = fsockopen('closure-compiler.appspot.com', 80, $errno, $errstr, 30);
+
+ if ( $fp ) {
+ fputs($fp, "POST /compile HTTP/1.1\r\n");
+ fputs($fp, "Host: closure-compiler.appspot.com\r\n");
+ fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
+ fputs($fp, "Content-length: ". strlen($data) ."\r\n");
+ fputs($fp, "Connection: close\r\n\r\n");
+ fputs($fp, $data);
+
+ $result = '';
+ while (!feof($fp)) {
+ $result .= fgets($fp, 128);
+ }
+
+ fclose($fp);
+ }
+ else {
+ throw new Exception('Could not connect to Google Closure Service: '.$errstr.' ('.$errno.')');
+ }
+
+ $data = substr($result, (strpos($result, "\r\n\r\n")+4));
+
+ if (strpos(strtolower($result), 'transfer-encoding: chunked') !== FALSE) {
+ $data = $this->_unchunk($data);
+ }
+
+ return $data;
+ }
+
+ protected function _sendRequestCurl ( $data ) {
+ # Prepare
+ $defaults = array(
+ CURLOPT_POST => 1,
+ CURLOPT_HEADER => 0,
+ CURLOPT_URL => 'closure-compiler.appspot.com/compile',
+ CURLOPT_FRESH_CONNECT => 1,
+ CURLOPT_RETURNTRANSFER => 1,
+ CURLOPT_FORBID_REUSE => 1,
+ CURLOPT_TIMEOUT => 30,
+ CURLOPT_POSTFIELDS => $data
+ );
+
+ # Open
+ $ch = curl_init();
+ curl_setopt_array($ch, $defaults);
+
+ # Perform Request
+ if ( !$result = curl_exec($ch) ) {
+ throw new Exception('Could not connect to Google Closure Service: '.curl_error($ch));
+ }
+
+ # Close Channel
+ curl_close($ch);
+
+ # Return result
+ return $result;
+ }
+
protected function _sendRequests ( ) {
$requests = array();
$groups = $this->_getSourceGroups();
@@ -74,33 +134,9 @@ protected function _sendRequests ( ) {
foreach ( $groups as $group ) {
$data = $this->_getParams($group);
- $referer = @$_SERVER['HTTP_REFERER'] or '';
- $fp = fsockopen('closure-compiler.appspot.com', 80) or die('Unable to open socket');;
-
- if ( $fp ) {
- fputs($fp, "POST /compile HTTP/1.1\r\n");
- fputs($fp, "Host: closure-compiler.appspot.com\r\n");
- fputs($fp, "Referer: $referer\r\n");
- fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
- fputs($fp, "Content-length: ". strlen($data) ."\r\n");
- fputs($fp, "Connection: close\r\n\r\n");
- fputs($fp, $data);
-
- $result = '';
- while (!feof($fp)) {
- $result .= fgets($fp, 128);
- }
+ // $referer = @$_SERVER['HTTP_REFERER'] or '';
- fclose($fp);
- }
- else {
- throw new Exception('Could not connect to Google Closure Service');
- }
-
- $data = substr($result, (strpos($result, "\r\n\r\n")+4));
- if (strpos(strtolower($result), 'transfer-encoding: chunked') !== FALSE) {
- $data = $this->_unchunk($data);
- }
+ $data = $this->_sendRequestCurl($data);
$requests[] = $data;
}
View
2  lib/core/functions/_general.funcs.php
@@ -16,7 +16,7 @@
* @author Benjamin "balupton" Lupton <contact@balupton.com> - {@link http://www.balupton.com/}
* @copyright Copyright (c) 2008, Benjamin Arthur Lupton - {@link http://www.balupton.com/}
* @license http://www.gnu.org/licenses/agpl.html GNU Affero General Public License
- */
+ */
require_once (dirname(__FILE__).DIRECTORY_SEPARATOR.'_general.funcs.php');
Please sign in to comment.
Something went wrong with that request. Please try again.