Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/Clarity/Lang/LangServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,20 @@
*/
class LangServiceProvider extends ServiceProvider
{
/**
* @var string
*/
protected $alias = 'lang';

/**
* @var bool
*/
protected $shared = false;

/**
* {@inheritdoc}
*/
public function register()
{
$language = config()->app->lang;
$this->app->singleton('lang', function () {
$language = config()->app->lang;

$translation = new Lang();
$translation
->setLanguage($language)
->setLangDir(config()->path->lang);
$translation = new Lang();
$translation
->setLanguage($language)
->setLangDir(config()->path->lang);

return $translation;
return $translation;
});
}
}
36 changes: 15 additions & 21 deletions src/Clarity/Mail/MailServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,31 @@
*/
class MailServiceProvider extends ServiceProvider
{
/**
* @var string
*/
protected $alias = 'mail';

/**
* @var bool
*/
protected $shared = false;

/**
* {@inheritdoc}
*/
public function register()
{
$selected_adapter = config()->app->mail_adapter;
$this->app->singleton('mail.selected_adapter', function () {
$selected_adapter = config()->app->mail_adapter;

$adapter = config()->mail->{$selected_adapter};
return config()->mail->{$selected_adapter};
});

if (! $adapter) {
throw new Exception('Adapter not found.');
}
$this->app->singleton('mail', function ($app) {
$adapter = $app->make('mail.selected_adapter')->toArray();

if (! $adapter['active']) {
return $this;
}
if (! $adapter) {
throw new Exception('Adapter not found.');
}

$adapter = $adapter->toArray();
if (! $adapter['active']) {
return $this;
}

$class = $adapter['class'];
$class = $adapter['class'];

return new Mail(new $class, $adapter['options']);
return new Mail(new $class, $adapter['options']);
});
}
}
36 changes: 6 additions & 30 deletions src/Clarity/Providers/Aliaser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,17 @@
*/
class Aliaser extends ServiceProvider
{
/**
* {@inheridoc}.
*/
protected $alias = 'aliaser';

/**
* {@inheridoc}.
*/
protected $shared = true;

/**
* {@inheridoc}.
*/
public function register()
{
foreach (config()->app->aliases as $alias => $class) {
if (! class_exists($alias)) {
$this->append($alias, $class);
$this->app->singleton('aliaser', function () {
foreach (config('app.aliases') as $alias => $class) {
if (! class_exists($alias)) {
class_alias($class, $alias);
}
}
}

return $this;
}

/**
* Attach the alias and the full class.
*
* @param string $alias
* @param string $class
* @return mixed
*/
public function append($alias, $class)
{
class_alias($class, $alias);

return $this;
});
}
}
12 changes: 1 addition & 11 deletions src/Clarity/Providers/Annotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@
*/
class Annotations extends ServiceProvider
{
/**
* {@inheridoc}.
*/
protected $alias = 'annotations';

/**
* {@inheridoc}.
*/
protected $shared = true;

/**
* {@inheridoc}.
*/
public function register()
{
return new Memory;
$this->app->instance('annotations', new Memory, $singleton = true);
}
}
18 changes: 5 additions & 13 deletions src/Clarity/Providers/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,17 @@
*/
class Application extends ServiceProvider
{
/**
* {@inheridoc}.
*/
protected $alias = 'application';

/**
* {@inheridoc}.
*/
protected $shared = true;

/**
* {@inheridoc}.
*/
public function register()
{
$instance = new BaseApplication($this->getDI());
$this->app->singleton('application', function () {
$instance = new BaseApplication($this->getDI());

Facade::setFacadeApplication($instance);
Facade::setFacadeApplication($instance);

return $instance;
return $instance;
});
}
}
12 changes: 1 addition & 11 deletions src/Clarity/Providers/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@
*/
class Auth extends ServiceProvider
{
/**
* {@inheridoc}.
*/
protected $alias = 'auth';

/**
* {@inheridoc}.
*/
protected $shared = true;

/**
* {@inheridoc}.
*/
public function register()
{
return new BaseAuth;
$this->app->instance('auth', new BaseAuth, $singleton = true);
}
}
16 changes: 4 additions & 12 deletions src/Clarity/Providers/BehatMink.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,15 @@
*/
class BehatMink extends ServiceProvider
{
/**
* {@inheridoc}.
*/
protected $alias = 'behat_mink';

/**
* {@inheridoc}.
*/
protected $shared = true;

/**
* {@inheridoc}.
*/
public function register()
{
$adapters = config()->test_suite->behat->adapters->toArray();
$this->app->singleton('behat_mink', function () {
$adapters = config()->test_suite->behat->adapters->toArray();

return new Mink($adapters);
return new Mink($adapters);
});
}
}
26 changes: 9 additions & 17 deletions src/Clarity/Providers/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@
*/
class Cache extends ServiceProvider
{
/**
* {@inheridoc}.
*/
protected $alias = 'cache';

/**
* {@inheridoc}.
*/
protected $shared = true;

/**
* Get the selected cache adapter.
*
Expand All @@ -40,15 +30,17 @@ private function getSelectedAdapter()
*/
public function register()
{
$adapter = config()->cache->adapters->{$this->getSelectedAdapter()};
$this->app->singleton('cache', function () {
$adapter = config()->cache->adapters->{$this->getSelectedAdapter()};

$backend = $adapter->backend;
$frontend = $adapter->frontend;
$backend = $adapter->backend;
$frontend = $adapter->frontend;

$front_cache = new $frontend([
'lifetime' => $adapter->lifetime,
]);
$front_cache = new $frontend([
'lifetime' => $adapter->lifetime,
]);

return new $backend($front_cache, $adapter->options->toArray());
return new $backend($front_cache, $adapter->options->toArray());
});
}
}
16 changes: 5 additions & 11 deletions src/Clarity/Providers/CollectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@
*/
class CollectionManager extends ServiceProvider
{
/**
* {@inheridoc}.
*/
protected $alias = 'collectionManager';

/**
* {@inheridoc}.
*/
protected $shared = true;

/**
* {@inheridoc}.
*/
public function register()
{
return new BaseCollectionManager;
$this->app->instance(
'collectionManager',
new BaseCollectionManager,
$singleton = true
);
}
}
19 changes: 8 additions & 11 deletions src/Clarity/Providers/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,21 @@ class Console extends ServiceProvider
*/
const DESCRIPTION = 'Brood (c) Daison Cariño';

/**
* {@inheridoc}.
*/
protected $alias = 'console';

/**
* {@inheridoc}.
*/
public function register()
{
$app = new ConsoleApplication(self::DESCRIPTION, self::VERSION);
$this->app->bind('console', function () {
$app = new ConsoleApplication(static::DESCRIPTION, static::VERSION);

if (is_cli()) {
foreach (config()->consoles as $console) {
$app->add(new $console);
if (is_cli()) {
foreach (config()->consoles as $console) {
$app->add(new $console);
}
}
}

return $app;
return $app;
});
}
}
12 changes: 1 addition & 11 deletions src/Clarity/Providers/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@
*/
class Cookies extends ServiceProvider
{
/**
* {@inheridoc}.
*/
protected $alias = 'cookies';

/**
* {@inheridoc}.
*/
protected $shared = true;

/**
* {@inheridoc}.
*/
public function register()
{
return new BaseCookies;
$this->app->instance('cookies', new BaseCookies, $singleton = true);
}
}
22 changes: 12 additions & 10 deletions src/Clarity/Providers/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@ class Crypt extends ServiceProvider
*/
public function register()
{
$crypt = new BaseCrypt();
$this->app->singleton('crypt', function () {
$crypt = new BaseCrypt();

if (Str::startsWith($key = config('app.encryption.key'), 'base64:')) {
$key = base64_decode(substr($key, 7));
}
if (Str::startsWith($key = config('app.encryption.key'), 'base64:')) {
$key = base64_decode(substr($key, 7));
}

$crypt->setKey($key);
$crypt->setCipher(config('app.encryption.cipher'));
$crypt->setKey($key);
$crypt->setCipher(config('app.encryption.cipher'));

if ((int) Version::getId() <= 2001341) {
$crypt->setMode(config('app.encryption.mode'));
}
if ((int) Version::getId() <= 2001341) {
$crypt->setMode(config('app.encryption.mode'));
}

return $crypt;
return $crypt;
});
}
}
Loading