Last active
August 29, 2015 14:03
-
-
Save gravitano/3d7bb622bc4efa5a8e68 to your computer and use it in GitHub Desktop.
Drop the static system of Laravel using this trait :D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait LaravelTrait | |
{ | |
/** | |
* The Laravel Aliases. | |
* | |
* @var array | |
*/ | |
protected $aliases = array( | |
'app' => 'app', | |
'artisan' => 'artisan', | |
'auth' => 'auth', | |
'auth_reminder_repository' => 'auth.reminder.repository', | |
'blade' => 'blade.compiler', | |
'cache' => 'cache', | |
'cache_store' => 'cache.store', | |
'config' => 'config', | |
'cookie' => 'cookie', | |
'crypt' => 'encrypter', | |
'db' => 'db', | |
'events' => 'events', | |
'files' => 'files', | |
'form' => 'form', | |
'hash' => 'hash', | |
'html' => 'html', | |
'lang' => 'translator', | |
'translator' => 'translator', | |
'log' => 'log', | |
'mailer' => 'mailer', | |
'mail' => 'mailer', | |
'paginator' => 'paginator', | |
'auth_reminder' => 'auth.reminder', | |
'queue' => 'queue', | |
'redirect' => 'redirect', | |
'redis' => 'redis', | |
'request' => 'request', | |
'input' => 'request', | |
'router' => 'router', | |
'session' => 'session', | |
'session_store' => 'session.store', | |
'remote' => 'remote', | |
'url' => 'url', | |
'validator' => 'validator', | |
'view' => 'view', | |
); | |
/** | |
* Handle get property. | |
* | |
* @param $key | |
* @return mixed | |
*/ | |
public function __get($key) | |
{ | |
$app = app(); | |
if($key == 'laravel' || $key == 'app') | |
{ | |
return $app; | |
} | |
if(array_key_exists($key, $this->aliases)) | |
{ | |
return $app[$this->aliases[$key]]; | |
} | |
return $this->$key; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Usage :