Refactored structure

This commit is contained in:
Dmitry Khomutov 2016-04-17 12:34:12 +06:00
parent 963225382c
commit e5164ae1dd
329 changed files with 276 additions and 456 deletions

14
.gitignore vendored
View file

@ -1,19 +1,17 @@
.idea
vendor/
composer.phar
config.php
.DS_Store
.settings/
.project
.buildpath
.htaccess
PHPCI/config.yml
app/config.yml
cache
/loggerconfig.php
/pluginconfig.php
PHPCI/Model/Migration.php
PHPCI/Model/Base/MigrationBase.php
PHPCI/Store/MigrationStore.php
PHPCI/Store/Base/MigrationStoreBase.php
src/PHPCI/Model/Migration.php
src/PHPCI/Model/Base/MigrationBase.php
src/PHPCI/Store/MigrationStore.php
src/PHPCI/Store/Base/MigrationStoreBase.php
local_vars.php
Tests/PHPCI/config.yml
tests/PHPCI/config.yml

View file

@ -1,115 +0,0 @@
<?php
namespace b8\Cache;
use b8\Type;
class ApcCache implements Type\Cache
{
/**
* Check if caching is enabled.
*/
public function isEnabled()
{
$rtn = false;
$apcCli = ini_get('apc.enable_cli');
if( function_exists('apc_fetch') &&
(php_sapi_name() != 'cli' || in_array($apcCli, array('1', 1, true, 'On'))))
{
$rtn = true;
}
return $rtn;
}
/**
* Get item from the cache:
*/
public function get($key, $default = null)
{
if (!$this->isEnabled()) {
return $default;
}
$success = false;
$rtn = apc_fetch($key, $success);
if (!$success) {
$rtn = $default;
}
return $rtn;
}
/**
* Add an item to the cache:
*/
public function set($key, $value = null, $ttl = 0)
{
if (!$this->isEnabled()) {
return false;
}
return apc_store($key, $value, $ttl);
}
/**
* Remove an item from the cache:
*/
public function delete($key)
{
if (!$this->isEnabled()) {
return false;
}
return apc_delete($key);
}
/**
* Check if an item is in the cache:
*/
public function contains($key)
{
if (!$this->isEnabled()) {
return false;
}
return apc_exists($key);
}
/**
* Short-hand syntax for get()
* @see Config::get()
*/
public function __get($key)
{
return $this->get($key, null);
}
/**
* Short-hand syntax for set()
* @see Config::set()
*/
public function __set($key, $value = null)
{
return $this->set($key, $value);
}
/**
* Is set
*/
public function __isset($key)
{
return $this->contains($key);
}
/**
* Unset
*/
public function __unset($key)
{
$this->delete($key);
}
}

View file

@ -1,87 +0,0 @@
<?php
namespace b8;
use b8\Config;
use b8\Http\Request;
if (!defined('B8_PATH')) {
define('B8_PATH', dirname(__FILE__) . '/');
}
/**
* b8\Registry is now deprecated in favour of using the following classes:
* @see b8\Http\Request
* @see b8\Http\Response
* @see b8\Config
*/
class Registry
{
/**
* @var Registry
*/
protected static $instance;
protected $_data = array();
protected $_params = null;
/**
* @var Config
*/
protected $config;
/**
* @var Request
*/
protected $request;
/**
* @return Registry
*/
public static function getInstance()
{
return self::$instance;
}
public function __construct(Config $config, Request $request)
{
$this->config = $config;
$this->request = $request;
self::$instance = $this;
}
public function get($key, $default = null)
{
return $this->config->get($key, $default);
}
public function set($key, $value)
{
return $this->config->set($key, $value);
}
public function setArray($array)
{
return $this->config->set($array);
}
public function getParams()
{
return $this->request->getParams();
}
public function getParam($key, $default)
{
return $this->request->getParam($key, $default);
}
public function setParam($key, $value)
{
return $this->request->setParam($key, $value);
}
public function unsetParam($key)
{
return $this->request->unsetParam($key);
}
}

View file

