Commit e4612c77 authored by Jamie Carl's avatar Jamie Carl

Merge branch 'master' into 2.4-stable

parents 707a8871 cb422971
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -461,10 +461,7 @@ class Application {
if(setlocale(LC_ALL, $locale) === FALSE)
throw new \Exception("Unable to set locale to $locale. Make sure the $locale locale is enabled on your system.");
if($this->config->app->has('timezone'))
$tz = $this->config->app->timezone;
else
$tz = 'UTC';
$tz = $this->config->app->has('timezone') ? $this->config->app->timezone : 'UTC';
if(!date_default_timezone_set($tz))
throw new Application\Exception\BadTimezone($tz);
......
......@@ -14,7 +14,7 @@ class Controller extends \Hazaar\Controller\Action {
$this->handler = new Handler();
if($this->request->getActionName() == 'login')
if($this->request->getActionName() === 'login')
return;
if(!$this->handler->authenticated())
......
......@@ -151,7 +151,7 @@ abstract class Controller implements Controller\_Interface {
}
if(! $controller)
$controller = strtolower($this->getName());
$controller = strtolower($this->request->getControllerName());
return $this->application->url($controller, $method, $params, $this->base_path);
......
......@@ -105,7 +105,7 @@ abstract class Basic extends \Hazaar\Controller {
* default controller so check for the __default() method. Then check if the action method exists
* and if not check for the __default() method.
*/
if(ucfirst($this->name) . 'Controller' !== get_class($this) || !method_exists($this, $action)) {
if($this->request->getControllerName() !== $this->name || !method_exists($this, $action)) {
if(method_exists($this, '__default')) {
......
......@@ -25,6 +25,8 @@ class File {
protected $handle;
protected $relative_path;
/*
* Encryption bits
*/
......@@ -34,7 +36,7 @@ class File {
private $encrypted = false;
function __construct($file = null, File\Backend\_Interface $backend = NULL, File\Manager $manager = null) {
function __construct($file = null, File\Backend\_Interface $backend = NULL, File\Manager $manager = null, $relative_path = null) {
if($file instanceof \Hazaar\File) {
......@@ -77,6 +79,8 @@ class File {
}
$this->relative_path = rtrim(str_replace('\\', '/', $relative_path), '/');
}
public function __destruct(){
......@@ -144,7 +148,38 @@ class File {
$dir = $this->dirname();
return $dir . ((substr($dir, -1, 1) != '/') ? '/' : NULL) . $this->basename();
return trim($dir, '/') . '/' . $this->basename();
}
public function relativepath(){
if(!$this->relative_path)
return $this->fullpath();
$dir_parts = explode('/', $this->dirname());
$rel_parts = explode('/', $this->relative_path);
$path = null;
foreach($dir_parts as $index => $part){
if(array_key_exists($index, $rel_parts) && $rel_parts[$index] === $part)
continue;
$dir_parts = array_slice($dir_parts, $index);
if(($count = count($rel_parts) - $index) > 0)
$dir_parts = array_merge(array_fill(0, $count, '..'), $dir_parts);
$path = implode('/', $dir_parts);
break;
}
return ($path ? $path . '/' : '') . $this->basename();
}
......
......@@ -194,7 +194,7 @@ class Dir {
}
return new \Hazaar\File($this->fixPath($this->path, $file), $this->backend, $this->manager);
return new \Hazaar\File($this->fixPath($this->path, $file), $this->backend, $this->manager, $this->path);
}
......@@ -251,7 +251,7 @@ class Dir {
} elseif(! fnmatch($pattern, $file))
continue;
$list[] = new \Hazaar\File($start . $file, $this->backend, $this->manager);
$list[] = new \Hazaar\File($start . $file, $this->backend, $this->manager, $this->path);
}
......@@ -327,7 +327,7 @@ class Dir {
if($force_dir === true || (file_exists($path) && is_dir($path)))
return new \Hazaar\File\Dir($path, $this->backend, $this->manager);
return new \Hazaar\File($this->path($child), $this->backend, $this->manager);
return new \Hazaar\File($this->path($child), $this->backend, $this->manager, $this->path);
}
......
......@@ -1463,4 +1463,63 @@ function recursive_iterator_to_array(\Traversable $it) {
return $result;
}
/**
* Recursivly computes the difference of arrays with additional index check
*
* Compares `array1` against `array2` and returns the difference. Unlike array_diff() the array keys are also used
* in the comparison. Also, unlike the PHP array_diff_assoc() function, this function recurse into child arrays.
*
* @param array array1 The array to compare from.
*
* @param array array2 The array to compare against.
*
* @param array ... More arrays to compare against.
*
* @return array
*
* @author Diego Dias <diego.dias@apir.com.au>
*
* @since 2.4.1
*/
function array_diff_assoc_recursive() {
$arrays = func_get_args();
$array1 = array_shift($arrays);
$difference = array();
foreach($arrays as $array_compare){
foreach($array1 as $key => $value) {
if(is_array($value)) {
if(!isset($array_compare[$key]) || !is_array($array_compare[$key])){
$difference[$key] = $value;
}else{
$new_diff = array_diff_assoc_recursive($value, $array_compare[$key]);
if(!empty($new_diff))
$difference[$key] = $new_diff;
}
}elseif(!array_key_exists($key, $array_compare) || $array_compare[$key] !== $value){
$difference[$key] = $value;
}
}
}
return $difference;
}
\ No newline at end of file
......@@ -528,7 +528,9 @@ class Loader {
*/
if(boolify($this->application->config->app->useDefaultController)){
$controllerClass = ucfirst($this->application->config->app->defaultController) . 'Controller';
$controller = $this->application->config->app->defaultController;
$controllerClass = ucfirst($this->application->config->app->defaultController) . 'Controller';
if(! class_exists($controllerClass))
return FALSE;
......
......@@ -56,6 +56,17 @@ class DataBinderValue implements \JsonSerializable {
if(array_key_exists('__hz_label', $value))
$value = $value['__hz_value'];
}elseif($value instanceof \stdClass){
if(property_exists($value, '__hz_other'))
$other = $value->__hz_other;
if(property_exists($value, '__hz_value'))
$label = $value->__hz_label;
if(property_exists($value, '__hz_label'))
$value = $value->__hz_value;
}
return new DataBinderValue($value, $label, $other);
......
......@@ -44,7 +44,8 @@ abstract class DataTypeConverter {
if (in_array($type, DataTypeConverter::$known_types)) {
if(is_array($value) && array_key_exists('__hz_value', $value)){
if((is_array($value) && array_key_exists('__hz_value', $value))
|| ($value instanceof \stdClass && property_exists($value, '__hz_value'))){
if($type !== 'array'){
......
......@@ -123,7 +123,7 @@ abstract class Strict extends DataTypeConverter implements \ArrayAccess, \Iterat
*/
public function populate($data, $exec_filters = false) {
if (!\Hazaar\Map::is_array($data))
if (!(\Hazaar\Map::is_array($data) || $data instanceof \stdClass))
return false;
foreach($data as $key => $value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment