Commit 1aa86d07 authored by Taylor Otwell's avatar Taylor Otwell

improved performance. added support for database ports.

parent fef18099
<?php
return array(
/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| Here, you can specify any class aliases that you would like registered
| when Laravel loads. Aliases are lazy-loaded, so add as many as you want.
|
| We have already setup a few to make your life easier.
|
*/
'Auth' => 'System\\Auth',
'Benchmark' => 'System\\Benchmark',
'Cache' => 'System\\Cache',
'Config' => 'System\\Config',
'Cookie' => 'System\\Cookie',
'Crypt' => 'System\\Crypt',
'Date' => 'System\\Date',
'DB' => 'System\\DB',
'Download' => 'System\\Download',
'Eloquent' => 'System\\DB\\Eloquent',
'File' => 'System\\File',
'Form' => 'System\\Form',
'Hash' => 'System\\Hash',
'HTML' => 'System\\HTML',
'Inflector' => 'System\\Inflector',
'Input' => 'System\\Input',
'Lang' => 'System\\Lang',
'Log' => 'System\\Log',
'URL' => 'System\\URL',
'Redirect' => 'System\\Redirect',
'Request' => 'System\\Request',
'Response' => 'System\\Response',
'Session' => 'System\\Session',
'Str' => 'System\\Str',
'Text' => 'System\\Text',
'Validator' => 'System\\Validator',
'View' => 'System\\View',
);
\ No newline at end of file
......@@ -80,46 +80,4 @@ return array(
'key' => '',
/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| Here, you can specify any class aliases that you would like registered
| when Laravel loads. Aliases are lazy-loaded, so add as many as you want.
|
| We have already setup a few to make your life easier.
|
*/
'aliases' => array(
'Auth' => 'System\\Auth',
'Benchmark' => 'System\\Benchmark',
'Cache' => 'System\\Cache',
'Config' => 'System\\Config',
'Cookie' => 'System\\Cookie',
'Crypt' => 'System\\Crypt',
'Date' => 'System\\Date',
'DB' => 'System\\DB',
'Download' => 'System\\Download',
'Eloquent' => 'System\\DB\\Eloquent',
'File' => 'System\\File',
'Form' => 'System\\Form',
'Hash' => 'System\\Hash',
'HTML' => 'System\\HTML',
'Inflector' => 'System\\Inflector',
'Input' => 'System\\Input',
'Lang' => 'System\\Lang',
'Log' => 'System\\Log',
'URL' => 'System\\URL',
'Redirect' => 'System\\Redirect',
'Request' => 'System\\Request',
'Response' => 'System\\Response',
'Session' => 'System\\Session',
'Str' => 'System\\Str',
'Text' => 'System\\Text',
'Validator' => 'System\\Validator',
'View' => 'System\\View',
),
);
\ No newline at end of file
......@@ -4,74 +4,76 @@
<meta charset="utf-8">
<title>Welcome To Laravel!</title>
<link href="http://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<link href="http://fonts.googleapis.com/css?family=Quattrocento&amp;v1" rel="stylesheet" type="text/css" media="all" />
<link href="http://fonts.googleapis.com/css?family=Ubuntu&amp;v1" rel="stylesheet" type="text/css" media="all" />
<link href="http://fonts.googleapis.com/css?family=Lobster+Two&amp;v1" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
body {
background-color: #fff;
font-family: 'Ubuntu', sans-serif;
font-size: 16px;
color: #3f3f3f;
}
h1 {
font-size: 40px;
background-color: #eee;
color: #6d6d6d;
margin: 0 0 10px 0;
text-shadow: 1px 1px #000;
}
font-family: 'Ubuntu';
font-size: 15px;
}
a {
color: #000;
color: #7089b3;
font-weight: bold;
text-decoration: none;
}
#wrapper {
width: 740px;
h1.laravel {
font-family: 'Lobster Two', Helvetica, serif;
font-size: 60px;
margin: 0 0 15px -10px;
padding: 0;
text-shadow: -1px 1px 1px #fff;
}
#content {
padding: 10px 10px 10px 10px;
background-color: #eee;
h2 {
font-family: 'Quattrocento', serif;
font-size: 30px;
margin: 30px 0 0 0;
padding: 0;
text-shadow: -1px 1px 1px #fff;
}
p {
margin: 10px 0 0 0;
line-height: 25px;
}
#wrapper {
background-color: #fff;
border-radius: 10px;
margin: 0 auto;
padding: 10px;
width: 80%;
}
#footer {
font-size: 12px;
padding-top: 10px;
text-align: right;
#wrapper h2:first-of-type {
margin-top: 0;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$(window).resize(function(){
$('#wrapper').css({
position:'absolute',
left: ($(window).width() - $('#wrapper').outerWidth()) / 2,
top: ($(window).height() - $('#wrapper').outerHeight()) / 3
});
});
$(window).resize();
});
</script>
#header {
margin: 0 auto;
margin-bottom: 15px;
margin-top: 20px;
width: 80%;
}
</style>
</head>
<body>
<div id="wrapper">
<h1>Laravel</h1>
<div id="content">
You have successfully installed Laravel.
<div id="header">
<h1 class="laravel">Laravel</h1>
</div>
<br /><br />
<div id="wrapper">
<h2>Installation Complete!</h2>
Perhaps you would like to <a href="http://laravel.com/docs">peruse the documentation</a> or <a href="http://github.com/taylorotwell/laravel">contribute on GitHub</a>?
</div>
<p>Ready to dig in? Start building your application in the <strong>application/routes.php</strong> file.</p>
<div id="footer">
<?php echo Benchmark::memory(); ?>mb &middot; <?php echo Benchmark::check('laravel'); ?>ms
</div>
</div>
<p>Need to learn more? Peruse our <a href="http://laravel.com/docs">wonderful documentation</a>.</p>
</div>
</body>
</html>
\ No newline at end of file
......@@ -29,21 +29,15 @@ define('PACKAGE_PATH', APP_PATH.'packages/');
define('EXT', '.php');
// --------------------------------------------------------------
// Load the configuration, error, and string classes.
// Load the configuration class.
// --------------------------------------------------------------
require SYS_PATH.'config'.EXT;
require SYS_PATH.'str'.EXT;
// --------------------------------------------------------------
// Register the auto-loader.
// --------------------------------------------------------------
spl_autoload_register(require SYS_PATH.'loader'.EXT);
// --------------------------------------------------------------
// Set the Laravel starting time in the Benchmark class.
// --------------------------------------------------------------
System\Benchmark::$marks['laravel'] = LARAVEL_START;
// --------------------------------------------------------------
// Set the error reporting level.
// --------------------------------------------------------------
......
......@@ -66,11 +66,11 @@ class DB {
//
// For all other statements, return a boolean.
// ---------------------------------------------------
if (strpos(Str::upper($sql), 'SELECT') === 0)
if (strpos(strtoupper($sql), 'SELECT') === 0)
{
return $query->fetchAll(\PDO::FETCH_CLASS, 'stdClass');
}
elseif (strpos(Str::upper($sql), 'UPDATE') === 0 or strpos(Str::upper($sql), 'DELETE') === 0)
elseif (strpos(strtoupper($sql), 'UPDATE') === 0 or strpos(strtoupper($sql), 'DELETE') === 0)
{
return $query->rowCount();
}
......@@ -105,4 +105,22 @@ class DB {
return static::connection($connection)->getAttribute(\PDO::ATTR_DRIVER_NAME);
}
/**
* Get the table prefix for a database connection.
*
* @param string $connection
* @return string
*/
public static function prefix($connection = null)
{
$connections = Config::get('db.connections');
if (is_null($connection))
{
$connection = Config::get('db.default');
}
return (array_key_exists('prefix', $connections[$connection])) ? $connections[$connection]['prefix'] : '';
}
}
\ No newline at end of file
......@@ -51,8 +51,21 @@ class Connector {
// -----------------------------------------------------
elseif ($config->driver == 'mysql' or $config->driver == 'pgsql')
{
$connection = new \PDO($config->driver.':host='.$config->host.';dbname='.$config->database, $config->username, $config->password, static::$options);
// -----------------------------------------------------
// Build the PDO connection DSN.
// -----------------------------------------------------
$dsn = $config->driver.':host='.$config->host.';dbname='.$config->database;
if (isset($config->port))
{
$dsn .= ';port='.$config->port;
}
$connection = new \PDO($dsn, $config->username, $config->password, static::$options);
// -----------------------------------------------------
// Set the appropriate character set for the datbase.
// -----------------------------------------------------
if (isset($config->charset))
{
$connection->prepare("SET NAMES '".$config->charset."'")->execute();
......
<?php namespace System\DB;
use System\Str;
use System\Config;
use System\Inflector;
abstract class Eloquent {
......@@ -102,7 +103,7 @@ abstract class Eloquent {
return $class::$table;
}
return Str::lower(Inflector::plural($class));
return strtolower(Inflector::plural($class));
}
/**
......@@ -213,7 +214,7 @@ abstract class Eloquent {
// For example, the foreign key for a User model would
// be user_id. Photo would be photo_id, etc.
// -----------------------------------------------------
$this->relating_key = (is_null($foreign_key)) ? Str::lower(get_class($this)).'_id' : $foreign_key;
$this->relating_key = (is_null($foreign_key)) ? strtolower(get_class($this)).'_id' : $foreign_key;
return static::make($model)->where($this->relating_key, '=', $this->id);
}
......@@ -276,7 +277,7 @@ abstract class Eloquent {
sort($models);
$this->relating_table = Str::lower($models[0].'_'.$models[1]);
$this->relating_table = strtolower($models[0].'_'.$models[1]);
}
// -----------------------------------------------------
......@@ -286,11 +287,11 @@ abstract class Eloquent {
//
// This is the same convention as has_one and has_many.
// -----------------------------------------------------
$this->relating_key = Str::lower(get_class($this)).'_id';
$this->relating_key = strtolower(get_class($this)).'_id';
return static::make($model)
->select(static::table($model).'.*')
->join($this->relating_table, static::table($model).'.id', '=', $this->relating_table.'.'.Str::lower($model).'_id')
->join($this->relating_table, static::table($model).'.id', '=', $this->relating_table.'.'.strtolower($model).'_id')
->where($this->relating_table.'.'.$this->relating_key, '=', $this->id);
}
......
......@@ -326,7 +326,7 @@ class Query {
*/
public function order_by($column, $direction)
{
$this->orderings[] = $this->wrap($column).' '.Str::upper($direction);
$this->orderings[] = $this->wrap($column).' '.strtoupper($direction);
return $this;
}
......@@ -516,7 +516,7 @@ class Query {
// ---------------------------------------------------------
if (in_array($method, array('count', 'min', 'max', 'avg', 'sum')))
{
return ($method == 'count') ? $this->aggregate(Str::upper($method), '*') : $this->aggregate(Str::upper($method), $parameters[0]);
return ($method == 'count') ? $this->aggregate(strtoupper($method), '*') : $this->aggregate(strtoupper($method), $parameters[0]);
}
throw new \Exception("Method [$method] is not defined on the Query class.");
......
......@@ -55,7 +55,7 @@ class Dynamic {
}
else
{
$connector = trim(Str::upper($segment), '_');
$connector = trim(strtoupper($segment), '_');
}
}
......
......@@ -126,7 +126,7 @@ class Inflector {
return static::$plural_cache[$value];
}
if (in_array(Str::lower($value), static::$uncountable))
if (in_array(strtolower($value), static::$uncountable))
{
return static::$plural_cache[$value] = $value;
}
......@@ -165,7 +165,7 @@ class Inflector {
return static::$singular_cache[$value];
}
if (in_array(Str::lower($value), static::$uncountable))
if (in_array(strtolower($value), static::$uncountable))
{
return static::$singular_cache[$value] = $value;
}
......
......@@ -4,16 +4,16 @@
* This function is registered on the auto-loader stack by the front controller.
*/
return function($class) {
// ----------------------------------------------------------
// Replace namespace slashes with directory slashes.
// ----------------------------------------------------------
$file = System\Str::lower(str_replace('\\', '/', $class));
$file = strtolower(str_replace('\\', '/', $class));
// ----------------------------------------------------------
// Should the class be aliased?
// ----------------------------------------------------------
if (array_key_exists($class, $aliases = System\Config::get('application.aliases')))
if (array_key_exists($class, $aliases = System\Config::get('aliases')))
{
return class_alias($aliases[$class], $class);
}
......
......@@ -71,7 +71,7 @@ class Request {
// If the requests is to the root of the application, we
// always return a single forward slash.
// -------------------------------------------------------
return ($uri == '') ? '/' : Str::lower($uri);
return ($uri == '') ? '/' : strtolower($uri);
}
/**
......@@ -136,7 +136,7 @@ class Request {
*/
public static function is_ajax()
{
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and Str::lower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
}
/**
......
<?php namespace System\Validation;
class Error_Collector {
/**
* All of the error messages.
*
* @var array
*/
public $messages;
/**
* Create a new Error Collector instance.
*
* @return void
*/
public function __construct($messages = array())
{
$this->messages = $messages;
}
/**
* Add an error message to the collector.
*
* Duplicate messages will not be added.
*
* @param string $attribute
* @param string $message
* @return void
*/
public function add($attribute, $message)
{
// -------------------------------------------------------------
// Make sure the error message is not duplicated.
//
// For example, the Nullable rules can add a "required" message.
// If the same message has already been added we don't want to
// add it again.
// -------------------------------------------------------------
if ( ! array_key_exists($attribute, $this->messages) or ! is_array($this->messages[$attribute]) or ! in_array($message, $this->messages[$attribute]))
{
$this->messages[$attribute][] = $message;
}
}
/**
* Determine if errors exist for an attribute.
*
* @param string $attribute
* @return bool
*/
public function has($attribute)
{
return $this->first($attribute) !== '';
}
/**
* Get the first error message for an attribute.
*
* @param string $attribute
* @return string
*/
public function first($attribute)
{
return (count($messages = $this->get($attribute)) > 0) ? $messages[0] : '';
}
/**
* Get all of the error messages for an attribute.
*
* If no attribute is specified, all of the error messages will be returned.
*
* @param string $attribute
* @param string $format
* @return array
*/
public function get($attribute = null, $format = ':message')
{
if (is_null($attribute))
{
return $this->all($format);
}
return (array_key_exists($attribute, $this->messages)) ? $this->format($this->messages[$attribute], $format) : array();
}
/**
* Get all of the error messages.
*
* @param string $format
* @return array
*/
public function all($format = ':message')
{
$all = array();
// ---------------------------------------------------------
// Add each error message to the array of messages. Each
// messages will have the specified format applied to it.
// ---------------------------------------------------------
foreach ($this->messages as $messages)
{
$all = array_merge($all, $this->format($messages, $format));
}
return $all;
}
/**
* Format an array of messages.
*
* @param array $messages
* @param string $format
* @return array
*/
private function format($messages, $format)
{
array_walk($messages, function(&$message, $key) use ($format) { $message = str_replace(':message', $message, $format); });
return $messages;
}
}
\ No newline at end of file
......@@ -47,7 +47,7 @@ class Message {
{
$class = explode('\\', get_class($rule));
$rule->error = Str::lower(end($class));
$rule->error = strtolower(end($class));
}
return (is_null($rule->message)) ? Lang::line('validation.'.$rule->error)->get() : $rule->message;
......
......@@ -40,11 +40,11 @@ abstract class Rule {
/**
* Run the validation rule.
*
* @param array $attributes
* @param array $errors
* @param array $attributes
* @param Error_Collector $errors
* @return void
*/
public function validate($attributes, &$errors)
public function validate($attributes, $errors)
{
foreach ($this->attributes as $attribute)
{
......@@ -52,19 +52,7 @@ abstract class Rule {
if ( ! $this->check($attribute, $attributes))
{
$message = Message::get($this, $attribute);
// -------------------------------------------------------------
// Make sure the error message is not duplicated.
//
// For example, the Nullable rules can add a "required" message.
// If the same message has already been added we don't want to
// add it again.
// -------------------------------------------------------------
if ( ! array_key_exists($attribute, $errors) or ! is_array($errors[$attribute]) or ! in_array($message, $errors[$attribute]))
{
$errors[$attribute][] = $message;
}
$errors->add($attribute, Message::get($this, $attribute));
}
}
}
......
......@@ -10,9 +10,9 @@ class Validator {
public $attributes;
/**
* The validation errors
* The validation error collector.
*
* @var array
* @var Error_Collector
*/
public $errors;
......@@ -31,6 +31,8 @@ class Validator {
*/
public function __construct($target = array())
{
$this->errors = new Validation\Error_Collector;
// ---------------------------------------------------------
// If the source is an Eloquent model, use the model's
// attributes as the validation attributes.
......@@ -56,7 +58,7 @@ class Validator {
*/
public function is_valid()
{
$this->errors = array();
$this->errors->messages = array();
foreach ($this->rules as $rule)
{
......@@ -67,7 +69,7 @@ class Validator {
$rule->validate($this->attributes, $this->errors);
}
return count($this->errors) == 0;
return count($this->errors->messages) == 0;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment