mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
Applied fixes from StyleCI
This commit is contained in:
parent
3e1a5d9659
commit
06b29a4938
10 changed files with 151 additions and 149 deletions
46
src/Di.php
46
src/Di.php
|
@ -6,35 +6,33 @@ use Pimple\Container;
|
|||
|
||||
/**
|
||||
* Class Di
|
||||
* Dependency Injection Container
|
||||
*
|
||||
* @package TorrentPier
|
||||
* Dependency Injection Container.
|
||||
*/
|
||||
class Di extends Container
|
||||
{
|
||||
private static $instance;
|
||||
private static $instance;
|
||||
|
||||
public function __construct(array $values = [])
|
||||
{
|
||||
parent::__construct($values);
|
||||
static::$instance = $this;
|
||||
}
|
||||
public function __construct(array $values = [])
|
||||
{
|
||||
parent::__construct($values);
|
||||
static::$instance = $this;
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (static::$instance instanceof Container) {
|
||||
return static::$instance;
|
||||
}
|
||||
public static function getInstance()
|
||||
{
|
||||
if (static::$instance instanceof Container) {
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
throw new \Exception('The container has not been initialized');
|
||||
}
|
||||
throw new \Exception('The container has not been initialized');
|
||||
}
|
||||
|
||||
public function __get($id)
|
||||
{
|
||||
if ($this->offsetExists($id)) {
|
||||
return $this->offsetGet($id);
|
||||
}
|
||||
public function __get($id)
|
||||
{
|
||||
if ($this->offsetExists($id)) {
|
||||
return $this->offsetGet($id);
|
||||
}
|
||||
|
||||
throw new \Exception("Service '{$id}' is not registered in the container");
|
||||
}
|
||||
}
|
||||
throw new \Exception("Service '{$id}' is not registered in the container");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,19 +8,19 @@ use Zend\Config\Factory;
|
|||
|
||||
class ConfigServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['config'] = function($container) {
|
||||
$config = Factory::fromFile($container['config.file.system.main'], true);
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['config'] = function ($container) {
|
||||
$config = Factory::fromFile($container['config.file.system.main'], true);
|
||||
|
||||
if (isset($container['config.file.local.main']) && file_exists($container['config.file.local.main'])) {
|
||||
$config->merge(Factory::fromFile($container['config.file.local.main'], true));
|
||||
}
|
||||
if (isset($container['config.file.local.main']) && file_exists($container['config.file.local.main'])) {
|
||||
$config->merge(Factory::fromFile($container['config.file.local.main'], true));
|
||||
}
|
||||
|
||||
return $config;
|
||||
};
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,15 +8,16 @@ use Zend\Db\Adapter\Adapter;
|
|||
|
||||
class DbServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['db'] = function($container) {
|
||||
$adapter = new Adapter($container['config.db']);
|
||||
unset($container['config.db']);
|
||||
return $adapter;
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['db'] = function ($container) {
|
||||
$adapter = new Adapter($container['config.db']);
|
||||
unset($container['config.db']);
|
||||
|
||||
return $adapter;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
|
||||
class RequestServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['request'] = function(Container $container) {
|
||||
return Request::createFromGlobals();
|
||||
};
|
||||
}
|
||||
}
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['request'] = function (Container $container) {
|
||||
return Request::createFromGlobals();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,13 @@ use Symfony\Component\HttpFoundation\Response;
|
|||
|
||||
class ResponseServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['response'] = function(Container $container) {
|
||||
$response = Response::create();
|
||||
$response->prepare($container['request']);
|
||||
return $response;
|
||||
};
|
||||
}
|
||||
}
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['response'] = function (Container $container) {
|
||||
$response = Response::create();
|
||||
$response->prepare($container['request']);
|
||||
|
||||
return $response;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,29 +13,30 @@ use Zend\Db\Adapter\Driver\Pdo\Pdo;
|
|||
|
||||
class SphinxServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['sphinx'] = function($container) {
|
||||
$platform = new SphinxQL();
|
||||
$adapter = new Adapter($container['config.sphinx']);
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['sphinx'] = function ($container) {
|
||||
$platform = new SphinxQL();
|
||||
$adapter = new Adapter($container['config.sphinx']);
|
||||
|
||||
$driver = $adapter->getDriver();
|
||||
// Check driver
|
||||
if ($driver instanceof Pdo && $driver->getDatabasePlatformName(Pdo::NAME_FORMAT_CAMELCASE) == 'Mysql' ) {
|
||||
$driver->registerStatementPrototype(new Statement());
|
||||
} elseif (!$driver instanceof Mysqli) {
|
||||
$class = get_class($driver);
|
||||
throw new UnsupportedDriverException(
|
||||
$class . ' not supported. Use Zend\Db\Adapter\Driver\Pdo\Pdo or Zend\Db\Adapter\Driver\Mysqli\Mysqli'
|
||||
);
|
||||
}
|
||||
$driver = $adapter->getDriver();
|
||||
// Check driver
|
||||
if ($driver instanceof Pdo && $driver->getDatabasePlatformName(Pdo::NAME_FORMAT_CAMELCASE) == 'Mysql') {
|
||||
$driver->registerStatementPrototype(new Statement());
|
||||
} elseif (!$driver instanceof Mysqli) {
|
||||
$class = get_class($driver);
|
||||
throw new UnsupportedDriverException(
|
||||
$class.' not supported. Use Zend\Db\Adapter\Driver\Pdo\Pdo or Zend\Db\Adapter\Driver\Mysqli\Mysqli'
|
||||
);
|
||||
}
|
||||
|
||||
$platform->setDriver($adapter->getDriver());
|
||||
unset($container['config.sphinx']);
|
||||
return $adapter;
|
||||
};
|
||||
}
|
||||
}
|
||||
$platform->setDriver($adapter->getDriver());
|
||||
unset($container['config.sphinx']);
|
||||
|
||||
return $adapter;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,23 +9,23 @@ use Symfony\Component\Translation\Translator;
|
|||
|
||||
class TranslationServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['translator'] = function(Container $container) {
|
||||
$translator = new Translator(
|
||||
$container['settings.locale'],
|
||||
null,
|
||||
null, // $container['config.translator.dir_cache'],
|
||||
$container['config.debug']
|
||||
);
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['translator'] = function (Container $container) {
|
||||
$translator = new Translator(
|
||||
$container['settings.locale'],
|
||||
null,
|
||||
null, // $container['config.translator.dir_cache'],
|
||||
$container['config.debug']
|
||||
);
|
||||
|
||||
$translator->addLoader('php', new PhpFileLoader());
|
||||
$translator->addLoader('php', new PhpFileLoader());
|
||||
|
||||
foreach ($container['config.translator.resources'] as $item) {
|
||||
$translator->addResource('php', $item['resource'], $item['locale']);
|
||||
}
|
||||
foreach ($container['config.translator.resources'] as $item) {
|
||||
$translator->addResource('php', $item['resource'], $item['locale']);
|
||||
}
|
||||
|
||||
return $translator;
|
||||
};
|
||||
}
|
||||
}
|
||||
return $translator;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,23 +8,23 @@ use Symfony\Bridge\Twig\Extension\TranslationExtension;
|
|||
|
||||
class TwigServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['twig'] = function(Container $container) {
|
||||
$loader = new \Twig_Loader_Filesystem($container['config.twig.dir_templates']);
|
||||
$twig = new \Twig_Environment($loader, [
|
||||
'debug' => $container['config.debug'],
|
||||
'cache' => $container['config.twig.dir_cache']
|
||||
]);
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['twig'] = function (Container $container) {
|
||||
$loader = new \Twig_Loader_Filesystem($container['config.twig.dir_templates']);
|
||||
$twig = new \Twig_Environment($loader, [
|
||||
'debug' => $container['config.debug'],
|
||||
'cache' => $container['config.twig.dir_cache'],
|
||||
]);
|
||||
|
||||
$twig->addExtension(new \Twig_Extension_Core);
|
||||
$twig->addExtension(new \Twig_Extension_Escaper);
|
||||
$twig->addExtension(new \Twig_Extension_Optimizer);
|
||||
$twig->addExtension(new \Twig_Extension_Debug);
|
||||
$twig->addExtension(new \Twig_Extension_Core());
|
||||
$twig->addExtension(new \Twig_Extension_Escaper());
|
||||
$twig->addExtension(new \Twig_Extension_Optimizer());
|
||||
$twig->addExtension(new \Twig_Extension_Debug());
|
||||
|
||||
$twig->addExtension(new TranslationExtension($container['translator']));
|
||||
$twig->addExtension(new TranslationExtension($container['translator']));
|
||||
|
||||
return $twig;
|
||||
};
|
||||
}
|
||||
}
|
||||
return $twig;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ use TorrentPier\View;
|
|||
|
||||
class ViewServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['view'] = function(Container $container) {
|
||||
return new View($container['twig']);
|
||||
};
|
||||
}
|
||||
}
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container['view'] = function (Container $container) {
|
||||
return new View($container['twig']);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
37
src/View.php
37
src/View.php
|
@ -4,23 +4,24 @@ namespace TorrentPier;
|
|||
|
||||
class View
|
||||
{
|
||||
/**
|
||||
* @var \Twig_Environment
|
||||
*/
|
||||
protected $twig;
|
||||
/**
|
||||
* @var \Twig_Environment
|
||||
*/
|
||||
protected $twig;
|
||||
|
||||
public function __construct(\Twig_Environment $twig)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
}
|
||||
public function __construct(\Twig_Environment $twig)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $template
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function make($template, $params = [])
|
||||
{
|
||||
return $this->twig->render($template . '.twig', $params);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param $template
|
||||
* @param array $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function make($template, $params = [])
|
||||
{
|
||||
return $this->twig->render($template.'.twig', $params);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue