From fb1acc31d25d597aa7be3df4f0af6e0e56a269bc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 19 Aug 2011 21:39:38 -0500 Subject: [PATCH] more additions. --- laravel/db/connection.php | 8 ++++---- laravel/db/query.php | 13 ++++++++----- laravel/loader.php | 31 +++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/laravel/db/connection.php b/laravel/db/connection.php index 759e1b5e..c6a760fb 100644 --- a/laravel/db/connection.php +++ b/laravel/db/connection.php @@ -35,7 +35,7 @@ class Connection { * * @var Connector */ - protected $connector; + private $connector; /** * Create a new Connection instance. @@ -57,7 +57,7 @@ public function __construct($name, $config, Connector $connector) * * @return void */ - protected function connect() + public function connect() { $this->pdo = $this->connector->connect($this->config); } @@ -67,7 +67,7 @@ protected function connect() * * @return bool */ - protected function connected() + public function connected() { return ! is_null($this->pdo); } @@ -128,7 +128,7 @@ public function query($sql, $bindings = array()) * @param array $results * @return mixed */ - protected function execute(\PDOStatement $statement, $bindings) + private function execute(\PDOStatement $statement, $bindings) { $result = $statement->execute($bindings); diff --git a/laravel/db/query.php b/laravel/db/query.php index 7c48c923..e56bebc2 100644 --- a/laravel/db/query.php +++ b/laravel/db/query.php @@ -471,7 +471,13 @@ private function aggregate($aggregator, $column) { $this->select = 'SELECT '.$aggregator.'('.$this->wrap($column).') AS '.$this->wrap('aggregate'); - return $this->first()->aggregate; + $result = $this->connection->scalar($this->compile_select(), $this->bindings); + + // Reset the SELECT clause so more queries can be performed using the same instance. + // This is helpful for getting aggregates and then getting actual results. + $this->select = null; + + return $result; } /** @@ -656,10 +662,7 @@ private function wrap_alias($value) * * @return string */ - protected function wrapper() - { - return '"'; - } + protected function wrapper() { return '"'; } /** * Create query parameters from an array of values. diff --git a/laravel/loader.php b/laravel/loader.php index 6d37932e..ef48984a 100644 --- a/laravel/loader.php +++ b/laravel/loader.php @@ -33,7 +33,7 @@ public static function bootstrap($paths = array()) { static::$aliases = Config::get('aliases'); - foreach ($paths as $path) { static::register($path); } + foreach ($paths as $path) { static::register_path($path); } } /** @@ -113,15 +113,38 @@ private static function module_path($file) } /** - * Register a path with the auto-loader. After registering the path, it will be - * checked similarly to the models and libraries directories. + * Register a path with the auto-loader. + * + * After registering the path, it will be checked similarly to the models and libraries directories. * * @param string $path * @return void */ - public static function register($path) + public static function register_path($path) { static::$paths[] = rtrim($path, '/').'/'; } + /** + * Register an alias with the auto-loader. + * + * @param array $alias + * @return void + */ + public static function register_alias($alias) + { + static::$aliases = array_merge(static::$aliases, $alias); + } + + /** + * Remove an alias from the auto-loader's list of aliases. + * + * @param string $alias + * @return void + */ + public static function forget_alias($alias) + { + unset(static::$aliases[$alias]); + } + } \ No newline at end of file