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