This commit is contained in:
Dennis Eichhorn 2016-02-12 12:16:16 +01:00
parent f4df9a6f84
commit 1535d8fdbe
22 changed files with 262 additions and 119 deletions

View File

@ -26,7 +26,7 @@ namespace phpOMS\Account;
* @link http://orange-management.com
* @since 1.0.0
*/
class AccountManager
class AccountManager implements \Countable
{
/**
@ -83,4 +83,37 @@ class AccountManager
return null;
}
/**
* Remove account.
*
* @param int $id Account id
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function remove(int $id) : bool
{
if (isset($this->accounts[$id])) {
unset($this->accounts[$id]);
return true;
}
return false;
}
/**
* Get accounts count.
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function count() : int {
return count($this->accounts);
}
}

View File

@ -32,7 +32,7 @@ class ApplicationAbstract
/**
* App name.
*
* @var \phpOMS\DataStorage\Database\Pool
* @var string
* @since 1.0.0
*/
public $appName = '';

View File

@ -39,7 +39,7 @@ abstract class SettingsAbstract implements OptionsInterface
/**
* Cache manager (pool).
*
* @var \phpOMS\DataStorage\Cache\CacheManager
* @var \phpOMS\DataStorage\Cache\Pool
* @since 1.0.0
*/
protected $cache = null;

View File

@ -30,10 +30,16 @@ use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
*/
abstract class BuilderAbstract
{
/**
* Grammar.
*
* @var GrammarAbstract
* @since 1.0.0
*/
protected $grammar = null;
/**
* Database connectino.
* Database connection.
*
* @var ConnectionAbstract
* @since 1.0.0
@ -61,7 +67,7 @@ abstract class BuilderAbstract
*
* @param string $prefix Prefix
*
* @return BuilderAbstract
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>

View File

@ -226,7 +226,8 @@ abstract class DataMapperAbstract implements DataMapperInterface
/**
* Create object in db.
*
* @param mixed $obj Object reference (gets filled with insert id)
* @param mixed $obj Object reference (gets filled with insert id)
* @param bool $relations Create all relations as well
*
* @return mixed
*
@ -256,11 +257,13 @@ abstract class DataMapperAbstract implements DataMapperInterface
/* Insert has one first */
if (isset(static::$hasOne[$pname]) && is_object($relObj = $property->getValue($obj))) {
/* only insert if not already inserted */
/** @var DataMapperAbstract $mapper */
$mapper = static::$hasOne[$pname]['mapper'];
$mapper = new $mapper($this->db);
$relReflectionClass = new \ReflectionClass(get_class($relObj));
$relProperty = $relReflectionClass->getProperty($mapper::$columns[$mapper::$primaryField]['internal']);
/** @var array $columns */
$relProperty = $relReflectionClass->getProperty($mapper::$columns[$mapper::$primaryField]['internal']);
$relProperty->setAccessible(true);
$primaryKey = $relProperty->getValue($relObj);
$relProperty->setAccessible(false);
@ -327,6 +330,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
foreach ($values as $key => &$value) {
// Skip if already in db/has key
/** @noinspection PhpUndefinedVariableInspection */
$relProperty = $relReflectionClass->getProperty($mapper::$columns[$mapper::$primaryField]['internal']);
$relProperty->setAccessible(true);
$primaryKey = $relProperty->getValue($value);
@ -552,6 +556,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
$reflectionProperty->setAccessible(true);
}
/** @var DataMapperAbstract $mapper */
$mapper = static::$hasOne[$column]['mapper'];
$mapper = new $mapper($this->db);
@ -792,6 +797,16 @@ abstract class DataMapperAbstract implements DataMapperInterface
return $this->populateIterable($results);
}
/**
* Get raw by primary key
*
* @param mixed $primaryKey Primary key
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getManyRaw($primaryKey) : array
{
$result = [];

View File

@ -31,7 +31,17 @@ namespace phpOMS\Datatypes\Exception;
class InvalidEnumName extends \UnexpectedValueException
{
public function __construct($message, $code = 0, \Exception $previous = null)
/**
* Constructor.
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception Previous exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(string $message, int $code = 0, \Exception $previous = null)
{
parent::__construct('The enum name "' . $message . '" is not valid.', $code, $previous);
}

View File

@ -31,7 +31,17 @@ namespace phpOMS\Datatypes\Exception;
class InvalidEnumValue extends \UnexpectedValueException
{
public function __construct($message, $code = 0, \Exception $previous = null)
/**
* Constructor.
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception Previous exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(string $message, int $code = 0, \Exception $previous = null)
{
parent::__construct('The enum value "' . $message . '" is not valid.', $code, $previous);
}

View File

@ -30,7 +30,20 @@ namespace phpOMS\Datatypes;
*/
class SmartDateTime extends \DateTime
{
/**
* Default format
*
* @var string
* @since 1.0.0
*/
const FORMAT = 'Y-m-d hh:mm:ss';
/**
* Default timezone
*
* @var string
* @since 1.0.0
*/
const TIMEZONE = 'UTC';
/**
@ -103,4 +116,30 @@ class SmartDateTime extends \DateTime
return $this;
}
/**
* Get days of current month
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDaysOfMonth() : int
{
return cal_days_in_month(CAL_GREGORIAN, $this->format('m'), $this->format('Y'));
}
/**
* Get first day of current month
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getFirstDayOfMonth() : int
{
return getdate(mktime(null, null, null, $this->format('m'), 1, $this->format('Y')))['wday'];
}
}

View File

@ -71,9 +71,9 @@ class Dispatcher
* Dispatch controller.
*
* @param string|array|\Closure $controller Controller string
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Data
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Data
*
* @return array
*
@ -94,11 +94,13 @@ class Dispatcher
$dispatch = explode(':', $controller);
$this->get($dispatch[0]);
if (count($dispatch) == 3) {
if (($c = count($dispatch)) == 3) {
/* Handling static functions */
$views[$type][$controller] = $dispatch[0]::$dispatch[2]();
} else {
} elseif ($c == 2) {
$views[$type][$controller] = $this->controllers[$dispatch[0]]->{$dispatch[1]}($request, $response, $data);
} else {
throw new \UnexpectedValueException('Unexpected function.');
}
} elseif (is_array($controller)) {
foreach ($controller as $controllerSingle) {
@ -142,7 +144,7 @@ class Dispatcher
* Set controller by alias.
*
* @param ModuleAbstract $controller Controller
* @param string $name Controller string
* @param string $name Controller string
*
* @return bool
*

View File

@ -611,12 +611,23 @@ class FileLogger implements LoggerInterface
return $log;
}
public function console(string $text, bool $verbose)
/**
* Create console log.
*
* @param string $message Log message
* @param bool $verbose Is verbose
* @param array $context Context
*
* @return array
*/
public function console(string $message, bool $verbose = true, array $context = [])
{
$text = date('[Y-m-d H:i:s] ') . $text . "\r\n";
$message = date('[Y-m-d H:i:s] ') . $message . "\r\n";
if ($verbose) {
echo $text;
echo $message;
} else {
$this->info($message, $context);
}
}
}

View File

@ -1 +0,0 @@
# Log #

View File

@ -1 +0,0 @@
# Math #

View File

@ -14,7 +14,9 @@
* @link http://orange-management.com
*/
namespace phpOMS\Module;
use phpOMS\System\FilePathException;
use phpOMS\Utils\ArrayUtils;
use phpOMS\Validation\Validator;
/**
@ -34,20 +36,20 @@ class InfoManager
{
/**
* File pointer.
*
* @var mixed
* @since 1.0.0
*/
private $fp = null;
/**
* Module path.
* File path.
*
* @var string
* @since 1.0.0
*/
const MODULE_PATH = __DIR__ . '/../../Modules/';
private $path = '';
/**
* Info data.
*
* @var array
* @since 1.0.0
*/
private $info = [];
/**
* Object constructor.
@ -59,26 +61,54 @@ class InfoManager
*/
public function __construct(string $module)
{
if (($path = realpath($oldPath = self::MODULE_PATH . $module . '/info.json')) === false || Validator::startsWith($path, self::MODULE_PATH)) {
if (($path = realpath($oldPath = ModuleAbstract::MODULE_PATH . '/' . $module . '/info.json')) === false || Validator::startsWith($path, ModuleAbstract::MODULE_PATH)) {
throw new FilePathException($oldPath);
}
$this->fp = fopen($oldPath, 'r');
}
public function update()
{
// TODO: update file (convert to json)
$this->path = $path;
$this->info = json_decode(file_get_contents($this->path), true);
}
/**
* Object destructor.
* Update info file
*
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function __destruct()
public function update()
{
$this->fp->close();
file_put_contents($this->path, json_encode($this->info, JSON_PRETTY_PRINT));
}
/**
* Set data
*
* @param string $path Value path
* @param mixed $data Scalar or array of data to set
* @param string $delim Delimiter of path
*
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function set(string $path, $data, string $delim = '/')
{
if (!is_scalar($data) || !is_array($data)) {
throw new \InvalidArgumentException('Type of $data "' . gettype($data) . '" is not supported.');
}
ArrayUtils::setArray($path, $this->info, $data, $delim);
}
/**
* Get info data.
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function get() : array
{
return $this->info;
}
}

View File

@ -14,6 +14,7 @@
* @link http://orange-management.com
*/
namespace phpOMS\Module;
use phpOMS\System\FilePathException;
@ -61,7 +62,7 @@ abstract class ModuleAbstract
* @var string
* @since 1.0.0
*/
const MODULE_PATH = __DIR__;
const MODULE_PATH = __DIR__ . '/../../Modules';
/**
* Module version.
@ -148,8 +149,9 @@ abstract class ModuleAbstract
{
$lang = [];
if (isset(static::$localization[$destination])) {
/** @noinspection PhpUnusedLocalVariableInspection */
foreach (static::$localization[$destination] as $file) {
if(($path = realpath($oldPath = __DIR__ . '/../../Modules/' . static::MODULE_NAME . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) === false) {
if (($path = realpath($oldPath = __DIR__ . '/../../Modules/' . static::MODULE_NAME . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) === false) {
throw new FilePathException($oldPath);
}
@ -197,4 +199,17 @@ abstract class ModuleAbstract
/** @noinspection PhpUndefinedFieldInspection */
return static::$dependencies;
}
/**
* Get event id prefix.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getEventId() : string
{
return static::class;
}
}

View File

@ -16,8 +16,6 @@
namespace phpOMS\Module;
use phpOMS\ApplicationAbstract;
use phpOMS\Module\NullModule;
/**
* ModuleFactory class.

View File

@ -22,7 +22,6 @@ use phpOMS\Message\Http\Request;
use phpOMS\System\FilePathException;
use phpOMS\Utils\IO\Json\InvalidJsonException;
/**
* Modules class.
*

View File

@ -21,8 +21,6 @@ namespace phpOMS\Stdlib;
* @category Stdlib
* @package Framework
* @since 1.0.0
*
* @todo : implement JsonableInterface
*/
class PriorityQueue implements \Countable, \Serializable
{

View File

@ -30,7 +30,17 @@ namespace phpOMS\System;
*/
class FilePathException extends \UnexpectedValueException
{
public function __construct($message, $code = 0, \Exception $previous = null)
/**
* Constructor.
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception Previous exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(string $message, int $code = 0, \Exception $previous = null)
{
parent::__construct('The path "' . $message . '" is not a valid path.', $code, $previous);
}

View File

@ -48,7 +48,7 @@ class FileSystem
*
* @param string $path Path to folder
* @param bool $recursive Should sub folders be counted as well?
* @param array $ignore Ignore these sub-paths
* @param array $ignore Ignore these sub-paths
*
* @return int
*
@ -56,7 +56,7 @@ class FileSystem
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getFileCount(string $path, bool $recursive = true, array $ignore = ['.', '..', 'cgi-bin',
'.DS_Store'])
'.DS_Store'])
{
$size = 0;
$files = scandir($path);
@ -77,23 +77,21 @@ class FileSystem
return $size;
}
public function copy()
{
}
public function rename()
{
}
public function move()
{
}
/**
* Delete directory and all its content.
*
* @param string $path Path to folder
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function deletePath($path) : bool
{
$path = realpath($oldPath = $path);
if ($path === false || !is_dir($path) || Validator::startsWith($path, ROOT_PATH)) {
return false;
throw new FilePathException($oldPath);
}
$files = scandir($path);
@ -114,52 +112,4 @@ class FileSystem
return true;
}
public function touch()
{
}
public function mkdir()
{
}
public function exists()
{
}
public function chmod()
{
}
public function chown()
{
}
public function chgrp()
{
}
public function symlink()
{
}
public function toRelative()
{
}
public function toAbsolute()
{
}
public function isRelative()
{
}
public function isAbsolute()
{
}
public function dump()
{
}
}

View File

@ -28,7 +28,17 @@ namespace phpOMS\Uri;
*/
class InvalidUriException extends \UnexpectedValueException
{
public function __construct($message, $code = 0, \Exception $previous = null)
/**
* Constructor.
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception Previous exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(string $message, int $code = 0, \Exception $previous = null)
{
parent::__construct('The uri "' . $message . '" is not valid.', $code, $previous);
}

View File

@ -15,8 +15,6 @@
*/
namespace phpOMS\Uri;
/**
* UriFactory class.
*
@ -93,8 +91,7 @@ class UriFactory
* Build uri.
*
* @param string $uri Path data
* @param array $toMatch Optional special replacements
* @param UriScheme|int $scheme Scheme type
* @param array $toMatch Optional special replacements
*
* @return null|string
*
@ -103,7 +100,7 @@ class UriFactory
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function build(string $uri, array $toMatch = [], int $scheme = UriScheme::HTTP)
public static function build(string $uri, array $toMatch = [])
{
$uri = preg_replace_callback('(\{[\/#\?@\.\$][a-zA-Z0-9]*\})', function ($match) use ($toMatch) {
$match = substr($match[0], 1, strlen($match[0]) - 2);

View File

@ -22,9 +22,21 @@ namespace phpOMS\Utils\IO\Csv;
* @package phpOMS\Config
* @since 1.0.0
*/
trait CsvSettingsTrait
class CsvSettings
{
private function getFileDelimiter($file, int $checkLines = 2, array $delimiters = [',', '\t', ';', '|', ':']) : string
/**
* Get csv file delimiter.
*
* @param mixed $file File resource
* @param int $checkLines Lines to check for evaluation
* @param array $delimiters Potential delimiters
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn
*/
public static function getFileDelimiter($file, int $checkLines = 2, array $delimiters = [',', '\t', ';', '|', ':']) : string
{
$results = [];