Start work toward 2.0

This commit is contained in:
Timothy Warren 2017-02-22 15:41:30 -05:00
parent 6c1de63cf0
commit 023f3f8c69
5 changed files with 53 additions and 15 deletions

View File

@ -7,9 +7,9 @@
* *
* @package Ion * @package Ion
* @author Timothy J. Warren <tim@timshomepage.net> * @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2016 Timothy J. Warren * @copyright 2015 - 2017 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License * @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 1.0.0 * @version 2.0.0
* @link https://git.timshomepage.net/timw4mail/ion * @link https://git.timshomepage.net/timw4mail/ion
*/ */

View File

@ -36,7 +36,9 @@
"henrikbjorn/lurker": "^1.1.0", "henrikbjorn/lurker": "^1.1.0",
"nikic/php-parser": "3.0.*@beta", "nikic/php-parser": "3.0.*@beta",
"monolog/monolog": "1.*", "monolog/monolog": "1.*",
"squizlabs/php_codesniffer": "^3.0.0@RC" "squizlabs/php_codesniffer": "^3.0.0@RC",
"vimeo/psalm": "^0.3.24",
"phpstan/phpstan": "^0.6.4"
}, },
"scripts": { "scripts": {
"coverage": "vendor/bin/phpunit -c build", "coverage": "vendor/bin/phpunit -c build",
@ -47,4 +49,4 @@
"suggest": { "suggest": {
"monolog/monolog": "Provides implementation of psr/log" "monolog/monolog": "Provides implementation of psr/log"
} }
} }

View File

@ -33,9 +33,17 @@ abstract class Enum {
* *
* @return array * @return array
*/ */
protected function getConstList(): array protected static function getConstList(): array
{ {
$reflect = new ReflectionClass($this); static $self;
if (is_null($self))
{
$class = \get_called_class();
$self = new $class;
}
$reflect = new ReflectionClass($self);
return $reflect->getConstants(); return $reflect->getConstants();
} }
@ -44,9 +52,9 @@ abstract class Enum {
* @param mixed $key * @param mixed $key
* @return boolean * @return boolean
*/ */
protected function isValid($key): bool protected static function isValid($key): bool
{ {
$values = array_values($this->getConstList()); $values = array_values(static::getConstList());
return in_array($key, $values); return in_array($key, $values);
} }
} }

View File

@ -39,10 +39,15 @@ trait StaticInstance {
*/ */
public function __call(string $method, array $args) public function __call(string $method, array $args)
{ {
$class = \get_called_class();
if (method_exists($this, $method)) if (method_exists($this, $method))
{ {
return call_user_func_array([$this, $method], $args); return call_user_func_array([$this, $method], $args);
} }
else if(method_exists($class, $method))
{
return static::__callStatic($method, $args);
}
} }
/** /**
@ -55,13 +60,7 @@ trait StaticInstance {
*/ */
public static function __callStatic(string $method, array $args) public static function __callStatic(string $method, array $args)
{ {
$class = get_called_class(); return call_user_func_array([\get_called_class(), $method], $args);
if ( ! array_key_exists($class, self::$instance))
{
self::$instance[$class] = new $class();
}
return call_user_func_array([self::$instance[$class], $method], $args);
} }
} }
// End of StaticInstance.php // End of StaticInstance.php

29
src/functions.php Normal file
View File

@ -0,0 +1,29 @@
<?php declare(strict_types=1);
/**
* Ion
*
* Building blocks for web development
*
* PHP version 7
*
* @package Ion
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2016 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 1.0.0
* @link https://git.timshomepage.net/timw4mail/ion
*/
namespace Aviat\Ion;
/**
* Joins paths together. Variadic to take an
* arbitrary number of arguments
*
* @param string[] ...$args
* @return string
*/
function _dir(...$args)
{
return implode(DIRECTORY_SEPARATOR, $args);
}