Proin id libero molestie ante faucibus tincidunt sit amet ac nisi. Mauris feugiat ultricies magna eu laoreet. Nunc tincidunt tempus leo vitae gravida.
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | @yield('content')
60 |
61 |
62 | @yield('sidebar')
63 |
64 |
65 |
66 |
67 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/artisan:
--------------------------------------------------------------------------------
1 |
8 | * @link http://laravel.com
9 | */
10 |
11 | // --------------------------------------------------------------
12 | // Set the core Laravel path constants.
13 | // --------------------------------------------------------------
14 | require 'paths.php';
15 |
16 | // --------------------------------------------------------------
17 | // Bootstrap the Laravel core.
18 | // --------------------------------------------------------------
19 | require path('sys').'core.php';
20 |
21 | // --------------------------------------------------------------
22 | // Launch the Laravel "Artisan" CLI.
23 | // --------------------------------------------------------------
24 | require path('sys').'cli/artisan'.EXT;
--------------------------------------------------------------------------------
/bundles/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/howframework/Laravel/a1a0e4e07b17cb40c265a60cbdbc661c0fe296ff/bundles/.gitignore
--------------------------------------------------------------------------------
/bundles/docs/routes.php:
--------------------------------------------------------------------------------
1 | with('sidebar', document('contents'));
46 | });
47 |
48 | /**
49 | * Handle the documentation homepage.
50 | *
51 | * This page contains the "introduction" to Laravel.
52 | */
53 | Route::get('(:bundle)', function()
54 | {
55 | return View::make('docs::page')->with('content', document('home'));
56 | });
57 |
58 | /**
59 | * Handle documentation routes for sections and pages.
60 | *
61 | * @param string $section
62 | * @param string $page
63 | * @return mixed
64 | */
65 | Route::get('(:bundle)/(:any)/(:any?)', function($section, $page = null)
66 | {
67 | $file = rtrim(implode('/', func_get_args()), '/');
68 |
69 | // If no page was specified, but a "home" page exists for the section,
70 | // we'll set the file to the home page so that the proper page is
71 | // display back out to the client for the requested doc page.
72 | if (is_null($page) and document_exists($file.'/home'))
73 | {
74 | $file .= '/home';
75 | }
76 |
77 | if (document_exists($file))
78 | {
79 | return View::make('docs::page')->with('content', document($file));
80 | }
81 | else
82 | {
83 | return Response::error('404');
84 | }
85 | });
--------------------------------------------------------------------------------
/bundles/docs/views/page.blade.php:
--------------------------------------------------------------------------------
1 | @layout('docs::template')
2 |
3 | @section('content')
4 | {{ $content }}
5 | @endsection
--------------------------------------------------------------------------------
/bundles/docs/views/template.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Laravel: A Framework For Web Artisans
7 |
8 |
9 | {{ HTML::style('laravel/css/style.css') }}
10 | {{ HTML::style('laravel/js/modernizr-2.5.3.min.js') }}
11 |
12 |
13 |
14 |
15 |
Laravel
16 |
A Framework For Web Artisans
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 | @yield('content')
27 |
28 |
29 |
30 | {{ HTML::script('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js') }}
31 | {{ HTML::script('laravel/js/prettify.js') }}
32 | {{ HTML::script('laravel/js/scroll.js') }}
33 |
34 |
--------------------------------------------------------------------------------
/laravel/auth.php:
--------------------------------------------------------------------------------
1 |
81 | * // Call the "user" method on the default auth driver
82 | * $user = Auth::user();
83 | *
84 | * // Call the "check" method on the default auth driver
85 | * Auth::check();
86 | *
87 | */
88 | public static function __callStatic($method, $parameters)
89 | {
90 | return call_user_func_array(array(static::driver(), $method), $parameters);
91 | }
92 |
93 | }
--------------------------------------------------------------------------------
/laravel/auth/drivers/eloquent.php:
--------------------------------------------------------------------------------
1 | model()->find($id);
18 | }
19 | }
20 |
21 | /**
22 | * Attempt to log a user into the application.
23 | *
24 | * @param array $arguments
25 | * @return void
26 | */
27 | public function attempt($arguments = array())
28 | {
29 | $username = Config::get('auth.username');
30 |
31 | $user = $this->model()->where($username, '=', $arguments['username'])->first();
32 |
33 | // This driver uses a basic username and password authentication scheme
34 | // so if the credentials match what is in the database we will just
35 | // log the user into the application and remember them if asked.
36 | $password = $arguments['password'];
37 |
38 | if ( ! is_null($user) and Hash::check($password, $user->password))
39 | {
40 | return $this->login($user->id, array_get($arguments, 'remember'));
41 | }
42 |
43 | return false;
44 | }
45 |
46 | /**
47 | * Get a fresh model instance.
48 | *
49 | * @return Eloquent
50 | */
51 | protected function model()
52 | {
53 | $model = Config::get('auth.model');
54 |
55 | return new $model;
56 | }
57 |
58 | }
--------------------------------------------------------------------------------
/laravel/auth/drivers/fluent.php:
--------------------------------------------------------------------------------
1 | find($id);
22 | }
23 | }
24 |
25 | /**
26 | * Attempt to log a user into the application.
27 | *
28 | * @param array $arguments
29 | * @return void
30 | */
31 | public function attempt($arguments = array())
32 | {
33 | $user = $this->get_user($arguments['username']);
34 |
35 | // This driver uses a basic username and password authentication scheme
36 | // so if the credentials mmatch what is in the database we will just
37 | // log the user into the application and remember them if asked.
38 | $password = $arguments['password'];
39 |
40 | if ( ! is_null($user) and Hash::check($password, $user->password))
41 | {
42 | return $this->login($user->id, array_get($arguments, 'remember'));
43 | }
44 |
45 | return false;
46 | }
47 |
48 | /**
49 | * Get the user from the database table by username.
50 | *
51 | * @param mixed $value
52 | * @return mixed
53 | */
54 | protected function get_user($value)
55 | {
56 | $table = Config::get('auth.table');
57 |
58 | $username = Config::get('auth.username');
59 |
60 | return DB::table($table)->where($username, '=', $value)->first();
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/laravel/cache/drivers/apc.php:
--------------------------------------------------------------------------------
1 | key = $key;
21 | }
22 |
23 | /**
24 | * Determine if an item exists in the cache.
25 | *
26 | * @param string $key
27 | * @return bool
28 | */
29 | public function has($key)
30 | {
31 | return ( ! is_null($this->get($key)));
32 | }
33 |
34 | /**
35 | * Retrieve an item from the cache driver.
36 | *
37 | * @param string $key
38 | * @return mixed
39 | */
40 | protected function retrieve($key)
41 | {
42 | if (($cache = apc_fetch($this->key.$key)) !== false)
43 | {
44 | return $cache;
45 | }
46 | }
47 |
48 | /**
49 | * Write an item to the cache for a given number of minutes.
50 | *
51 | *
52 | * // Put an item in the cache for 15 minutes
53 | * Cache::put('name', 'Taylor', 15);
54 | *
55 | *
56 | * @param string $key
57 | * @param mixed $value
58 | * @param int $minutes
59 | * @return void
60 | */
61 | public function put($key, $value, $minutes)
62 | {
63 | apc_store($this->key.$key, $value, $minutes * 60);
64 | }
65 |
66 | /**
67 | * Write an item to the cache that lasts forever.
68 | *
69 | * @param string $key
70 | * @param mixed $value
71 | * @return void
72 | */
73 | public function forever($key, $value)
74 | {
75 | return $this->put($key, $value, 0);
76 | }
77 |
78 | /**
79 | * Delete an item from the cache.
80 | *
81 | * @param string $key
82 | * @return void
83 | */
84 | public function forget($key)
85 | {
86 | apc_delete($this->key.$key);
87 | }
88 |
89 | }
--------------------------------------------------------------------------------
/laravel/cache/drivers/file.php:
--------------------------------------------------------------------------------
1 | path = $path;
21 | }
22 |
23 | /**
24 | * Determine if an item exists in the cache.
25 | *
26 | * @param string $key
27 | * @return bool
28 | */
29 | public function has($key)
30 | {
31 | return ( ! is_null($this->get($key)));
32 | }
33 |
34 | /**
35 | * Retrieve an item from the cache driver.
36 | *
37 | * @param string $key
38 | * @return mixed
39 | */
40 | protected function retrieve($key)
41 | {
42 | if ( ! file_exists($this->path.$key)) return null;
43 |
44 | // File based caches store have the expiration timestamp stored in
45 | // UNIX format prepended to their contents. We'll compare the
46 | // timestamp to the current time when we read the file.
47 | if (time() >= substr($cache = file_get_contents($this->path.$key), 0, 10))
48 | {
49 | return $this->forget($key);
50 | }
51 |
52 | return unserialize(substr($cache, 10));
53 | }
54 |
55 | /**
56 | * Write an item to the cache for a given number of minutes.
57 | *
58 | *
59 | * // Put an item in the cache for 15 minutes
60 | * Cache::put('name', 'Taylor', 15);
61 | *
62 | *
63 | * @param string $key
64 | * @param mixed $value
65 | * @param int $minutes
66 | * @return void
67 | */
68 | public function put($key, $value, $minutes)
69 | {
70 | if ($minutes <= 0) return;
71 |
72 | $value = $this->expiration($minutes).serialize($value);
73 |
74 | file_put_contents($this->path.$key, $value, LOCK_EX);
75 | }
76 |
77 | /**
78 | * Write an item to the cache for five years.
79 | *
80 | * @param string $key
81 | * @param mixed $value
82 | * @return void
83 | */
84 | public function forever($key, $value)
85 | {
86 | return $this->put($key, $value, 2628000);
87 | }
88 |
89 | /**
90 | * Delete an item from the cache.
91 | *
92 | * @param string $key
93 | * @return void
94 | */
95 | public function forget($key)
96 | {
97 | if (file_exists($this->path.$key)) @unlink($this->path.$key);
98 | }
99 |
100 | }
--------------------------------------------------------------------------------
/laravel/cache/drivers/redis.php:
--------------------------------------------------------------------------------
1 | redis = $redis;
21 | }
22 |
23 | /**
24 | * Determine if an item exists in the cache.
25 | *
26 | * @param string $key
27 | * @return bool
28 | */
29 | public function has($key)
30 | {
31 | return ( ! is_null($this->redis->get($key)));
32 | }
33 |
34 | /**
35 | * Retrieve an item from the cache driver.
36 | *
37 | * @param string $key
38 | * @return mixed
39 | */
40 | protected function retrieve($key)
41 | {
42 | if ( ! is_null($cache = $this->redis->get($key)))
43 | {
44 | return unserialize($cache);
45 | }
46 | }
47 |
48 | /**
49 | * Write an item to the cache for a given number of minutes.
50 | *
51 | *
52 | * // Put an item in the cache for 15 minutes
53 | * Cache::put('name', 'Taylor', 15);
54 | *
55 | *
56 | * @param string $key
57 | * @param mixed $value
58 | * @param int $minutes
59 | * @return void
60 | */
61 | public function put($key, $value, $minutes)
62 | {
63 | $this->forever($key, $value);
64 |
65 | $this->redis->expire($key, $minutes * 60);
66 | }
67 |
68 | /**
69 | * Write an item to the cache that lasts forever.
70 | *
71 | * @param string $key
72 | * @param mixed $value
73 | * @return void
74 | */
75 | public function forever($key, $value)
76 | {
77 | $this->redis->set($key, serialize($value));
78 | }
79 |
80 | /**
81 | * Delete an item from the cache.
82 | *
83 | * @param string $key
84 | * @return void
85 | */
86 | public function forget($key)
87 | {
88 | $this->redis->del($key);
89 | }
90 |
91 | }
--------------------------------------------------------------------------------
/laravel/cli/artisan.php:
--------------------------------------------------------------------------------
1 | getMessage();
47 | }
48 |
49 | echo PHP_EOL;
--------------------------------------------------------------------------------
/laravel/cli/tasks/bundle/providers/github.php:
--------------------------------------------------------------------------------
1 | download($url));
34 |
35 | $zip = new \ZipArchive;
36 |
37 | $zip->open($target);
38 |
39 | // Once we have the Zip archive, we can open it and extract it
40 | // into the working directory. By convention, we expect the
41 | // archive to contain one root directory with the bundle.
42 | mkdir($work.'zip');
43 |
44 | $zip->extractTo($work.'zip');
45 |
46 | $latest = File::latest($work.'zip')->getRealPath();
47 |
48 | @chmod($latest, 0777);
49 |
50 | // Once we have the latest modified directory, we should be
51 | // able to move its contents over into the bundles folder
52 | // so the bundle will be usable by the develoepr.
53 | File::mvdir($latest, $path);
54 |
55 | File::rmdir($work.'zip');
56 |
57 | $zip->close();
58 | @unlink($target);
59 | }
60 |
61 | /**
62 | * Download a remote zip archive from a URL.
63 | *
64 | * @param string $url
65 | * @return string
66 | */
67 | protected function download($url)
68 | {
69 | $remote = file_get_contents($url);
70 |
71 | // If we were unable to download the zip archive correctly
72 | // we'll bomb out since we don't want to extract the last
73 | // zip that was put in the storage directory.
74 | if ($remote === false)
75 | {
76 | throw new \Exception("Error downloading bundle [{$bundle}].");
77 | }
78 |
79 | return $remote;
80 | }
81 |
82 | }
--------------------------------------------------------------------------------
/laravel/cli/tasks/bundle/publisher.php:
--------------------------------------------------------------------------------
1 | move($path.'public', path('public').'bundles'.DS.$bundle);
27 |
28 | echo "Assets published for bundle [$bundle].".PHP_EOL;
29 | }
30 |
31 | /**
32 | * Copy the contents of a bundle's assets to the public folder.
33 | *
34 | * @param string $source
35 | * @param string $destination
36 | * @return void
37 | */
38 | protected function move($source, $destination)
39 | {
40 | File::cpdir($source, $destination);
41 | }
42 |
43 | /**
44 | * Get the "to" location of the bundle's assets.
45 | *
46 | * @param string $bundle
47 | * @return string
48 | */
49 | protected function to($bundle)
50 | {
51 | return path('public').'bundles'.DS.$bundle.DS;
52 | }
53 |
54 | /**
55 | * Get the "from" location of the bundle's assets.
56 | *
57 | * @param string $bundle
58 | * @return string
59 | */
60 | protected function from($bundle)
61 | {
62 | return Bundle::path($bundle).'public';
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/laravel/cli/tasks/bundle/repository.php:
--------------------------------------------------------------------------------
1 | api.$bundle);
25 |
26 | return json_decode($bundle, true);
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/laravel/cli/tasks/key.php:
--------------------------------------------------------------------------------
1 | path = path('app').'config/application'.EXT;
23 | }
24 |
25 | /**
26 | * Generate a random key for the application.
27 | *
28 | * @param array $arguments
29 | * @return void
30 | */
31 | public function generate($arguments = array())
32 | {
33 | // By default the Crypter class uses AES-256 encryption which uses
34 | // a 32 byte input vector, so that is the length of string we will
35 | // generate for the application token unless another length is
36 | // specified through the CLI.
37 | $key = Str::random(array_get($arguments, 0, 32));
38 |
39 | $config = File::get($this->path);
40 |
41 | $config = str_replace("'key' => '',", "'key' => '{$key}',", $config, $count);
42 |
43 | File::put($this->path, $config);
44 |
45 | if ($count > 0)
46 | {
47 | echo "Configuration updated with secure key!";
48 | }
49 | else
50 | {
51 | echo "An application key already exists!";
52 | }
53 |
54 | echo PHP_EOL;
55 | }
56 |
57 | }
--------------------------------------------------------------------------------
/laravel/cli/tasks/migrate/database.php:
--------------------------------------------------------------------------------
1 | table()->insert(compact('bundle', 'name', 'batch'));
19 | }
20 |
21 | /**
22 | * Delete a row from the migration table.
23 | *
24 | * @param string $bundle
25 | * @param string $name
26 | * @return void
27 | */
28 | public function delete($bundle, $name)
29 | {
30 | $this->table()->where_bundle_and_name($bundle, $name)->delete();
31 | }
32 |
33 | /**
34 | * Return an array of the last batch of migrations.
35 | *
36 | * @return array
37 | */
38 | public function last()
39 | {
40 | $table = $this->table();
41 |
42 | // First we need to grab the last batch ID from the migration table,
43 | // as this will allow us to grab the lastest batch of migrations
44 | // that need to be run for a rollback command.
45 | $id = $this->batch();
46 |
47 | // Once we have the batch ID, we will pull all of the rows for that
48 | // batch. Then we can feed the results into the resolve method to
49 | // get the migration instances for the command.
50 | return $table->where_batch($id)->order_by('name', 'desc')->get();
51 | }
52 |
53 | /**
54 | * Get all of the migrations that have run for a bundle.
55 | *
56 | * @param string $bundle
57 | * @return array
58 | */
59 | public function ran($bundle)
60 | {
61 | return $this->table()->where_bundle($bundle)->lists('name');
62 | }
63 |
64 | /**
65 | * Get the maximum batch ID from the migration table.
66 | *
67 | * @return int
68 | */
69 | public function batch()
70 | {
71 | return $this->table()->max('batch');
72 | }
73 |
74 | /**
75 | * Get a database query instance for the migration table.
76 | *
77 | * @return Laravel\Database\Query
78 | */
79 | protected function table()
80 | {
81 | return DB::connection(Request::server('cli.db'))->table('laravel_migrations');
82 | }
83 |
84 | }
--------------------------------------------------------------------------------
/laravel/cli/tasks/migrate/stub.php:
--------------------------------------------------------------------------------
1 | route();
30 |
31 | echo PHP_EOL;
32 | }
33 |
34 | /**
35 | * Dump the results of the currently established route.
36 | *
37 | * @return void
38 | */
39 | protected function route()
40 | {
41 | // We'll call the router using the method and URI specified by
42 | // the developer on the CLI. If a route is found, we will not
43 | // run the filters, but simply dump the result.
44 | $route = Router::route(Request::method(), URI::current());
45 |
46 | if ( ! is_null($route))
47 | {
48 | var_dump($route->response());
49 | }
50 | else
51 | {
52 | echo '404: Not Found';
53 | }
54 | }
55 |
56 | }
--------------------------------------------------------------------------------
/laravel/cli/tasks/session/manager.php:
--------------------------------------------------------------------------------
1 | generate();
28 |
29 | // To create the session table, we will actually create a database
30 | // migration and then run it. This allows the application to stay
31 | // portable through the framework's migrations system.
32 | $migration = $migrator->make(array('create_session_table'));
33 |
34 | $stub = path('sys').'cli/tasks/session/migration'.EXT;
35 |
36 | File::put($migration, File::get($stub));
37 |
38 | // By default no session driver is set within the configuration.
39 | // Since the developer is requesting that the session table be
40 | // created on the database, we'll set it.
41 | $this->driver('database');
42 |
43 | echo PHP_EOL;
44 |
45 | $migrator->run();
46 | }
47 |
48 | /**
49 | * Sweep the expired sessions from storage.
50 | *
51 | * @param array $arguments
52 | * @return void
53 | */
54 | public function sweep($arguments = array())
55 | {
56 | $driver = Session::factory(Config::get('session.driver'));
57 |
58 | // If the driver implements the "Sweeper" interface, we know that it
59 | // can sweep expired sessions from storage. Not all drivers need be
60 | // sweepers since they do their own.
61 | if ($driver instanceof Sweeper)
62 | {
63 | $lifetime = Config::get('session.lifetime');
64 |
65 | $driver->sweep(time() - ($lifetime * 60));
66 | }
67 |
68 | echo "The session table has been swept!";
69 | }
70 |
71 | /**
72 | * Set the session driver to a given value.
73 | *
74 | * @param string $driver
75 | * @return void
76 | */
77 | protected function driver($driver)
78 | {
79 | // By default no session driver is set within the configuration.
80 | // This method will replace the empty driver option with the
81 | // driver specified in the arguments.
82 | $config = File::get(path('app').'config/session'.EXT);
83 |
84 | $config = str_replace(
85 | "'driver' => '',",
86 | "'driver' => 'database',",
87 | $config
88 | );
89 |
90 | File::put(path('app').'config/session'.EXT, $config);
91 | }
92 |
93 | }
--------------------------------------------------------------------------------
/laravel/cli/tasks/session/migration.php:
--------------------------------------------------------------------------------
1 | create();
15 |
16 | // The session table consists simply of an ID, a UNIX timestamp to
17 | // indicate the expiration time, and a blob field which will hold
18 | // the serialized form of the session payload.
19 | $table->string('id')->length(40)->primary('session_primary');
20 |
21 | $table->integer('last_activity');
22 |
23 | $table->text('data');
24 | });
25 | }
26 |
27 | /**
28 | * Revert the changes to the database.
29 | *
30 | * @return void
31 | */
32 | public function down()
33 | {
34 | Schema::table(Config::get('session.table'), function($table)
35 | {
36 | $table->drop();
37 | });
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/laravel/cli/tasks/task.php:
--------------------------------------------------------------------------------
1 |
8 | * @link http://laravel.com
9 | */
10 |
11 | // --------------------------------------------------------------
12 | // Define the directory separator for the environment.
13 | // --------------------------------------------------------------
14 | define('DS', DIRECTORY_SEPARATOR);
15 |
16 | // --------------------------------------------------------------
17 | // Set the core Laravel path constants.
18 | // --------------------------------------------------------------
19 | require 'paths.php';
20 |
21 | // --------------------------------------------------------------
22 | // Override the application paths when testing the core.
23 | // --------------------------------------------------------------
24 | $config = file_get_contents('phpunit.xml');
25 |
26 | if (strpos($config, 'laravel-tests') !== false)
27 | {
28 | $path = path('bundle').'laravel-tests'.DS;
29 |
30 | set_path('app', $path.'application'.DS);
31 |
32 | set_path('bundle', $path.'bundles'.DS);
33 |
34 | set_path('storage', $path.'storage'.DS);
35 | }
36 |
37 | // --------------------------------------------------------------
38 | // Bootstrap the Laravel core.
39 | // --------------------------------------------------------------
40 | require path('sys').'core.php';
41 |
42 | // --------------------------------------------------------------
43 | // Start the default bundle.
44 | // --------------------------------------------------------------
45 | Laravel\Bundle::start(DEFAULT_BUNDLE);
--------------------------------------------------------------------------------
/laravel/cli/tasks/test/stub.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 | {{directory}}
7 |
8 |
9 |
--------------------------------------------------------------------------------
/laravel/database/connectors/connector.php:
--------------------------------------------------------------------------------
1 | PDO::CASE_LOWER,
12 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
13 | PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
14 | PDO::ATTR_STRINGIFY_FETCHES => false,
15 | PDO::ATTR_EMULATE_PREPARES => false,
16 | );
17 |
18 | /**
19 | * Establish a PDO database connection.
20 | *
21 | * @param array $config
22 | * @return PDO
23 | */
24 | abstract public function connect($config);
25 |
26 | /**
27 | * Get the PDO connection options for the configuration.
28 | *
29 | * Developer specified options will override the default connection options.
30 | *
31 | * @param array $config
32 | * @return array
33 | */
34 | protected function options($config)
35 | {
36 | $options = (isset($config['options'])) ? $config['options'] : array();
37 |
38 | return $this->options + $options;
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/laravel/database/connectors/mysql.php:
--------------------------------------------------------------------------------
1 | options($config));
34 |
35 | // If a character set has been specified, we'll execute a query against
36 | // the database to set the correct character set. By default, this is
37 | // set to UTF-8 which should be fine for most scenarios.
38 | if (isset($config['charset']))
39 | {
40 | $connection->prepare("SET NAMES '{$config['charset']}'")->execute();
41 | }
42 |
43 | return $connection;
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/laravel/database/connectors/postgres.php:
--------------------------------------------------------------------------------
1 | options($config));
26 |
27 | // If a character set has been specified, we'll execute a query against
28 | // the database to set the correct character set. By default, this is
29 | // set to UTF-8 which should be fine for most scenarios.
30 | if (isset($config['charset']))
31 | {
32 | $connection->prepare("SET NAMES '{$config['charset']}'")->execute();
33 | }
34 |
35 | return $connection;
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/laravel/database/connectors/sqlite.php:
--------------------------------------------------------------------------------
1 | options($config);
14 |
15 | // SQLite provides supported for "in-memory" databases, which exist only for
16 | // lifetime of the request. Any given in-memory database may only have one
17 | // PDO connection open to it at a time. These are mainly for tests.
18 | if ($config['database'] == ':memory:')
19 | {
20 | return new PDO('sqlite::memory:', null, null, $options);
21 | }
22 |
23 | $path = path('storage').'database'.DS.$config['database'].'.sqlite';
24 |
25 | return new PDO('sqlite:'.$path, null, null, $options);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/laravel/database/connectors/sqlserver.php:
--------------------------------------------------------------------------------
1 | PDO::CASE_LOWER,
12 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
13 | PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
14 | PDO::ATTR_STRINGIFY_FETCHES => false,
15 | );
16 |
17 | /**
18 | * Establish a PDO database connection.
19 | *
20 | * @param array $config
21 | * @return PDO
22 | */
23 | public function connect($config)
24 | {
25 | extract($config);
26 |
27 | // Format the SQL Server connection string. This connection string format can
28 | // also be used to connect to Azure SQL Server databases. The port is defined
29 | // directly after the server name, so we'll create that first.
30 | $port = (isset($port)) ? ','.$port : '';
31 |
32 | $dsn = "sqlsrv:Server={$host}{$port};Database={$database}";
33 |
34 | return new PDO($dsn, $username, $password, $this->options($config));
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/laravel/database/eloquent/pivot.php:
--------------------------------------------------------------------------------
1 | pivot_table = $table;
29 | $this->connection = $connection;
30 |
31 | parent::__construct(array(), true);
32 | }
33 |
34 | /**
35 | * Get the name of the pivot table.
36 | *
37 | * @return string
38 | */
39 | public function table()
40 | {
41 | return $this->pivot_table;
42 | }
43 |
44 | /**
45 | * Get the connection used by the pivot table.
46 | *
47 | * @return string
48 | */
49 | public function connection()
50 | {
51 | return $this->connection;
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/laravel/database/eloquent/relationships/has_one.php:
--------------------------------------------------------------------------------
1 | relationships[$relationship] = null;
27 | }
28 | }
29 |
30 | /**
31 | * Match eagerly loaded child models to their parent models.
32 | *
33 | * @param array $parents
34 | * @param array $children
35 | * @return void
36 | */
37 | public function match($relationship, &$parents, $children)
38 | {
39 | $foreign = $this->foreign_key();
40 |
41 | foreach ($parents as &$parent)
42 | {
43 | $matching = array_first($children, function($k, $v) use ($parent, $foreign)
44 | {
45 | return $v->$foreign == $parent->get_key();
46 | });
47 |
48 | $parent->relationships[$relationship] = $matching;
49 | }
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/laravel/database/eloquent/relationships/has_one_or_many.php:
--------------------------------------------------------------------------------
1 | attributes : $attributes;
16 |
17 | $attributes[$this->foreign_key()] = $this->base->get_key();
18 |
19 | return $this->model->create($attributes);
20 | }
21 |
22 | /**
23 | * Update a record for the association.
24 | *
25 | * @param array $attributes
26 | * @return bool
27 | */
28 | public function update(array $attributes)
29 | {
30 | if ($this->model->timestamps())
31 | {
32 | $attributes['updated_at'] = new \DateTime;
33 | }
34 |
35 | return $this->table->update($attributes);
36 | }
37 |
38 | /**
39 | * Set the proper constraints on the relationship table.
40 | *
41 | * @return void
42 | */
43 | protected function constrain()
44 | {
45 | $this->table->where($this->foreign_key(), '=', $this->base->get_key());
46 | }
47 |
48 | /**
49 | * Set the proper constraints on the relationship table for an eager load.
50 | *
51 | * @param array $results
52 | * @return void
53 | */
54 | public function eagerly_constrain($results)
55 | {
56 | $this->table->where_in($this->foreign_key(), $this->keys($results));
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/laravel/database/exception.php:
--------------------------------------------------------------------------------
1 | inner = $inner;
23 |
24 | $this->setMessage($sql, $bindings);
25 | }
26 |
27 | /**
28 | * Set the exception message to include the SQL and bindings.
29 | *
30 | * @param string $sql
31 | * @param array $bindings
32 | * @return void
33 | */
34 | protected function setMessage($sql, $bindings)
35 | {
36 | $this->message = $this->inner->getMessage();
37 |
38 | $this->message .= "\n\nSQL: ".$sql."\n\nBindings: ".var_export($bindings, true);
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/laravel/database/expression.php:
--------------------------------------------------------------------------------
1 | value = $value;
21 | }
22 |
23 | /**
24 | * Get the string value of the database expression.
25 | *
26 | * @return string
27 | */
28 | public function get()
29 | {
30 | return $this->value;
31 | }
32 |
33 | /**
34 | * Get the string value of the database expression.
35 | *
36 | * @return string
37 | */
38 | public function __toString()
39 | {
40 | return $this->get();
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/laravel/database/query/grammars/mysql.php:
--------------------------------------------------------------------------------
1 | orderings as $ordering)
17 | {
18 | $sql[] = $this->wrap($ordering['column']).' COLLATE NOCASE '.strtoupper($ordering['direction']);
19 | }
20 |
21 | return 'ORDER BY '.implode(', ', $sql);
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/laravel/database/query/join.php:
--------------------------------------------------------------------------------
1 | type = $type;
36 | $this->table = $table;
37 | }
38 |
39 | /**
40 | * Add an ON clause to the join.
41 | *
42 | * @param string $column1
43 | * @param string $operator
44 | * @param string $column2
45 | * @param string $connector
46 | * @return Join
47 | */
48 | public function on($column1, $operator, $column2, $connector = 'AND')
49 | {
50 | $this->clauses[] = compact('column1', 'operator', 'column2', 'connector');
51 |
52 | return $this;
53 | }
54 |
55 | /**
56 | * Add an OR ON clause to the join.
57 | *
58 | * @param string $column1
59 | * @param string $operator
60 | * @param string $column2
61 | * @return Join
62 | */
63 | public function or_on($column1, $operator, $column2)
64 | {
65 | return $this->on($column1, $operator, $column2, 'OR');
66 | }
67 |
68 | }
--------------------------------------------------------------------------------
/laravel/database/schema/grammars/grammar.php:
--------------------------------------------------------------------------------
1 | name;
18 |
19 | // We need to wrap both of the table names in quoted identifiers to protect
20 | // against any possible keyword collisions, both the table on which the
21 | // command is being executed and the referenced table are wrapped.
22 | $table = $this->wrap($table);
23 |
24 | $on = $this->wrap($command->on);
25 |
26 | // Next we need to columnize both the command table's columns as well as
27 | // the columns referenced by the foreign key. We'll cast the referenced
28 | // columns to an array since they aren't by the fluent command.
29 | $foreign = $this->columnize($command->columns);
30 |
31 | $referenced = $this->columnize((array) $command->references);
32 |
33 | $sql = "ALTER TABLE $table ADD CONSTRAINT $name ";
34 |
35 | $sql .= "FOREIGN KEY ($foreign) REFERENCES $on ($referenced)";
36 |
37 | // Finally we will check for any "on delete" or "on update" options for
38 | // the foreign key. These control the behavior of the constraint when
39 | // an update or delete statement is run against the record.
40 | if ( ! is_null($command->on_delete))
41 | {
42 | $sql .= " ON DELETE {$command->on_delete}";
43 | }
44 |
45 | if ( ! is_null($command->on_update))
46 | {
47 | $sql .= " ON UPDATE {$command->on_update}";
48 | }
49 |
50 | return $sql;
51 | }
52 |
53 | /**
54 | * Drop a constraint from the table.
55 | *
56 | * @param Table $table
57 | * @param Fluent $fluent
58 | * @return string
59 | */
60 | protected function drop_constraint(Table $table, Fluent $command)
61 | {
62 | return "ALTER TABLE ".$this->wrap($table)." DROP CONSTRAINT ".$command->name;
63 | }
64 |
65 | /**
66 | * Wrap a value in keyword identifiers.
67 | *
68 | * @param Table|string $value
69 | * @return string
70 | */
71 | public function wrap($value)
72 | {
73 | // This method is primarily for convenience so we can just pass a
74 | // column or table instance into the wrap method without sending
75 | // in the name each time we need to wrap one of these objects.
76 | if ($value instanceof Table)
77 | {
78 | return $this->wrap_table($value->name);
79 | }
80 | elseif ($value instanceof Fluent)
81 | {
82 | $value = $value->name;
83 | }
84 |
85 | return parent::wrap($value);
86 | }
87 |
88 | /**
89 | * Get the appropriate data type definition for the column.
90 | *
91 | * @param Fluent $column
92 | * @return string
93 | */
94 | protected function type(Fluent $column)
95 | {
96 | return $this->{'type_'.$column->type}($column);
97 | }
98 |
99 | }
--------------------------------------------------------------------------------
/laravel/documentation/artisan/tasks.md:
--------------------------------------------------------------------------------
1 | # Tasks
2 |
3 | ## Contents
4 |
5 | - [The Basics](#the-basics)
6 | - [Creating & Running Tasks](#creating-tasks)
7 | - [Bundle Tasks](#bundle-tasks)
8 | - [CLI Options](#cli-options)
9 |
10 |
11 | ## The Basics
12 |
13 | Laravel's command-line tool is called Artisan. Artisan can be used to run "tasks" such as migrations, cronjobs, unit-tests, or anything that want.
14 |
15 |
16 | ## Creating & Running Tasks
17 |
18 | To create a task create a new class in your **application/tasks** directory. The class name should be suffixed with "_Task", and should at least have a "run" method, like this:
19 |
20 | #### Creating a task class:
21 |
22 | class Notify_Task {
23 |
24 | public function run($arguments)
25 | {
26 | // Do awesome notifying...
27 | }
28 |
29 | }
30 |
31 | Now you can call the "run" method of your task via the command-line. You can even pass arguments:
32 |
33 | #### Calling a task from the command line:
34 |
35 | php artisan notify
36 |
37 | #### Calling a task and passing arguments:
38 |
39 | php artisan notify taylor
40 |
41 | Remember, you can call specific methods on your task, so, let's add an "urgent" method to the notify task:
42 |
43 | #### Adding a method to the task:
44 |
45 | class Notify_Task {
46 |
47 | public function run($arguments)
48 | {
49 | // Do awesome notifying...
50 | }
51 |
52 | public function urgent($arguments)
53 | {
54 | // This is urgent!
55 | }
56 |
57 | }
58 |
59 | Now we can call our "urgent" method:
60 |
61 | #### Calling a specific method on a task:
62 |
63 | php artisan notify:urgent
64 |
65 |
66 | ## Bundle Tasks
67 |
68 | To create a task for your bundle just prefix the bundle name to the class name of your task. So, if your bundle was named "admin", a task might look like this:
69 |
70 | #### Creating a task class that belongs to a bundle:
71 |
72 | class Admin_Generate_Task {
73 |
74 | public function run($arguments)
75 | {
76 | // Generate the admin!
77 | }
78 |
79 | }
80 |
81 | To run your task just use the usual Laravel double-colon syntax to indicate the bundle:
82 |
83 | #### Running a task belonging to a bundle:
84 |
85 | php artisan admin::generate
86 |
87 | #### Running a specific method on a task belonging to a bundle:
88 |
89 | php artisan admin::generate:list
90 |
91 |
92 | ## CLI Options
93 |
94 | #### Setting the Laravel environment:
95 |
96 | php artisan foo --env=local
97 |
98 | #### Setting the default database connection:
99 |
100 | php artisan foo --database=sqlite
--------------------------------------------------------------------------------
/laravel/documentation/cache/usage.md:
--------------------------------------------------------------------------------
1 | # Cache Usage
2 |
3 | ## Contents
4 |
5 | - [Storing Items](#put)
6 | - [Retrieving Items](#get)
7 | - [Removing Items](#forget)
8 |
9 |
10 | ## Storing Items
11 |
12 | Storing items in the cache is simple. Simply call the **put** method on the Cache class:
13 |
14 | Cache::put('name', 'Taylor', 10);
15 |
16 | The first parameter is the **key** to the cache item. You will use this key to retrieve the item from the cache. The second parameter is the **value** of the item. The third parameter is the number of **minutes** you want the item to be cached.
17 |
18 | You may also cache something "forever" if you do not want the cache to expire:
19 |
20 | Cache::forever('name', 'Taylor');
21 |
22 | > **Note:** It is not necessary to serialize objects when storing them in the cache.
23 |
24 |
25 | ## Retrieving Items
26 |
27 | Retrieving items from the cache is even more simple than storing them. It is done using the **get** method. Just mention the key of the item you wish to retrieve:
28 |
29 | $name = Cache::get('name');
30 |
31 | By default, NULL will be returned if the cached item has expired or does not exist. However, you may pass a different default value as a second parameter to the method:
32 |
33 | $name = Cache::get('name', 'Fred');
34 |
35 | Now, "Fred" will be returned if the "name" cache item has expired or does not exist.
36 |
37 | What if you need a value from your database if a cache item doesn't exist? The solution is simple. You can pass a closure into the **get** method as a default value. The closure will only be executed if the cached item doesn't exist:
38 |
39 | $users = Cache::get('count', function() {return DB::table('users')->count();});
40 |
41 | Let's take this example a step further. Imagine you want to retrieve the number of registered users for your application; however, if the value is not cached, you want to store the default value in the cache using the **remember** method:
42 |
43 | $users = Cache::remember('count', function() {return DB::table('users')->count();}, 5);
44 |
45 | Let's talk through that example. If the **count** item exists in the cache, it will be returned. If it doesn't exist, the result of the closure will be stored in the cache for five minutes **and** be returned by the method. Slick, huh?
46 |
47 | Laravel even gives you a simple way to determine if a cached item exists using the **has** method:
48 |
49 | if (Cache::has('name'))
50 | {
51 | $name = Cache::get('name');
52 | }
53 |
54 |
55 | ## Removing Items
56 |
57 | Need to get rid of a cached item? No problem. Just mention the name of the item to the **forget** method:
58 |
59 | Cache::forget('name');
--------------------------------------------------------------------------------
/laravel/documentation/config.md:
--------------------------------------------------------------------------------
1 | # Runtime Configuration
2 |
3 | ## Contents
4 |
5 | - [The Basics](#the-basics)
6 | - [Retrieving Options](#retrieving-options)
7 | - [Setting Options](#setting-options)
8 |
9 |
10 | ## The Basics
11 |
12 | Sometimes you may need to get and set configuration options at runtime. For this you'll use the **Config** class, which utilizes Laravel's "dot" syntax for accessing configuration files and items.
13 |
14 |
15 | ## Retrieving Options
16 |
17 | #### Retrieve a configuration option:
18 |
19 | $value = Config::get('application.url');
20 |
21 | #### Return a default value if the option doesn't exist:
22 |
23 | $value = Config::get('application.timezone', 'UTC');
24 |
25 | #### Retrieve an entire configuration array:
26 |
27 | $options = Config::get('database');
28 |
29 |
30 | ## Setting Options
31 |
32 | #### Set a configuration option:
33 |
34 | Config::set('cache.driver', 'apc');
--------------------------------------------------------------------------------
/laravel/documentation/database/config.md:
--------------------------------------------------------------------------------
1 | # Database Configuration
2 |
3 | ## Contents
4 |
5 | - [Quick Start Using SQLite](#quick)
6 | - [Configuring Other Databases](#server)
7 | - [Setting The Default Connection Name](#default)
8 |
9 | Laravel supports the following databases out of the box:
10 |
11 | - MySQL
12 | - PostgreSQL
13 | - SQLite
14 | - SQL Server
15 |
16 | All of the database configuration options live in the **application/config/database.php** file.
17 |
18 |
19 | ## Quick Start Using SQLite
20 |
21 | [SQLite](http://sqlite.org) is an awesome, zero-configuration database system. By default, Laravel is configured to use a SQLite database. Really, you don't have to change anything. Just drop a SQLite database named **application.sqlite** into the **application/storage/database** directory. You're done.
22 |
23 | Of course, if you want to name your database something besides "application", you can modify the database option in the SQLite section of the **application/config/database.php** file:
24 |
25 | 'sqlite' => array(
26 | 'driver' => 'sqlite',
27 | 'database' => 'your_database_name',
28 | )
29 |
30 | If your application receives less than 100,000 hits per day, SQLite should be suitable for production use in your application. Otherwise, consider using MySQL or PostgreSQL.
31 |
32 | > **Note:** Need a good SQLite manager? Check out this [Firefox extension](https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/).
33 |
34 |
35 | ## Configuring Other Databases
36 |
37 | If you are using MySQL, SQL Server, or PostgreSQL, you will need to edit the configuration options in **application/config/database.php**. In the configuration file you can find sample configurations for each of these systems. Just change the options as necessary for your server and set the default connection name.
38 |
39 |
40 | ## Setting The Default Connection Name
41 |
42 | As you have probably noticed, each database connection defined in the **application/config/database.php** file has a name. By default, there are three connections defined: **sqlite**, **mysql**, **sqlsrv**, and **pgsql**. You are free to change these connection names. The default connection can be specified via the **default** option:
43 |
44 | 'default' => 'sqlite';
45 |
46 | The default connection will always be used by the [fluent query builder](/docs/database/fluent). If you need to change the default connection during a request, use the **Config::set** method.
--------------------------------------------------------------------------------
/laravel/documentation/database/migrations.md:
--------------------------------------------------------------------------------
1 | # Migrations
2 |
3 | ## Contents
4 |
5 | - [The Basics](#the-basics)
6 | - [Prepping Your Database](#prepping-your-database)
7 | - [Creating Migrations](#creating-migrations)
8 | - [Running Migrations](#running-migrations)
9 | - [Rolling Back](#rolling-back)
10 |
11 |
12 | ## The Basics
13 |
14 | Think of migrations as a type of version control for your database. Let's say your working on a team, and you all have local databases for development. Good ole' Eric makes a change to the database and checks in his code that uses the new column. You pull in the code, and your application breaks because you don't have the new column. What do you do? Migrations are the answer. Let's dig in deeper to find out how to use them!
15 |
16 |
17 | ## Prepping Your Database
18 |
19 | Before you can run migrations, we need to do some work on your database. Laravel uses a special table to keep track of which migrations have already run. To create this table, just use the Artisan command-line:
20 |
21 | **Creating the Laravel migrations table:**
22 |
23 | php artisan migrate:install
24 |
25 |
26 | ## Creating Migrations
27 |
28 | You can easily create migrations through Laravel's "Artisan" CLI. It looks like this:
29 |
30 | **Creating a migration**
31 |
32 | php artisan migrate:make create_users_table
33 |
34 | Now, check your **application/migrations** folder. You should see your brand new migration! Notice that it also contains a timestamp. This allows Laravel to run your migrations in the correct order.
35 |
36 | You may also create migrations for a bundle.
37 |
38 | **Creating a migration for a bundle:**
39 |
40 | php artisan migrate:make bundle::create_users_table
41 |
42 | *Further Reading:*
43 |
44 | - [Schema Builder](/docs/database/schema)
45 |
46 |
47 | ## Running Migrations
48 |
49 | **Running all outstanding migrations in application and bundles:**
50 |
51 | php artisan migrate
52 |
53 | **Running all outstanding migrations in the application:**
54 |
55 | php artisan migrate application
56 |
57 | **Running all outstanding migrations in a bundle:**
58 |
59 | php artisan migrate bundle
60 |
61 |
62 | ## Rolling Back
63 |
64 | When you roll back a migration, Laravel rolls back the entire migration "operation". So, if the last migration command ran 122 migrations, all 122 migrations would be rolled back.
65 |
66 | **Rolling back the last migration operation:**
67 |
68 | php artisan migrate:rollback
69 |
70 | **Roll back all migrations that have ever run:**
71 |
72 | php artisan migrate:reset
--------------------------------------------------------------------------------
/laravel/documentation/database/raw.md:
--------------------------------------------------------------------------------
1 | # Raw Queries
2 |
3 | ## Contents
4 |
5 | - [The Basics](#the-basics)
6 | - [Other Query Methods](#other-query-methods)
7 | - [PDO Connections](#pdo-connections)
8 |
9 |
10 | ## The Basics
11 |
12 | The **query** method is used to execute arbitrary, raw SQL against your database connection.
13 |
14 | #### Selecting records from the database:
15 |
16 | $users = DB::query('select * from users');
17 |
18 | #### Selecting records from the database using bindings:
19 |
20 | $users = DB::query('select * from users where name = ?', array('test'));
21 |
22 | #### Inserting a record into the database
23 |
24 | $success = DB::query('insert into users values (?, ?)', $bindings);
25 |
26 | #### Updating table records and getting the number of affected rows:
27 |
28 | $affected = DB::query('update users set name = ?', $bindings);
29 |
30 | #### Deleting from a table and getting the number of affected rows:
31 |
32 | $affected = DB::query('delete from users where id = ?', array(1));
33 |
34 |
35 | ## Other Query Methods
36 |
37 | Laravel provides a few other methods to make querying your database simple. Here's an overview:
38 |
39 | #### Running a SELECT query and returning the first result:
40 |
41 | $user = DB::first('select * from users where id = 1');
42 |
43 | #### Running a SELECT query and getting the value of a single column:
44 |
45 | $email = DB::only('select email from users where id = 1');
46 |
47 |
48 | ## PDO Connections
49 |
50 | Sometimes you may wish to access the raw PDO connection behind the Laravel Connection object.
51 |
52 | #### Get the raw PDO connection for a database:
53 |
54 | $pdo = DB::connection('sqlite')->pdo;
55 |
56 | > **Note:** If no connection name is specified, the **default** connection will be returned.
--------------------------------------------------------------------------------
/laravel/documentation/database/redis.md:
--------------------------------------------------------------------------------
1 | # Redis
2 |
3 | ## Contents
4 |
5 | - [The Basics](#the-basics)
6 | - [Configuration](#config)
7 | - [Usage](#usage)
8 |
9 |
10 | ## The Basics
11 |
12 | [Redis](http://redis.io) is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain [strings](http://redis.io/topics/data-types#strings), [hashes](http://redis.io/topics/data-types#hashes), [lists](http://redis.io/topics/data-types#lists), [sets](http://redis.io/topics/data-types#sets), and [sorted sets](http://redis.io/topics/data-types#sorted-sets).
13 |
14 |
15 | ## Configuration
16 |
17 | The Redis configuration for your application lives in the **application/config/database.php** file. Within this file, you will see a **redis** array containing the Redis servers used by your application:
18 |
19 | 'redis' => array(
20 |
21 | 'default' => array('host' => '127.0.0.1', 'port' => 6379),
22 |
23 | ),
24 |
25 | The default server configuration should suffice for development. However, you are free to modify this array based on your environment. Simply give each Redis server a name, and specify the host and port used by the server.
26 |
27 |
28 | ## Usage
29 |
30 | You may get a Redis instance by calling the **db** method on the **Redis** class:
31 |
32 | $redis = Redis::db();
33 |
34 | This will give you an instance of the **default** Redis server. You may pass the server name to the **db** method to get a specific server as defined in your Redis configuration:
35 |
36 | $redis = Redis::db('redis_2');
37 |
38 | Great! Now that we have an instance of the Redis client, we may issue any of the [Redis commands](http://redis.io/commands) to the instance. Laravel uses magic methods to pass the commands to the Redis server:
39 |
40 | $redis->set('name', 'Taylor');
41 |
42 | $name = $redis->get('name');
43 |
44 | $values = $redis->lrange('names', 5, 10);
45 |
46 | Notice the arguments to the comment are simply passed into the magic method. Of course, you are not required to use the magic methods, you may also pass commands to the server using the **run** method:
47 |
48 | $values = $redis->run('lrange', array(5, 10));
49 |
50 | Just want to execute commands on the default Redis server? You can just use static magic methods on the Redis class:
51 |
52 | Redis::set('name', 'Taylor');
53 |
54 | $name = Redis::get('name');
55 |
56 | $values = Redis::lrange('names', 5, 10);
57 |
58 | > **Note:** Redis [cache](/docs/cache/config#redis) and [session](/docs/session/config#redis) drivers are included with Laravel.
--------------------------------------------------------------------------------
/laravel/documentation/encryption.md:
--------------------------------------------------------------------------------
1 | # Encryption
2 |
3 | ## Contents
4 |
5 | - [The Basics](#the-basics)
6 | - [Encrypting A String](#encrypt)
7 | - [Decrypting A String](#decrypt)
8 |
9 |
10 | ## The Basics
11 |
12 | Laravel's **Crypter** class provides a simple interface for handling secure, two-way encryption. By default, the Crypter class provides strong AES-256 encryption and decryption out of the box via the Mcrypt PHP extension.
13 |
14 | > **Note:** Don't forget to install the Mcrypt PHP extension on your server.
15 |
16 |
17 | ## Encrypting A String
18 |
19 | #### Encrypting a given string:
20 |
21 | $encrypted = Crypter::encrypt($value);
22 |
23 |
24 | ## Decrypting A String
25 |
26 | #### Decrypting a string:
27 |
28 | $decrypted = Crypter::decrypt($encrypted);
29 |
30 | > **Note:** It's incredibly important to point out that the decrypt method will only decrypt strings that were encrypted using **your** application key.
--------------------------------------------------------------------------------
/laravel/documentation/events.md:
--------------------------------------------------------------------------------
1 | # Events
2 |
3 | ## Contents
4 |
5 | - [The Basics](#the-basics)
6 | - [Firing Events](#firing-events)
7 | - [Listening To Events](#listening-to-events)
8 | - [Laravel Events](#laravel-events)
9 |
10 |
11 | ## The Basics
12 |
13 | Events can provide a great away to build de-coupled applications, and allow plug-ins to tap into the core of your application without modifying its code.
14 |
15 |
16 | ## Firing Events
17 |
18 | To fire an event, just tell the **Event** class the name of the event you want to fire:
19 |
20 | #### Firing an event:
21 |
22 | $responses = Event::fire('loaded');
23 |
24 | Notice that we assigned the result of the **fire** method to a variable. This method will return an array containing the responses of all the event's listeners.
25 |
26 | Sometimes you may want to fire an event, but just get the first response. Here's how:
27 |
28 | #### Firing an event and retrieving the first response:
29 |
30 | $response = Event::first('loaded');
31 |
32 | > **Note:** The **first** method will still fire all of the handlers listening to the event, but will only return the first response.
33 |
34 | The **Event::until** method will execute the event handlers until the first non-null response is returned.
35 |
36 | #### Firing an event until the first non-null response:
37 |
38 | $response = Event::until('loaded');
39 |
40 |
41 | ## Listening To Events
42 |
43 | So, what good are events if nobody is listening? Register an event handler that will be called when an event fires:
44 |
45 | #### Registering an event handler:
46 |
47 | Event::listen('loaded', function()
48 | {
49 | // I'm executed on the "loaded" event!
50 | });
51 |
52 | The Closure we provided to the method will be executed each time the "loaded" event is fired.
53 |
54 |
55 | ## Laravel Events
56 |
57 | There are several events that are fired by the Laravel core. Here they are:
58 |
59 | #### Event fired when a bundle is started:
60 |
61 | Event::listen('laravel.started: bundle', function() {});
62 |
63 | #### Event fired when a database query is executed:
64 |
65 | Event::listen('laravel.query', function($sql, $bindings, $time) {});
66 |
67 | #### Event fired right before response is sent to browser:
68 |
69 | Event::listen('laravel.done', function($response) {});
70 |
71 | #### Event fired when a messaged is logged using the Log class:
72 |
73 | Event::listen('laravel.log', function($type, $message) {});
--------------------------------------------------------------------------------
/laravel/documentation/files.md:
--------------------------------------------------------------------------------
1 | # Working With Files
2 |
3 | ## Contents
4 |
5 | - [Reading Files](#get)
6 | - [Writing Files](#put)
7 | - [File Uploads](#upload)
8 | - [File Extensions](#ext)
9 | - [Checking File Types](#is)
10 | - [Getting MIME Types](#mime)
11 | - [Copying Directories](#cpdir)
12 | - [Removing Directories](#rmdir)
13 |
14 |
15 | ## Reading Files
16 |
17 | #### Getting the contents of a file:
18 |
19 | $contents = File::get('path/to/file');
20 |
21 |
22 | ## Writing Files
23 |
24 | #### Writing to a file:
25 |
26 | File::put('path/to/file', 'file contents');
27 |
28 | #### Appending to a file:
29 |
30 | File::append('path/to/file', 'appended file content');
31 |
32 |
33 | ## File Uploads
34 |
35 | #### Moving a $_FILE to a permanent location:
36 |
37 | Input::upload('picture', 'path/to/pictures');
38 |
39 | > **Note:** You can easily validate file uploads using the [Validator class](/docs/validation).
40 |
41 |
42 | ## File Extensions
43 |
44 | #### Getting the extension from a filename:
45 |
46 | File::extension('picture.png');
47 |
48 |
49 | ## Checking File Types
50 |
51 | #### Determining if a file is given type:
52 |
53 | if (File::is('jpg', 'path/to/file.jpg'))
54 | {
55 | //
56 | }
57 |
58 | The **is** method does not simply check the file extension. The Fileinfo PHP extension will be used to read the content of the file and determine the actual MIME type.
59 |
60 | > **Note:** You may pass any of the extensions defined in the **application/config/mimes.php** file to the **is** method.
61 | > **Note:** The Fileinfo PHP extension is required for this functionality. More information can be found on the [PHP Fileinfo page](http://php.net/manual/en/book.fileinfo.php).
62 |
63 |
64 | ## Getting MIME Types
65 |
66 | #### Getting the MIME type associated with an extension:
67 |
68 | echo File::mime('gif');
69 |
70 | > **Note:** This method simply returns the MIME type defined for the extension in the **application/config/mimes.php** file.
71 |
72 |
73 | ## Copying Directories
74 |
75 | #### Recursively copy a directory to a given location:
76 |
77 | File::cpdir($directory, $destination);
78 |
79 |
80 | ## Removing Directories
81 |
82 | #### Recursively delete a directory:
83 |
84 | File::rmdir($directory);
--------------------------------------------------------------------------------
/laravel/documentation/ioc.md:
--------------------------------------------------------------------------------
1 | # IoC Container
2 |
3 | - [Definition](/docs/ioc#definition)
4 | - [Registering Objects](/docs/ioc#register)
5 | - [Resolving Objects](/docs/ioc#resolve)
6 |
7 |
8 | ## Definition
9 |
10 | An IoC container is simply a way of managing the creation of objects. You can use it to define the creation of complex objects, allowing you to resolve them throughout your application using a single line of code. You may also use it to "inject" dependencies into your classes and controllers.
11 |
12 | IoC containers help make your application more flexible and testable. Since you may register alternate implementations of an interface with the container, you may isolate the code you are testing from external dependencies using [stubs and mocks](http://martinfowler.com/articles/mocksArentStubs.html).
13 |
14 |
15 | ## Registering Objects
16 |
17 | #### Registering a resolver in the IoC container:
18 |
19 | IoC::register('mailer', function()
20 | {
21 | $transport = Swift_MailTransport::newInstance();
22 |
23 | return Swift_Mailer::newInstance($transport);
24 | });
25 |
26 |
27 | Great! Now we have registered a resolver for SwiftMailer in our container. But, what if we don't want the container to create a new mailer instance every time we need one? Maybe we just want the container to return the same instance after the intial instance is created. Just tell the container the object should be a singleton:
28 |
29 | #### Registering a singleton in the container:
30 |
31 | IoC::singleton('mailer', function()
32 | {
33 | //
34 | });
35 |
36 | You may also register an existing object instance as a singleton in the container.
37 |
38 | #### Registering an existing instance in the container:
39 |
40 | IoC::instance('mailer', $instance);
41 |
42 |
43 | ## Resolving Objects
44 |
45 | Now that we have SwiftMailer registered in the container, we can resolve it using the **resolve** method on the **IoC** class:
46 |
47 | $mailer = IoC::resolve('mailer');
48 |
49 | > **Note:** You may also [register controllers in the container](/docs/controllers#dependency-injection).
--------------------------------------------------------------------------------
/laravel/documentation/logging.md:
--------------------------------------------------------------------------------
1 | # Errors & Logging
2 |
3 | ## Contents
4 |
5 | - [Basic Configuration](#basic-configuration)
6 | - [Logging](#logging)
7 | - [The Logger Class](#the-logger-class)
8 |
9 |
10 | ## Basic Configuration
11 |
12 | All of the configuration options regarding errors and logging live in the **application/config/errors.php** file. Let's jump right in.
13 |
14 | ### Ignored Errors
15 |
16 | The **ignore** option contains an array of error levels that should be ignored by Laravel. By "ignored", we mean that we won't stop execution of the script on these errors. However, they will be logged when logging is enabled.
17 |
18 | ### Error Detail
19 |
20 | The **detail** option indicates if the framework should display the error message and stack trace when an error occurs. For development, you will want this to be **true**. However, in a production environment, set this to **false**. When disabled, the view located in **application/views/error/500.php** will be displayed, which contains a generic error message.
21 |
22 |
23 | ## Logging
24 |
25 | To enable logging, set the **log** option in the error configuration to "true". When enabled, the Closure defined by the **logger** configuration item will be executed when an error occurs. This gives you total flexibility in how the error should be logged. You can even e-mail the errors to your development team!
26 |
27 | By default, logs are stored in the **storage/logs** direcetory, and a new log file is created for each day. This keeps your log files from getting crowded with too many messages.
28 |
29 |
30 | ## The Logger Class
31 |
32 | Sometimes you may wish to use Laravel's **Log** class for debugging, or just to log informational messages. Here's how to use it:
33 |
34 | #### Writing a message to the logs:
35 |
36 | Log::write('info', 'This is just an informational message!');
37 |
38 | #### Using magic methods to specify the log message type:
39 |
40 | Log::info('This is just an informational message!');
--------------------------------------------------------------------------------
/laravel/documentation/requests.md:
--------------------------------------------------------------------------------
1 | # Examining Requests
2 |
3 | ## Contents
4 |
5 | - [Working With The URI](#working-with-the-uri)
6 | - [Other Request Helpers](#other-request-helpers)
7 |
8 |
9 | ## Working With The URI
10 |
11 | #### Getting the current URI for the request:
12 |
13 | echo URI::current();
14 |
15 | #### Getting a specific segment from the URI:
16 |
17 | echo URI::segment(1);
18 |
19 | #### Returning a default value if the segment doesn't exist:
20 |
21 | echo URI::segment(10, 'Foo');
22 |
23 | #### Getting the full request URI, including query string:
24 |
25 | echo URI::full();
26 |
27 | Sometimes you may need to determine if the current URI is a given string, or begins with a given string. Here's an example of how you can use the is() method to accomplish this:
28 |
29 | #### Determine if the URI is "home":
30 |
31 | if (URI::is('home'))
32 | {
33 | // The current URI is "home"!
34 | }
35 |
36 | #### Determine if the current URI begins with "docs/":
37 |
38 | if URI::is('docs/*'))
39 | {
40 | // The current URI begins with "docs/"!
41 | }
42 |
43 |
44 | ## Other Request Helpers
45 |
46 | #### Getting the current request method:
47 |
48 | echo Request::method();
49 |
50 | #### Accessing the $_SERVER global array:
51 |
52 | echo Request::server('http_referer');
53 |
54 | #### Retrieving the requester's IP address:
55 |
56 | echo Request::ip();
57 |
58 | #### Determining if the current request is using HTTPS:
59 |
60 | if (Request::secure())
61 | {
62 | // This request is over HTTPS!
63 | }
64 |
65 | #### Determing if the current request is an AJAX request:
66 |
67 | if (Request::ajax())
68 | {
69 | // This request is using AJAX!
70 | }
71 |
72 | #### Determining if the current requst is via the Artisan CLI:
73 |
74 | if (Request::cli())
75 | {
76 | // This request came from the CLI!
77 | }
--------------------------------------------------------------------------------
/laravel/documentation/session/usage.md:
--------------------------------------------------------------------------------
1 | # Session Usage
2 |
3 | ## Contents
4 |
5 | - [Storing Items](#put)
6 | - [Retrieving Items](#get)
7 | - [Removing Items](#forget)
8 | - [Regeneration](#regeneration)
9 |
10 |
11 | ## Storing Items
12 |
13 | To store items in the session call the put method on the Session class:
14 |
15 | Session::put('name', 'Taylor');
16 |
17 | The first parameter is the **key** to the session item. You will use this key to retrieve the item from the session. The second parameter is the **value** of the item.
18 |
19 | The **flash** method stores an item in the session that will expire after the next request. It's useful for storing temporary data like status or error messages:
20 |
21 | Session::flash('status', 'Welcome Back!');
22 |
23 |
24 | ## Retrieving Items
25 |
26 | You can use the **get** method on the Session class to retrieve any item in the session, including flash data. Just pass the key of the item you wish to retrieve:
27 |
28 | $name = Session::get('name');
29 |
30 | By default, NULL will be returned if the session item does not exist. However, you may pass a default value as a second parameter to the get method:
31 |
32 | $name = Session::get('name', 'Fred');
33 |
34 | $name = Session::get('name', function() {return 'Fred';});
35 |
36 | Now, "Fred" will be returned if the "name" item does not exist in the session.
37 |
38 | Laravel even provides a simple way to determine if a session item exists using the **has** method:
39 |
40 | if (Session::has('name'))
41 | {
42 | $name = Session::get('name');
43 | }
44 |
45 |
46 | ## Removing Items
47 |
48 | To remove an item from the session use the **forget** method on the Session class:
49 |
50 | Session::forget('name');
51 |
52 | You can even remove all of the items from the session using the **flush** method:
53 |
54 | Session::flush();
55 |
56 |
57 | ## Regeneration
58 |
59 | Sometimes you may want to "regenerate" the session ID. This simply means that a new, random session ID will be assigned to the session. Here's how to do it:
60 |
61 | Session::regenerate();
--------------------------------------------------------------------------------
/laravel/documentation/strings.md:
--------------------------------------------------------------------------------
1 | # Working With Strings
2 |
3 | ## Contents
4 |
5 | - [Capitalization, Etc.](#capitalization)
6 | - [Word & Character Limiting](#limits)
7 | - [Generating Random Strings](#random)
8 | - [Singular & Plural](#singular-and-plural)
9 | - [Slugs](#slugs)
10 |
11 |
12 | ## Capitalization, Etc.
13 |
14 | The **Str** class also provides three convenient methods for manipulating string capitalization: **upper**, **lower**, and **title**. These are more intelligent versions of the PHP [strtoupper](http://php.net/manual/en/function.strtoupper.php), [strtolower](http://php.net/manual/en/function.strtolower.php), and [ucwords](http://php.net/manual/en/function.ucwords.php) methods. More intelligent because they can handle UTF-8 input if the [multi-byte string](http://php.net/manual/en/book.mbstring.php) PHP extension is installed on your web server. To use them, just pass a string to the method:
15 |
16 | echo Str::lower('I am a string.');
17 |
18 | echo Str::upper('I am a string.');
19 |
20 | echo Str::title('I am a string.');
21 |
22 |
23 | ## Word & Character Limiting
24 |
25 | #### Limiting the number of characters in a string:
26 |
27 | echo Str::limit($string, 10);
28 |
29 | #### Limiting the number of words in a string:
30 |
31 | echo Str::words($string, 10);
32 |
33 |
34 | ## Generating Random Strings
35 |
36 | #### Generating a random string of alpha-numeric characters:
37 |
38 | echo Str::random(32);
39 |
40 | #### Generating a random string of alphabetic characters:
41 |
42 | echo Str::random(32, 'alpha');
43 |
44 |
45 | ## Singular & Plural
46 |
47 | The String class is capable of transforming your strings from singular to plural, and vice versa.
48 |
49 | #### Getting the plural form of a word:
50 |
51 | echo Str::plural('user');
52 |
53 | #### Getting the singular form of a word:
54 |
55 | echo Str::singular('users');
56 |
57 | #### Getting the plural form if given value is greater than one:
58 |
59 | echo Str::plural('comment', count($comments));
60 |
61 |
62 | ## Slugs
63 |
64 | #### Generating a URL friendly slug:
65 |
66 | return Str::slug('My First Blog Post!');
67 |
68 | #### Generating a URL friendly slug using a given separator:
69 |
70 | return Str::slug('My First Blog Post!', '_');
71 |
72 |
--------------------------------------------------------------------------------
/laravel/documentation/testing.md:
--------------------------------------------------------------------------------
1 | # Unit Testing
2 |
3 | ## Contents
4 |
5 | - [The Basics](#the-basics)
6 | - [Creating Test Classes](#creating-test-classes)
7 | - [Running Tests](#running-tests)
8 | - [Calling Controllers From Tests](#calling-controllers-from-tests)
9 |
10 |
11 | ## The Basics
12 |
13 | Unit Testing allows you to test your code and verify that it is working correctly. In fact, many advocate that you should even write your tests before you write your code! Laravel provides beautiful integration with the popular [PHPUnit](http://www.phpunit.de/manual/current/en/) testing library, making it easy to get started writing your tests. In fact, the Laravel framework itself has hundreds of unit tests!
14 |
15 |
16 | ## Creating Test Classes
17 |
18 | All of your application's tests live in the **application/tests** directory. In this directory, you will find a basic **example.test.php** file. Pop it open and look at the class it contains:
19 |
20 | assertTrue(true);
32 | }
33 |
34 | }
35 |
36 | Take special note of the **.test.php** file suffix. This tells Laravel that it should include this class as a test case when running your test. Any files in the test directory that are not named with this suffix will not be considered a test case.
37 |
38 | If you are writing tests for a bundle, just place them in a **tests** directory within the bundle. Laravel will take care of the rest!
39 |
40 | For more information regarding creating test cases, check out the [PHPUnit documentation](http://www.phpunit.de/manual/current/en/).
41 |
42 |
43 | ## Running Tests
44 |
45 | To run your tests, you can use Laravel's Artisan command-line utility:
46 |
47 | #### Running the application's tests via the Artisan CLI:
48 |
49 | php artisan test
50 |
51 | #### Running the unit tests for a bundle:
52 |
53 | php artisan test bundle-name
54 |
55 |
56 | ## Calling Controllers From Tests
57 |
58 | Here's an example of how you can call your controllers from your tests:
59 |
60 | #### Calling a controller from a test:
61 |
62 | $response = Controller::call('home@index', $parameters);
63 |
64 | #### Resolving an instance of a controller from a test:
65 |
66 | $controller = Controller::resolve('application', 'home@index');
67 |
68 | > **Note:** The controller's action filters will still run when using Controller::call to execute controller actions.
--------------------------------------------------------------------------------
/laravel/documentation/urls.md:
--------------------------------------------------------------------------------
1 | # Generating URLs
2 |
3 | ## Contents
4 |
5 | - [The Basics](#the-basics)
6 | - [URLs To Routes](#urls-to-routes)
7 | - [URLs To Controller Actions](#urls-to-controller-actions)
8 | - [URLs To Assets](#urls-to-assets)
9 | - [URL Helpers](#url-helpers)
10 |
11 |
12 | ## The Basics
13 |
14 | #### Retrieving the application's base URL:
15 |
16 | $url = URL::base();
17 |
18 | #### Generating a URL relative to the base URL:
19 |
20 | $url = URL::to('user/profile');
21 |
22 | #### Generating a HTTPS URL:
23 |
24 | $url = URL::to_secure('user/login');
25 |
26 | #### Retrieving the current URL:
27 |
28 | $url = URL::current();
29 |
30 | #### Retrieving the current URL including query string:
31 |
32 | $url = URL::full();
33 |
34 |
35 | ## URLs To Routes
36 |
37 | #### Generating a URL to a named route:
38 |
39 | $url = URL::to_route('profile');
40 |
41 | Sometimes you may need to generate a URL to a named route, but also need to specify the values that should be used instead of the route's URI wildcards. It's easy to replace the wildcards with proper values:
42 |
43 | #### Generating a URL to a named route with wildcard values:
44 |
45 | $url = URL::to_route('profile', array($username));
46 |
47 | *Further Reading:*
48 |
49 | - [Named Routes](/docs/routing#named-routes)
50 |
51 |
52 | ## URLs To Controller Actions
53 |
54 | #### Generating a URL to a controller action:
55 |
56 | $url = URL::to_action('user@profile');
57 |
58 | #### Generating a URL to an action with wildcard values:
59 |
60 | $url = URL::to_action('user@profile', array($username));
61 |
62 |
63 | ## URLs To Assets
64 |
65 | URLs generated for assets will not contain the "application.index" configuration option.
66 |
67 | #### Generating a URL to an asset:
68 |
69 | $url = URL::to_asset('js/jquery.js');
70 |
71 |
72 | ## URL Helpers
73 |
74 | There are several global functions for generating URLs designed to make your life easier and your code cleaner:
75 |
76 | #### Generating a URL relative to the base URL:
77 |
78 | $url = url('user/profile');
79 |
80 | #### Generating a URL to an asset:
81 |
82 | $url = asset('js/jquery.js');
83 |
84 | #### Generating a URL to a named route:
85 |
86 | $url = route('profile');
87 |
88 | #### Generating a URL to a named route with wildcard values:
89 |
90 | $url = route('profile', array($username));
91 |
92 | #### Generating a URL to a controller action:
93 |
94 | $url = action('user@profile');
95 |
96 | #### Generating a URL to an action with wildcard values:
97 |
98 | $url = action('user@profile', array($username));
--------------------------------------------------------------------------------
/laravel/fluent.php:
--------------------------------------------------------------------------------
1 |
16 | * Create a new fluent container with attributes
17 | * $fluent = new Fluent(array('name' => 'Taylor'));
18 | *
19 | *
20 | * @param array $attributes
21 | * @return void
22 | */
23 | public function __construct($attributes = array())
24 | {
25 | foreach ($attributes as $key => $value)
26 | {
27 | $this->$key = $value;
28 | }
29 | }
30 |
31 | /**
32 | * Get an attribute from the fluent container.
33 | *
34 | * @param string $attribute
35 | * @param mixed $default
36 | * @return mixed
37 | */
38 | public function get($attribute, $default = null)
39 | {
40 | return array_get($this->attributes, $attribute, $default);
41 | }
42 |
43 | /**
44 | * Handle dynamic calls to the container to set attributes.
45 | *
46 | *
47 | * // Fluently set the value of a few attributes
48 | * $fluent->name('Taylor')->age(25);
49 | *
50 | * // Set the value of an attribute to true (boolean)
51 | * $fluent->nullable()->name('Taylor');
52 | *
53 | */
54 | public function __call($method, $parameters)
55 | {
56 | $this->$method = (count($parameters) > 0) ? $parameters[0] : true;
57 |
58 | return $this;
59 | }
60 |
61 | /**
62 | * Dynamically retrieve the value of an attribute.
63 | */
64 | public function __get($key)
65 | {
66 | if (array_key_exists($key, $this->attributes))
67 | {
68 | return $this->attributes[$key];
69 | }
70 | }
71 |
72 | /**
73 | * Dynamically set the value of an attribute.
74 | */
75 | public function __set($key, $value)
76 | {
77 | $this->attributes[$key] = $value;
78 | }
79 |
80 | /**
81 | * Dynamically check if an attribute is set.
82 | */
83 | public function __isset($key)
84 | {
85 | return isset($this->attributes[$key]);
86 | }
87 |
88 | /**
89 | * Dynamically unset an attribute.
90 | */
91 | public function __unset($key)
92 | {
93 | unset($this->attributes[$key]);
94 | }
95 |
96 | }
--------------------------------------------------------------------------------
/laravel/hash.php:
--------------------------------------------------------------------------------
1 |
9 | * // Create a Bcrypt hash of a value
10 | * $hash = Hash::make('secret');
11 | *
12 | * // Use a specified number of iterations when creating the hash
13 | * $hash = Hash::make('secret', 12);
14 | *
15 | *
16 | * @param string $value
17 | * @param int $rounds
18 | * @return string
19 | */
20 | public static function make($value, $rounds = 8)
21 | {
22 | $work = str_pad($rounds, 2, '0', STR_PAD_LEFT);
23 |
24 | // Bcrypt expects the salt to be 22 base64 encoded characters including
25 | // dots and slashes. We will get rid of the plus signs included in the
26 | // base64 data and replace them with dots.
27 | if (function_exists('openssl_random_pseudo_bytes'))
28 | {
29 | $salt = openssl_random_pseudo_bytes(16);
30 | }
31 | else
32 | {
33 | $salt = Str::random(40);
34 | }
35 |
36 | $salt = substr(strtr(base64_encode($salt), '+', '.'), 0 , 22);
37 |
38 | return crypt($value, '$2a$'.$work.'$'.$salt);
39 | }
40 |
41 | /**
42 | * Determine if an unhashed value matches a Bcrypt hash.
43 | *
44 | * @param string $value
45 | * @param string $hash
46 | * @return bool
47 | */
48 | public static function check($value, $hash)
49 | {
50 | return crypt($value, $hash) === $hash;
51 | }
52 |
53 | }
--------------------------------------------------------------------------------
/laravel/log.php:
--------------------------------------------------------------------------------
1 | getMessage().' in '.$e->getFile().' on line '.$e->getLine();
25 | }
26 |
27 | /**
28 | * Write a message to the log file.
29 | *
30 | *
31 | * // Write an "error" messge to the log file
32 | * Log::write('error', 'Something went horribly wrong!');
33 | *
34 | * // Write an "error" message using the class' magic method
35 | * Log::error('Something went horribly wrong!');
36 | *
37 | *
38 | * @param string $type
39 | * @param string $message
40 | * @return void
41 | */
42 | public static function write($type, $message)
43 | {
44 | // If there is a listener for the log event, we'll delegate the logging
45 | // to the event and not write to the log files. This allows for quick
46 | // swapping of log implementations for debugging.
47 | if (Event::listeners('laravel.log'))
48 | {
49 | Event::fire('laravel.log', array($type, $message));
50 | }
51 |
52 | // If there aren't listeners on the log event, we'll just write to the
53 | // log files using the default conventions, writing one log file per
54 | // day so they files don't get too crowded.
55 | else
56 | {
57 | $message = static::format($type, $message);
58 |
59 | File::append(path('storage').'logs/'.date('Y-m-d').'.log', $message);
60 | }
61 | }
62 |
63 | /**
64 | * Format a log message for logging.
65 | *
66 | * @param string $type
67 | * @param
68 | */
69 | protected static function format($type, $message)
70 | {
71 | return date('Y-m-d H:i:s').' '.Str::upper($type)." - {$message}".PHP_EOL;
72 | }
73 |
74 | /**
75 | * Dynamically write a log message.
76 | *
77 | *
78 | * // Write an "error" message to the log file
79 | * Log::error('This is an error!');
80 | *
81 | * // Write a "warning" message to the log file
82 | * Log::warning('This is a warning!');
83 | *
84 | */
85 | public static function __callStatic($method, $parameters)
86 | {
87 | static::write($method, $parameters[0]);
88 | }
89 |
90 | }
--------------------------------------------------------------------------------
/laravel/memcached.php:
--------------------------------------------------------------------------------
1 |
16 | * // Get the Memcache connection and get an item from the cache
17 | * $name = Memcached::connection()->get('name');
18 | *
19 | * // Get the Memcache connection and place an item in the cache
20 | * Memcached::connection()->set('name', 'Taylor');
21 | *
22 | *
23 | * @return Memcached
24 | */
25 | public static function connection()
26 | {
27 | if (is_null(static::$connection))
28 | {
29 | static::$connection = static::connect(Config::get('cache.memcached'));
30 | }
31 |
32 | return static::$connection;
33 | }
34 |
35 | /**
36 | * Create a new Memcached connection instance.
37 | *
38 | * @param array $servers
39 | * @return Memcached
40 | */
41 | protected static function connect($servers)
42 | {
43 | $memcache = new \Memcached;
44 |
45 | foreach ($servers as $server)
46 | {
47 | $memcache->addServer($server['host'], $server['port'], $server['weight']);
48 | }
49 |
50 | if ($memcache->getVersion() === false)
51 | {
52 | throw new \Exception('Could not establish memcached connection.');
53 | }
54 |
55 | return $memcache;
56 | }
57 |
58 | /**
59 | * Dynamically pass all other method calls to the Memcache instance.
60 | *
61 | *
62 | * // Get an item from the Memcache instance
63 | * $name = Memcached::get('name');
64 | *
65 | * // Store data on the Memcache server
66 | * Memcached::set('name', 'Taylor');
67 | *
68 | */
69 | public static function __callStatic($method, $parameters)
70 | {
71 | return call_user_func_array(array(static::instance(), $method), $parameters);
72 | }
73 |
74 | }
--------------------------------------------------------------------------------
/laravel/profiling/profiler.php:
--------------------------------------------------------------------------------
1 | array(), 'logs' => array());
17 |
18 | /**
19 | * Get the rendered contents of the Profiler.
20 | *
21 | * @param Response $response
22 | * @return string
23 | */
24 | public static function render($response)
25 | {
26 | // We only want to send the profiler toolbar if the request is not an AJAX
27 | // request, as sending it on AJAX requests could mess up JSON driven API
28 | // type applications, so we will not send anything in those scenarios.
29 | if ( ! Request::ajax())
30 | {
31 | return render('path: '.__DIR__.'/template'.BLADE_EXT, static::$data);
32 | }
33 | }
34 |
35 | /**
36 | * Add a log entry to the log entries array.
37 | *
38 | * @return void
39 | */
40 | public static function log($type, $message)
41 | {
42 | static::$data['logs'][] = array($type, $message);
43 | }
44 |
45 | /**
46 | * Add a performed SQL query to the Profiler.
47 | *
48 | * @param string $sql
49 | * @param array $bindings
50 | * @param float $time
51 | * @return void
52 | */
53 | public static function query($sql, $bindings, $time)
54 | {
55 | foreach ($bindings as $binding)
56 | {
57 | $sql = preg_replace('/\?/', $binding, $sql, 1);
58 | }
59 |
60 | static::$data['queries'][] = array($sql, $time);
61 | }
62 |
63 | /**
64 | * Attach the Profiler's event listeners.
65 | *
66 | * @return void
67 | */
68 | public static function attach()
69 | {
70 | // First we'll attach to the query and log events. These allow us to catch
71 | // all of the SQL queries and log messages that come through Laravel,
72 | // and we will pass them onto the Profiler for simple storage.
73 | Event::listen('laravel.log', function($type, $message)
74 | {
75 | Profiler::log($type, $message);
76 | });
77 |
78 | Event::listen('laravel.query', function($sql, $bindings, $time)
79 | {
80 | Profiler::query($sql, $bindings, $time);
81 | });
82 |
83 | // We'll attach the profiler to the "done" event so that we can easily
84 | // attach the profiler output to the end of the output sent to the
85 | // browser. This will display the profiler's nice toolbar.
86 | Event::listen('laravel.done', function($response)
87 | {
88 | echo Profiler::render($response);
89 | });
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/laravel/profiling/template.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | @if (count($logs) > 0)
8 |
9 |
10 |
Type
11 |
Message
12 |
13 | @foreach ($logs as $log)
14 |
15 |
16 | {{ $log[0] }}
17 |
18 |
19 | {{ $log[1] }}
20 |
21 | @endforeach
22 |
23 |
24 | @else
25 | There are no log entries.
26 | @endif
27 |
28 |
29 |
30 | @if (count($queries) > 0)
31 |
32 |
33 |
Time
34 |
Query
35 |
36 | @foreach ($queries as $query)
37 |
38 |
39 | {{ $query[1] }}ms
40 |
41 |
42 |
{{ $query[0] }}
43 |
44 |
45 | @endforeach
46 |
47 | @else
48 | There have been no SQL queries executed.
49 | @endif
50 |