Skip to content

Commit

Permalink
Merge pull request #254 from AntonShevchuk/master
Browse files Browse the repository at this point in the history
Milestone 0.5.0
  • Loading branch information
Anton authored and Anton committed Sep 23, 2014
2 parents cf90363 + 9423e45 commit a280d0b
Show file tree
Hide file tree
Showing 63 changed files with 1,775 additions and 844 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"ext-gettext": "required by Bluz\\Translator (https://github.com/bluzphp/framework/wiki/Translator)",
"ext-redis": "required by Redis adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)",
"ext-memcached": "required by Memcached adapter for Bluz\\Cache (https://github.com/bluzphp/framework/wiki/Cache)",
"phpmailer/phpmailer": "required by Bluz\\Mailer (https://github.com/bluzphp/framework/wiki/Mailer)"
"phpmailer/phpmailer": "required by Bluz\\Mailer (https://github.com/bluzphp/framework/wiki/Mailer)",
"predis/predis": "required by Cache\\Adapter\\Predis ()"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 16 additions & 8 deletions src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ public function init($environment = 'production')
// first log message
$this->log('app:init');

// initial php settings
if ($ini = $this->getConfigData('php')) {
foreach ($ini as $key => $value) {
$result = ini_set($key, $value);
$this->log('app:init:php:'.$key.':'.($result?:'---'));
}
}

// initial session, start inside class
$this->getSession();