@ -1,54 +0,0 @@
<?php
require_once(dirname(__FILE__) . '/../b8/Registry.php');
require_once(dirname(__FILE__) . '/../b8/Database.php');
class DatabaseTest extends \PHPUnit_Framework_TestCase
{
protected $_host = 'localhost';
protected $_user = 'b8_test';
protected $_pass = 'b8_test';
protected $_name = 'b8_test';
public function testGetReadConnection()
{
\b8\Database::setDetails($this->_name, $this->_user, $this->_pass);
\b8\Database::setReadServers(array($this->_host));
$connection = \b8\Database::getConnection('read');
$this->assertInstanceOf('\b8\Database', $connection);
}
public function testGetWriteConnection()
{
\b8\Database::setDetails($this->_name, $this->_user, $this->_pass);
\b8\Database::setWriteServers(array($this->_host));
$connection = \b8\Database::getConnection('write');
$this->assertInstanceOf('\b8\Database', $connection);
}
public function testGetDetails()
{
\b8\Database::setDetails($this->_name, $this->_user, $this->_pass);
\b8\Database::setReadServers(array('localhost'));
$details = \b8\Database::getConnection('read')->getDetails();
$this->assertTrue(is_array($details));
$this->assertTrue(($details['db'] == $this->_name));
$this->assertTrue(($details['user'] == $this->_user));
$this->assertTrue(($details['pass'] == $this->_pass));
}
/**
* @expectedException \Exception
*/
public function testConnectionFailure()
{
\b8\Database::setDetails('non_existant', 'invalid_user', 'incorrect_password');
\b8\Database::setReadServers(array('localhost'));
\b8\Database::getConnection('read');
}
}

View file

@ -1,82 +0,0 @@
<?php
require_once(dirname(__FILE__) . '/../b8/Registry.php');
use b8\Registry;
class RegistryTest extends \PHPUnit_Framework_TestCase
{
public function testSingleton()
{
Registry::forceReset();
$instance = Registry::getInstance();
$instance->set('test', true);
$instance2 = Registry::getInstance();
$this->assertTrue($instance2->get('test', false));
}
public function testStoreAndRetrieve()
{
Registry::forceReset();
$r = Registry::getInstance();
$r->set('test', 'cat');
$this->assertTrue($r->get('test', 'dog') == 'cat');
}
public function testSetArray()
{
Registry::forceReset();
$r = Registry::getInstance();
$r->set('one', 'two');
$r->setArray(array('test' => 'cat'));
$this->assertTrue($r->get('test', 'dog') == 'cat');
$this->assertTrue($r->get('one', 'three') == 'two');
}
public function testGetNonExistent()
{
Registry::forceReset();
$r = Registry::getInstance();
$this->assertTrue(!$r->get('cat', false));
}
public function testGetParams()
{
Registry::forceReset();
$_REQUEST = array();
$_REQUEST['cat'] = 'dog';
$_SERVER['REQUEST_METHOD'] = 'GET';
$r = Registry::getInstance();
$params = $r->getParams();
$this->assertTrue(is_array($params));
$this->assertArrayHasKey('cat', $params);
$this->assertArrayNotHasKey('dog', $params);
}
public function testEmptyInput()
{
Registry::forceReset();
$r = Registry::getInstance();
$params = $r->getParams();
$this->assertTrue(is_array($params));
$this->assertTrue(!count($params));
}
public function testGetSetUnsetParam()
{
Registry::forceReset();
$r = Registry::getInstance();
$this->assertTrue($r->getParam('cat', false) == false);
$r->setParam('cat', 'dog');
$this->assertTrue($r->getParam('cat', false) == 'dog');
$r->unsetParam('cat');
$this->assertTrue($r->getParam('cat', false) == false);
}
}

View file

@ -1,2 +0,0 @@
*
!.gitignore

View file

View file

