mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Correzioni minori e aggiornamento a Laravel 9
This commit is contained in:
128
app/LaravelGettext/LaravelGettextServiceProvider.php
Normal file
128
app/LaravelGettext/LaravelGettextServiceProvider.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\LaravelGettext;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Foundation\AliasLoader;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\LaravelGettext\Adapters\AdapterInterface;
|
||||
use App\LaravelGettext\Config\ConfigManager;
|
||||
use App\LaravelGettext\Config\Models\Config;
|
||||
|
||||
/**
|
||||
* Main service provider
|
||||
*
|
||||
* Class LaravelGettextServiceProvider
|
||||
* @package App\LaravelGettext
|
||||
*
|
||||
*/
|
||||
class LaravelGettextServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Bootstrap the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__ . '/../../config/config.php' => config_path('laravel-gettext.php')
|
||||
], 'config');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$configuration = ConfigManager::create();
|
||||
|
||||
$this->app->bind(
|
||||
AdapterInterface::class,
|
||||
$configuration->get()->getAdapter()
|
||||
);
|
||||
|
||||
$this->app->singleton(Config::class, function($app) use ($configuration){
|
||||
return $configuration->get();
|
||||
});
|
||||
|
||||
// Main class register
|
||||
$this->app->singleton(LaravelGettext::class, function (Application $app) use ($configuration) {
|
||||
|
||||
$fileSystem = new FileSystem($configuration->get(), app_path(), storage_path());
|
||||
$storage = $app->make($configuration->get()->getStorage());
|
||||
|
||||
if ('symfony' == $configuration->get()->getHandler()) {
|
||||
// symfony translator implementation
|
||||
$translator = new Translators\Symfony(
|
||||
$configuration->get(),
|
||||
$this->app->make(AdapterInterface::class),
|
||||
$fileSystem,
|
||||
$storage
|
||||
);
|
||||
} else {
|
||||
// GNU/Gettext php extension
|
||||
$translator = new Translators\Gettext(
|
||||
$configuration->get(),
|
||||
$this->app->make(AdapterInterface::class),
|
||||
$fileSystem,
|
||||
$storage
|
||||
);
|
||||
}
|
||||
|
||||
return new LaravelGettext($translator);
|
||||
|
||||
});
|
||||
$this->app->alias(LaravelGettext::class, 'laravel-gettext');
|
||||
|
||||
// Alias
|
||||
$this->app->booting(function () {
|
||||
$aliasLoader = AliasLoader::getInstance();
|
||||
$aliasLoader->alias('LaravelGettext', \App\LaravelGettext\Facades\LaravelGettext::class);
|
||||
});
|
||||
|
||||
$this->registerCommands();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands
|
||||
*/
|
||||
protected function registerCommands()
|
||||
{
|
||||
// Package commands
|
||||
$this->app->bind('xinax::gettext.create', function ($app) {
|
||||
return new Commands\GettextCreate();
|
||||
});
|
||||
|
||||
$this->app->bind('xinax::gettext.update', function ($app) {
|
||||
return new Commands\GettextUpdate();
|
||||
});
|
||||
|
||||
$this->commands([
|
||||
'xinax::gettext.create',
|
||||
'xinax::gettext.update',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return [
|
||||
'laravel-gettext'
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user