Expand Down Expand Up @@ -254,8 +262,9 @@ public function getConfig($environment = null)
{
if (!$this->config) {
$this->config = new Config();
$this->config->setPath($this->getPath() . '/configs');
$this->config->load($environment);
$this->config->setPath($this->getPath());
$this->config->setEnvironment($environment);
$this->config->init();
}
return $this->config;
}
Expand Down Expand Up @@ -378,11 +387,10 @@ public function resetLayout()
public function getLogger()
{
if (!$this->logger) {
$config = $this->getConfigData('logger');
if (!isset($config['enabled']) or !$config['enabled']) {
$this->logger = new Nil();
} else {
if ($this->getConfigData('logger')) {
$this->logger = new Logger();
} else {
$this->logger = new Nil();
}
}
return $this->logger;
Expand Down Expand Up @@ -973,7 +981,7 @@ public function render()
*/
public function widget($module, $widget, $params = array())
{
$this->log(__METHOD__ . ": " . $module . '/' . $widget);
$this->log("app:widget: " . $module . '/' . $widget);
$widgetFile = $this->getWidgetFile($module, $widget);
$reflectionData = $this->reflection($widgetFile);

Expand Down Expand Up @@ -1038,7 +1046,7 @@ public function widget($module, $widget, $params = array())
*/
public function api($module, $method)
{
$this->log(__METHOD__ . ": " . $module . '/' . $method);
$this->log("app:api: " . $module . '/' . $method);

$this->getEventManager()->trigger(
'api',
Expand Down
28 changes: 1 addition & 27 deletions src/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
*/
namespace Bluz\Cache\Adapter;

use Bluz\Cache\InvalidArgumentException;
use Bluz\Cache\Cache;
use Bluz\Cache\CacheInterface;

/**
* Base class for all cache adapters within Bluz\Cache package
*
* @package Bluz\Cache\Adapter
* @author murzik
* @author murzik
*/
abstract class AbstractAdapter implements CacheInterface
{
Expand Down Expand Up @@ -47,7 +46,6 @@ public function __construct($settings = array())
*/
public function get($id)
{
$id = $this->castToString($id);
return $this->doGet($id);
}

Expand All @@ -60,7 +58,6 @@ public function get($id)
*/
public function contains($id)
{
$id = $this->castToString($id);
return $this->doContains($id);
}

Expand All @@ -75,7 +72,6 @@ public function contains($id)
*/
public function add($id, $data, $ttl = Cache::TTL_NO_EXPIRY)
{
$id = $this->castToString($id);
return $this->doAdd($id, $data, $ttl);
}

Expand All @@ -90,7 +86,6 @@ public function add($id, $data, $ttl = Cache::TTL_NO_EXPIRY)
*/
public function set($id, $data, $ttl = Cache::TTL_NO_EXPIRY)
{
$id = $this->castToString($id);
return $this->doSet($id, $data, $ttl);
}

Expand All @@ -103,7 +98,6 @@ public function set($id, $data, $ttl = Cache::TTL_NO_EXPIRY)
*/
public function delete($id)
{
$id = $this->castToString($id);
return $this->doDelete($id);
}

Expand All @@ -117,26 +111,6 @@ public function flush()
return $this->doFlush();
}

/**
* Cast given $inputValue to string.
* @param string $inputValue
* @throws InvalidArgumentException if given $input value not a number or string
* @return string $castedToString
* @internal defence from "fool".
* Attempt to cast to string object will lead to cache entry with id "Object".
* Which is wrong.
*/
protected function castToString($inputValue)
{
if (!is_string($inputValue) && !is_int($inputValue)) {
$msg = "<String> or <Integer> expected. But "
. "<" . gettype($inputValue) . "> given.";
throw new InvalidArgumentException($msg);
}

return (string)$inputValue;
}

/**
* Must be implemented in particular cache driver implementation
* Actual work for \Bluz\Cache\CacheInterface::flush() goes here
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Adapter/Apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* APC cache adapter
*
* @package Bluz\Cache\Adapter
* @author murzik
* @author murzik
*/
class Apc extends AbstractAdapter
{
Expand Down
12 changes: 6 additions & 6 deletions src/Cache/Adapter/FileBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
*/
namespace Bluz\Cache\Adapter;

use Bluz\Cache\InvalidArgumentException;
use Bluz\Config\ConfigException;

/**
* Base class for all filesystem-based cache adapters
*
* @todo http://habrahabr.ru/post/148527/#comment_5014715
*
* @package Bluz\Cache\Adapter
* @author murzik
* @author murzik
*/
abstract class FileBase extends AbstractAdapter
{
Expand All @@ -39,21 +39,21 @@ abstract class FileBase extends AbstractAdapter
* Check configuration and permissions
*
* @param array $settings
* @throws \Bluz\Cache\InvalidArgumentException
* @throws ConfigException
*/
public function __construct($settings = array())
{
if (!isset($settings['cacheDir'])) {
throw new InvalidArgumentException("FileBase adapters is required 'cacheDir' option");
throw new ConfigException("FileBase adapters is required 'cacheDir' option");
}
$cacheDir = $settings['cacheDir'];

if (!is_dir($cacheDir)) {
throw new InvalidArgumentException("'$cacheDir' is not directory");
throw new ConfigException("'$cacheDir' is not directory");
}

if (!is_writable($cacheDir)) {
throw new InvalidArgumentException("Directory '$cacheDir' is not writable");
throw new ConfigException("Directory '$cacheDir' is not writable");
}
// get rid of trailing slash
$this->cacheDir = realpath($cacheDir);
Expand Down
14 changes: 7 additions & 7 deletions src/Cache/Adapter/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Memcached extends AbstractAdapter
* Instance of memcached
* @var \Memcached
*/
protected $memcached = null;
protected $handler = null;

/**
* Check and setup memcached servers
Expand Down Expand Up @@ -59,21 +59,21 @@ public function __construct($settings = array())
*/
public function getHandler()
{
if (!$this->memcached) {
if (!$this->handler) {

$persistentId = isset($this->settings['persistent']) ? $this->settings['persistent'] : null;

$this->memcached = new \Memcached($persistentId);
$this->handler = new \Memcached($persistentId);

if (!$this->memcached->getServerList()) {
$this->memcached->addServers($this->settings['servers']);
if (!$this->handler->getServerList()) {
$this->handler->addServers($this->settings['servers']);
}

if (isset($this->settings['options'])) {
$this->memcached->setOptions($this->settings['options']);
$this->handler->setOptions($this->settings['options']);
}
}
return $this->memcached;
return $this->handler;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Cache/Adapter/PhpFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* It's best to use for scalar data caching
*
* @package Bluz\Cache\Adapter
* @link http://php.net/manual/en/function.var-export.php
* @link http://php.net/manual/en/language.oop5.magic.php#object.set-state
* @author murzik
* @link http://php.net/manual/en/function.var-export.php
* @link http://php.net/manual/en/language.oop5.magic.php#object.set-state
* @author murzik
*/
class PhpFile extends FileBase
{
Expand Down Expand Up @@ -90,7 +90,7 @@ protected function doSet($id, $data, $ttl = Cache::TTL_NO_EXPIRY)
$ttl = time() + $ttl;
}

//if we have an array containing objects - we will have a problem.
// if we have an array containing objects - we will have a problem.
if (is_object($data) && !method_exists($data, '__set_state')) {
throw new InvalidArgumentException(
"Invalid argument given, PhpFileAdapter only allows objects that implement __set_state() " .
Expand Down
Loading

0 comments on commit a280d0b

Please sign in to comment.