@ -15,7 +15,7 @@ if (empty($timezone)) {
date_default_timezone_set('UTC');
}
$configFile = dirname(__FILE__) . '/PHPCI/config.yml';
$configFile = dirname(__FILE__) . '/app/config.yml';
$configEnv = getenv('phpci_config_file');
$usingCustomConfigFile = false;
@ -54,7 +54,7 @@ if (defined('PHPCI_IS_CONSOLE') && PHPCI_IS_CONSOLE) {
$conf = array();
$conf['b8']['app']['namespace'] = 'PHPCI';
$conf['b8']['app']['default_controller'] = 'Home';
$conf['b8']['view']['path'] = dirname(__FILE__) . '/PHPCI/View/';
$conf['b8']['view']['path'] = dirname(__FILE__) . '/src/PHPCI/View/';
$conf['using_custom_file'] = $usingCustomConfigFile;
$config = new b8\Config($conf);

View file

@ -21,14 +21,14 @@
},
"autoload": {
"psr-4": {
"PHPCI\\": "PHPCI/",
"b8\\": "B8Framework/b8/"
"PHPCI\\": "src/PHPCI/",
"b8\\": "src/B8Framework/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\PHPCI\\": "Tests/PHPCI/",
"Tests\\b8\\": "B8Framework/tests/"
"Tests\\PHPCI\\": "tests/PHPCI/",
"Tests\\b8\\": "tests/B8Framework/"
}
},
"require": {

2
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "8284c7c2c1947ad6dab0eaa67bc2d268",
"hash": "1a7e6ffa53784a02d845d40fc34455f1",
"content-hash": "aea45980fd51944fe67aeb4a0677ec88",
"packages": [
{

View file

@ -1,33 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./Tests/bootstrap.php"
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./Tests/bootstrap.php"
>
<testsuites>
<testsuite name="PHPCI Command Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Command</directory>
</testsuite>
<testsuite name="PHPCI Controller Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Controller</directory>
</testsuite>
<testsuite name="PHPCI Helper Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Helper</directory>
</testsuite>
<testsuite name="PHPCI Logging Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Logging</directory>
</testsuite>
<testsuite name="PHPCI Plugin Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Plugin</directory>
</testsuite>
<testsuite name="PHPCI Model Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Model</directory>
</testsuite>
<testsuite name="PHPCI Plugin Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Plugin</directory>
</testsuite>
<!--<testsuite name="PHPCI ProcessControl Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/ProcessControl</directory>
</testsuite>-->
<testsuite name="PHPCI Service Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Service</directory>
</testsuite>
<!--<testsuite name="B8Framework Test Suite">
<directory suffix="Test.php">./B8Framework/tests</directory>
</testsuite>-->
</testsuites>
</phpunit>

0
runtime/builds/.gitkeep Normal file
View file

View file

@ -0,0 +1,149 @@
<?php
namespace b8\Cache;
use b8\Type;
class ApcCache implements Type\Cache
{
/**
* Check if caching is enabled.
*
* @return boolean
*/
public function isEnabled()
{
$rtn = false;
$apcCli = ini_get('apc.enable_cli');
if (function_exists('apc_fetch') && (php_sapi_name() != 'cli' || in_array($apcCli, array('1', 1, true, 'On')))) {
$rtn = true;
}
return $rtn;
}
/**
* Get item from the cache:
*
* @param string $key
* @param mixed $default
*
* @return mixed
*/
public function get($key, $default = null)
{
if (!$this->isEnabled()) {
return $default;
}
$success = false;
$rtn = apc_fetch($key, $success);
if (!$success) {
$rtn = $default;
}
return $rtn;
}
/**
* Add an item to the cache:
*
* @param string $key
* @param mixed $value
* @param integer $ttl
*
* @return array|bool
*/
public function set($key, $value = null, $ttl = 0)
{
if (!$this->isEnabled()) {
return false;
}
return apc_store($key, $value, $ttl);
}
/**
* Remove an item from the cache:
*
* @param string $key
*
* @return bool|string[]
*/
public function delete($key)
{
if (!$this->isEnabled()) {
return false;
}
return apc_delete($key);
}
/**
* Check if an item is in the cache:
*
* @param string $key
*
* @return bool|string[]
*/
public function contains($key)
{
if (!$this->isEnabled()) {
return false;
}
return apc_exists($key);
}
/**
* Short-hand syntax for get()
*
* @see Config::get()
*
* @param string $key
*
* @return mixed
*/
public function __get($key)
{
return $this->get($key, null);
}
/**
* Short-hand syntax for set()
*
* @see Config::set()
*
* @param string $key
* @param mixed $value
*
* @return array|bool
*/
public function __set($key, $value = null)
{
return $this->set($key, $value);
}
/**
* Is set
*
* @param string $key
*
* @return bool|string[]
*/
public function __isset($key)
{
return $this->contains($key);
}
/**
* Unset
*
* @param string $key
*/
public function __unset($key)
{
$this->delete($key);
}
}

Some files were not shown because too many files have changed in this diff Show more