Refactored Config.

This commit is contained in:
Dmitry Khomutov 2018-03-04 15:56:02 +07:00
parent e23ad3237a
commit dd9f43b7dd
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
37 changed files with 40 additions and 43 deletions

View file

@ -32,7 +32,7 @@ $conf['b8']['app']['namespace'] = 'PHPCensor';
$conf['b8']['app']['default_controller'] = 'Home'; $conf['b8']['app']['default_controller'] = 'Home';
$conf['b8']['view']['path'] = SRC_DIR . 'View/'; $conf['b8']['view']['path'] = SRC_DIR . 'View/';
$config = new b8\Config($conf); $config = new PHPCensor\Config($conf);
$configFile = APP_DIR . 'config.yml'; $configFile = APP_DIR . 'config.yml';
if (file_exists($configFile)) { if (file_exists($configFile)) {

View file

@ -6,6 +6,7 @@ use b8\Exception\HttpException\NotFoundException;
use b8\Http\Response; use b8\Http\Response;
use b8\Http\Request; use b8\Http\Request;
use b8\Http\Router; use b8\Http\Router;
use PHPCensor\Config;
class Application class Application
{ {

View file

@ -5,6 +5,7 @@ namespace b8;
use b8\Http\Request; use b8\Http\Request;
use b8\Http\Response; use b8\Http\Response;
use PHPCensor\View; use PHPCensor\View;
use PHPCensor\Config;
abstract class Controller abstract class Controller
{ {

View file

@ -3,7 +3,7 @@
namespace b8\Form; namespace b8\Form;
use PHPCensor\View; use PHPCensor\View;
use b8\Config; use PHPCensor\Config;
abstract class Element abstract class Element
{ {

View file

@ -3,7 +3,7 @@
namespace b8\Http; namespace b8\Http;
use b8\Application; use b8\Application;
use b8\Config; use PHPCensor\Config;
class Router class Router
{ {

View file

@ -151,7 +151,7 @@ class Application extends b8\Application
*/ */
protected function shouldSkipAuth() protected function shouldSkipAuth()
{ {
$config = b8\Config::getInstance(); $config = Config::getInstance();
$disableAuth = (bool)$config->get('php-censor.security.disable_auth', false); $disableAuth = (bool)$config->get('php-censor.security.disable_auth', false);
$defaultUserId = (integer)$config->get('php-censor.security.default_user_id', 1); $defaultUserId = (integer)$config->get('php-censor.security.default_user_id', 1);

View file

@ -7,7 +7,6 @@ use PHPCensor\Helper\MailerFactory;
use PHPCensor\Logging\BuildLogger; use PHPCensor\Logging\BuildLogger;
use PHPCensor\Model\Build; use PHPCensor\Model\Build;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use b8\Config;
use PHPCensor\Store\BuildErrorWriter; use PHPCensor\Store\BuildErrorWriter;
use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;

View file

@ -5,7 +5,7 @@ namespace PHPCensor\Command;
use Exception; use Exception;
use PDO; use PDO;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\Model\ProjectGroup; use PHPCensor\Model\ProjectGroup;
use PHPCensor\Store\UserStore; use PHPCensor\Store\UserStore;

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Command; namespace PHPCensor\Command;
use b8\Config; use PHPCensor\Config;
use Monolog\Logger; use Monolog\Logger;
use PHPCensor\Logging\BuildDBLogHandler; use PHPCensor\Logging\BuildDBLogHandler;
use PHPCensor\Logging\LoggedBuildContextTidier; use PHPCensor\Logging\LoggedBuildContextTidier;

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Command; namespace PHPCensor\Command;
use b8\Config; use PHPCensor\Config;
use Monolog\Logger; use Monolog\Logger;
use PHPCensor\Logging\OutputLogHandler; use PHPCensor\Logging\OutputLogHandler;
use PHPCensor\Worker\BuildWorker; use PHPCensor\Worker\BuildWorker;

View file

@ -1,11 +1,11 @@
<?php <?php
namespace b8; namespace PHPCensor;
use Symfony\Component\Yaml\Parser as YamlParser; use Symfony\Component\Yaml\Parser as YamlParser;
if (!defined('B8_PATH')) { if (!defined('B8_PATH')) {
define('B8_PATH', __DIR__ . '/'); define('B8_PATH', dirname(__DIR__) . '/B8Framework/');
} }
class Config class Config

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Console; namespace PHPCensor\Console;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler; use Monolog\Handler\StreamHandler;

View file

@ -2,7 +2,6 @@
namespace PHPCensor; namespace PHPCensor;
use b8\Config;
use b8\Exception\HttpException\ForbiddenException; use b8\Exception\HttpException\ForbiddenException;
use b8\Http\Request; use b8\Http\Request;
use b8\Http\Response; use b8\Http\Response;

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Controller; namespace PHPCensor\Controller;
use b8; use PHPCensor\Config;
use PHPCensor\Helper\Lang; use PHPCensor\Helper\Lang;
use PHPCensor\Controller; use PHPCensor\Controller;
@ -22,7 +22,7 @@ class HomeController extends Controller
'left' => [], 'left' => [],
'right' => [], 'right' => [],
]; ];
$widgets_config = b8\Config::getInstance()->get('php-censor.dashboard_widgets', [ $widgets_config = Config::getInstance()->get('php-censor.dashboard_widgets', [
'all_projects' => [ 'all_projects' => [
'side' => 'left', 'side' => 'left',
], ],

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Controller; namespace PHPCensor\Controller;
use b8; use PHPCensor\Config;
use b8\Exception\HttpException\NotFoundException; use b8\Exception\HttpException\NotFoundException;
use b8\Form; use b8\Form;
use PHPCensor\Controller; use PHPCensor\Controller;
@ -116,7 +116,7 @@ class UserController extends Controller
$language->setLabel(Lang::get('language')); $language->setLabel(Lang::get('language'));
$language->setRequired(true); $language->setRequired(true);
$language->setOptions(array_merge( $language->setOptions(array_merge(
[null => Lang::get('default') . ' (' . b8\Config::getInstance()->get('php-censor.language') . ')'], [null => Lang::get('default') . ' (' . Config::getInstance()->get('php-censor.language') . ')'],
Lang::getLanguageOptions()) Lang::getLanguageOptions())
); );
$language->setValue($user->getLanguage()); $language->setValue($user->getLanguage());
@ -128,7 +128,7 @@ class UserController extends Controller
$perPage->setLabel(Lang::get('per_page')); $perPage->setLabel(Lang::get('per_page'));
$perPage->setRequired(true); $perPage->setRequired(true);
$perPage->setOptions([ $perPage->setOptions([
null => Lang::get('default') . ' (' . b8\Config::getInstance()->get('php-censor.per_page') . ')', null => Lang::get('default') . ' (' . Config::getInstance()->get('php-censor.per_page') . ')',
10 => 10, 10 => 10,
25 => 25, 25 => 25,
50 => 50, 50 => 50,

View file

@ -12,7 +12,7 @@ use PHPCensor\Service\BuildService;
use PHPCensor\Store\BuildStore; use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectStore; use PHPCensor\Store\ProjectStore;
use b8\Controller; use b8\Controller;
use b8\Config; use PHPCensor\Config;
use b8\Exception\HttpException\NotFoundException; use b8\Exception\HttpException\NotFoundException;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;

View file

@ -2,8 +2,6 @@
namespace PHPCensor; namespace PHPCensor;
use b8\Config;
class Database extends \PDO class Database extends \PDO
{ {
const MYSQL_TYPE = 'mysql'; const MYSQL_TYPE = 'mysql';

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Helper; namespace PHPCensor\Helper;
use b8\Config; use PHPCensor\Config;
use GuzzleHttp\Client; use GuzzleHttp\Client;
/** /**

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Helper; namespace PHPCensor\Helper;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Builder; use PHPCensor\Builder;
/** /**
@ -99,13 +99,13 @@ class Email
'php-censor.email_settings.from_address', 'php-censor.email_settings.from_address',
self::DEFAULT_FROM self::DEFAULT_FROM
); );
if (strpos($from, '<') === false) { if (strpos($from, '<') === false) {
return (string)$from; return (string)$from;
} }
preg_match('#^(.*?)<(.*)>$#ui', $from, $fromParts); preg_match('#^(.*?)<(.*)>$#ui', $from, $fromParts);
return [$fromParts[2] => $fromParts[1]]; return [$fromParts[2] => $fromParts[1]];
} }

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Helper; namespace PHPCensor\Helper;
use b8\Config; use PHPCensor\Config;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Symfony\Component\Cache\Simple\FilesystemCache; use Symfony\Component\Cache\Simple\FilesystemCache;

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Helper; namespace PHPCensor\Helper;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\Store\UserStore; use PHPCensor\Store\UserStore;

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Helper; namespace PHPCensor\Helper;
use b8\Config; use PHPCensor\Config;
/** /**
* Helper class for dealing with SSH keys. * Helper class for dealing with SSH keys.

View file

@ -6,7 +6,7 @@ use GuzzleHttp\Client;
use PHPCensor\Builder; use PHPCensor\Builder;
use PHPCensor\Helper\Bitbucket; use PHPCensor\Helper\Bitbucket;
use PHPCensor\Helper\Diff; use PHPCensor\Helper\Diff;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Model\Build; use PHPCensor\Model\Build;
use PHPCensor\Model\BuildError; use PHPCensor\Model\BuildError;

View file

@ -6,7 +6,7 @@ use GuzzleHttp\Client;
use PHPCensor\Builder; use PHPCensor\Builder;
use PHPCensor\Helper\Diff; use PHPCensor\Helper\Diff;
use PHPCensor\Helper\Github; use PHPCensor\Helper\Github;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Model\Build; use PHPCensor\Model\Build;
use PHPCensor\Model\BuildError; use PHPCensor\Model\BuildError;

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Model; namespace PHPCensor\Model;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Model; use PHPCensor\Model;
/** /**

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Security\Authentication; namespace PHPCensor\Security\Authentication;
use b8\Config; use PHPCensor\Config;
/** /**
* Authentication facade. * Authentication facade.

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Service; namespace PHPCensor\Service;
use b8\Config; use PHPCensor\Config;
use Pheanstalk\Pheanstalk; use Pheanstalk\Pheanstalk;
use Pheanstalk\PheanstalkInterface; use Pheanstalk\PheanstalkInterface;
use PHPCensor\BuildFactory; use PHPCensor\BuildFactory;

View file

@ -2,7 +2,7 @@
namespace PHPCensor\Store; namespace PHPCensor\Store;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Database; use PHPCensor\Database;
use PHPCensor\Model\BuildError; use PHPCensor\Model\BuildError;

View file

@ -2,7 +2,6 @@
namespace PHPCensor; namespace PHPCensor;
use b8\Config;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\Model\User; use PHPCensor\Model\User;
use PHPCensor\Store\UserStore; use PHPCensor\Store\UserStore;

View file

@ -3,7 +3,7 @@
namespace Tests\b8; namespace Tests\b8;
use b8\Form; use b8\Form;
use b8\Config; use PHPCensor\Config;
class FormTest extends \PHPUnit\Framework\TestCase class FormTest extends \PHPUnit\Framework\TestCase
{ {

View file

@ -9,7 +9,7 @@ class WebhookControllerTest extends \PHPUnit\Framework\TestCase
public function test_wrong_action_name_return_json_with_error() public function test_wrong_action_name_return_json_with_error()
{ {
$webController = new WebhookController( $webController = new WebhookController(
$this->prophesize('b8\Config')->reveal(), $this->prophesize('PHPCensor\Config')->reveal(),
$this->prophesize('b8\Http\Request')->reveal(), $this->prophesize('b8\Http\Request')->reveal(),
$this->prophesize('b8\Http\Response')->reveal() $this->prophesize('b8\Http\Response')->reveal()
); );

View file

@ -2,7 +2,7 @@
namespace Tests\b8; namespace Tests\b8;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Database; use PHPCensor\Database;
class DatabaseMysqlTest extends \PHPUnit_Extensions_Database_TestCase class DatabaseMysqlTest extends \PHPUnit_Extensions_Database_TestCase

View file

@ -2,7 +2,7 @@
namespace Tests\b8; namespace Tests\b8;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Database; use PHPCensor\Database;
class DatabasePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase class DatabasePostgresqlTest extends \PHPUnit_Extensions_Database_TestCase

View file

@ -2,7 +2,7 @@
namespace Tests\PHPCensor\Plugin; namespace Tests\PHPCensor\Plugin;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Plugin; use PHPCensor\Plugin;
use PHPCensor\Plugin\Email as EmailPlugin; use PHPCensor\Plugin\Email as EmailPlugin;
use PHPCensor\Model\Build; use PHPCensor\Model\Build;

View file

@ -2,7 +2,7 @@
namespace Tests\PHPCensor; namespace Tests\PHPCensor;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Database; use PHPCensor\Database;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\Model\Project; use PHPCensor\Model\Project;

View file

@ -2,7 +2,7 @@
namespace Tests\PHPCensor; namespace Tests\PHPCensor;
use b8\Config; use PHPCensor\Config;
use PHPCensor\Database; use PHPCensor\Database;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\Model\Project; use PHPCensor\Model\Project;

View file

@ -33,7 +33,7 @@ $conf['b8']['app']['default_controller'] = 'Home';
$conf['b8']['view']['path'] = SRC_DIR . 'View/'; $conf['b8']['view']['path'] = SRC_DIR . 'View/';
$conf['php-censor']['url'] = 'http://php-censor.local'; $conf['php-censor']['url'] = 'http://php-censor.local';
$config = new b8\Config($conf); $config = new PHPCensor\Config($conf);
if (!defined('APP_URL')) { if (!defined('APP_URL')) {
define('APP_URL', $config->get('php-censor.url', '') . '/'); define('APP_URL', $config->get('php-censor.url', '') . '/');