Handle open todos

This commit is contained in:
Dennis Eichhorn 2018-06-03 14:22:05 +02:00
parent 7db81b9bdd
commit 3aa3c6b0dd
20 changed files with 108 additions and 93 deletions

View File

@ -126,8 +126,7 @@ class FileCache extends ConnectionAbstract
return;
}
// todo: allow $key to contain / as char and create subdirectory if necessary. This is important for cleaner caching.
$path = File::sanitize($key, self::SANITIZE);
$path = Directory::sanitize($key, self::SANITIZE);
File::put($this->con . '/' . trim($path, '/') . '.cache', $this->build($value, $expire));
}
@ -242,10 +241,10 @@ class FileCache extends ConnectionAbstract
*/
private function getExpire(string $raw) : int
{
$expireStart = strpos($raw, self::DELIM);
$expireEnd = strpos($raw, self::DELIM, $expireStart + 1);
$expireStart = \strpos($raw, self::DELIM);
$expireEnd = \strpos($raw, self::DELIM, $expireStart + 1);
return (int) substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
return (int) \substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
}
/**
@ -273,9 +272,9 @@ class FileCache extends ConnectionAbstract
$raw = File::get($path);
$type = (int) $raw[0];
$expireStart = strpos($raw, self::DELIM);
$expireEnd = strpos($raw, self::DELIM, $expireStart + 1);
$cacheExpire = substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
$expireStart = \strpos($raw, self::DELIM);
$expireEnd = \strpos($raw, self::DELIM, $expireStart + 1);
$cacheExpire = \substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
if ($cacheExpire >= 0 && $created + $cacheExpire < $now) {
$this->delete($key);
@ -303,16 +302,16 @@ class FileCache extends ConnectionAbstract
switch ($type) {
case CacheValueType::_INT:
$value = (int) substr($raw, $expireEnd + 1);
$value = (int) \substr($raw, $expireEnd + 1);
break;
case CacheValueType::_FLOAT:
$value = (float) substr($raw, $expireEnd + 1);
$value = (float) \substr($raw, $expireEnd + 1);
break;
case CacheValueType::_BOOL:
$value = (bool) substr($raw, $expireEnd + 1);
$value = (bool) \substr($raw, $expireEnd + 1);
break;
case CacheValueType::_STRING:
$value = substr($raw, $expireEnd + 1);
$value = \substr($raw, $expireEnd + 1);
break;
case CacheValueType::_ARRAY:
$value = \json_decode(substr($raw, $expireEnd + 1));
@ -322,9 +321,9 @@ class FileCache extends ConnectionAbstract
break;
case CacheValueType::_SERIALIZABLE:
case CacheValueType::_JSONSERIALIZABLE:
$namespaceStart = strpos($raw, self::DELIM, $expireEnd);
$namespaceEnd = strpos($raw, self::DELIM, $namespaceStart + 1);
$namespace = substr($raw, $namespaceStart, $namespaceEnd);
$namespaceStart = \strpos($raw, self::DELIM, $expireEnd);
$namespaceEnd = \strpos($raw, self::DELIM, $namespaceStart + 1);
$namespace = \substr($raw, $namespaceStart, $namespaceEnd);
$value = $namespace::unserialize(substr($raw, $namespaceEnd + 1));
break;
@ -351,12 +350,12 @@ class FileCache extends ConnectionAbstract
}
if ($expire >= 0) {
$created = Directory::created(File::sanitize($key, self::SANITIZE))->getTimestamp();
$now = time();
$created = Directory::created(Directory::sanitize($key, self::SANITIZE))->getTimestamp();
$now = \time();
$raw = \file_get_contents($path);
$expireStart = strpos($raw, self::DELIM);
$expireEnd = strpos($raw, self::DELIM, $expireStart + 1);
$cacheExpire = substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
$expireStart = \strpos($raw, self::DELIM);
$expireEnd = \strpos($raw, self::DELIM, $expireStart + 1);
$cacheExpire = \substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
if ($cacheExpire >= 0 && $created + $cacheExpire > $now) {
File::delete($path);
@ -425,7 +424,7 @@ class FileCache extends ConnectionAbstract
*/
private function getPath($key) : string
{
$path = File::sanitize($key, self::SANITIZE);
$path = Directory::sanitize($key, self::SANITIZE);
return $this->con . '/' . trim($path, '/') . '.cache';
}
}

View File

@ -47,8 +47,6 @@ abstract class ConnectionAbstract implements ConnectionInterface
*
* The database prefix name for unique table names
*
* @todo: make private? could add huge overhead since function call required
*
* @var string
* @since 1.0.0
*/
@ -94,6 +92,25 @@ abstract class ConnectionAbstract implements ConnectionInterface
*/
protected $schemaGrammar = null;
/**
* Set values
*
* @param string $name Variable name
* @param string $value Variable value
*
* @return void
*
* @since 1.0.0
*/
public function __set($name, $value) : void
{
if (!empty($this->$name)) {
return;
}
$this->$name = $value;
}
/**
* {@inheritdoc}
*/

View File

@ -246,7 +246,6 @@ final class Functions
* @return array
*
* @since 1.0.0
* todo: move to utils?! implement sqrt for array as well... could be usefull for others (e.g. matrix)
*/
public static function powerFloat(array $values, float $exp = 2.0) : array
{
@ -268,7 +267,6 @@ final class Functions
* @return array
*
* @since 1.0.0
* todo: move to utils?! implement sqrt for array as well... could be usefull for others (e.g. matrix)
*/
public static function powerInt(array $values, int $exp = 2) : array
{
@ -281,6 +279,26 @@ final class Functions
return $squared;
}
/**
* Sqrt all values in array.
*
* @param array $values Values to sqrt
*
* @return array
*
* @since 1.0.0
*/
public static function sqrt(array $values) : array
{
$squared = [];
foreach ($values as $value) {
$squared[] = sqrt($value);
}
return $squared;
}
/**
* Gets the relative position on a circular construct.
*

View File

@ -21,8 +21,6 @@ namespace phpOMS\Math\Geometry\ConvexHull;
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*
* @todo : implement vertice class or use vertice class used by graphs? May be usefull in order to give vertices IDs!
*/
final class MonotoneChain
{
@ -40,7 +38,7 @@ final class MonotoneChain
/**
* Create convex hull
*
* @param array<string, int|float> $points Points (Point Cloud)
* @param array<int, array<string, int|float>> $points Points (Point Cloud)
*
* @return array
*

View File

@ -102,16 +102,23 @@ final class Polygon implements D2ShapeInterface
$countIntersect = 0;
$polygonCount = count($polygon);
// todo: return based on highest possibility not by first match
for ($i = 1; $i < $polygonCount; ++$i) {
$vertex1 = $polygon[$i - 1];
$vertex2 = $polygon[$i];
if (abs($vertex1['y'] - $vertex2['y']) < self::EPSILON && abs($vertex1['y'] - $point['y']) < self::EPSILON && $point['x'] > min($vertex1['x'], $vertex2['x']) && $point['x'] < max($vertex1['x'], $vertex2['x'])) {
if (abs($vertex1['y'] - $vertex2['y']) < self::EPSILON
&& abs($vertex1['y'] - $point['y']) < self::EPSILON
&& $point['x'] > min($vertex1['x'], $vertex2['x'])
&& $point['x'] < max($vertex1['x'], $vertex2['x'])
) {
return 0; // boundary
}
if ($point['y'] > min($vertex1['y'], $vertex2['y']) && $point['y'] <= max($vertex1['y'], $vertex2['y']) && $point['x'] <= max($vertex1['x'], $vertex2['x']) && abs($vertex1['y'] - $vertex2['y']) >= self::EPSILON) {
if ($point['y'] > min($vertex1['y'], $vertex2['y'])
&& $point['y'] <= max($vertex1['y'], $vertex2['y'])
&& $point['x'] <= max($vertex1['x'], $vertex2['x'])
&& abs($vertex1['y'] - $vertex2['y']) >= self::EPSILON
) {
$xinters = ($point['y'] - $vertex1['y']) * ($vertex2['x'] - $vertex1['x']) / ($vertex2['y'] - $vertex1['y']) + $vertex1['x'];
if (abs($xinters - $point['x']) < self::EPSILON) {

View File

@ -672,19 +672,6 @@ class Matrix implements \ArrayAccess, \Iterator
return $sign;
}
/**
* Lower triangulize matrix.
*
* @return Matrix
*
* @since 1.0.0
*/
public function lowerTriangular() : Matrix
{
// todo: implement
return new Matrix($this->m, $this->n);
}
/**
* Inverse matrix.
*

View File

@ -67,8 +67,6 @@ final class Request extends RequestAbstract
*
* @return void
*
* @todo: maybe change to normal path string e.g. /some/path/here instead of hash! Remember to adjust navigation elements
*
* @since 1.0.0
*/
public function createRequestHashs(int $start = 0) : void

View File

@ -58,8 +58,6 @@ final class Header extends HeaderAbstract
*
* @return bool
*
* @todo Allow to extend header key with additional values.
*
* @since 1.0.0
*/
public function set(string $key, string $header, bool $overwrite = false) : bool

View File

@ -183,9 +183,9 @@ final class Request extends RequestAbstract
*/
private function setupUriBuilder() : void
{
UriFactory::clean('?');
UriFactory::setQuery('/lang', $this->header->getL11n()->getLanguage());
// todo: flush previous
foreach ($this->data as $key => $value) {
UriFactory::setQuery('?' . $key, $value);
}
@ -221,8 +221,6 @@ final class Request extends RequestAbstract
*
* @return void
*
* @todo: maybe change to normal path string e.g. /some/path/here instead of hash! Remember to adjust navigation elements
*
* @since 1.0.0
*/
public function createRequestHashs(int $start = 0) : void
@ -249,7 +247,6 @@ final class Request extends RequestAbstract
*/
public function isMobile() : bool
{
// TODO: maybe replace this with smart media queries... checked gets handled in reverse!!!
$useragent = $_SERVER['HTTP_USER_AGENT'] ?? '';
if (\preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent) || \preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', $useragent)) {

View File

@ -396,14 +396,7 @@ final class ModuleManager
$this->activateModule($info);
return true;
} catch (PathException $e) {
// todo: handle module doesn't exist or files are missing
//echo $e->getMessage();
return false;
} catch (\Exception $e) {
//echo $e->getMessage();
return false;
}
}

View File

@ -151,8 +151,7 @@ class SmartDateTime extends \DateTime
*/
public function getDaysOfMonth() : int
{
// todo: maybe ->format('t') is better
return cal_days_in_month(CAL_GREGORIAN, (int) $this->format('m'), (int) $this->format('Y'));
return (int) $this->format('t');
}
/**

View File

@ -181,12 +181,13 @@ interface ContainerInterface
*
* @param string $path Path of the resource
* @param string $replace Replace invalid chars with
* @param string $invalid Invalid chars to sanitize
*
* @return string
*
* @since 1.0.0
*/
public static function sanitize(string $path, string $replace = '') : string;
public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;\/\[\]\(\]]/') : string;
/**
* Get amount of sub-resources.

View File

@ -165,9 +165,9 @@ class Directory extends FileAbstract implements DirectoryInterface
/**
* {@inheritdoc}
*/
public static function sanitize(string $path, string $replace = '') : string
public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;\/\[\]\(\]]/') : string
{
return DirectoryLocal::sanitize($path, $replace);
return DirectoryLocal::sanitize($path, $replace, $invalid);
}
/**

View File

@ -187,9 +187,9 @@ class File extends FileAbstract implements FileInterface
/**
* {@inheritdoc}
*/
public static function sanitize(string $path, string $replace = '') : string
public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;\/\[\]\(\]]/') : string
{
return LocalFile::sanitize($path, $replace);
return LocalFile::sanitize($path, $replace, $invalid);
}
/**

View File

@ -370,9 +370,9 @@ final class Directory extends FileAbstract implements DirectoryInterface
/**
* {@inheritdoc}
*/
public static function sanitize(string $path, string $replace = '') : string
public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;:\[\]\(\]\/]/') : string
{
return \preg_replace('[^\w\s\d\.\-_~,;:\[\]\(\]\/]', $replace, $path);
return \preg_replace($invalid, $replace, $path);
}
/**

View File

@ -152,9 +152,9 @@ final class File extends FileAbstract implements FileInterface
/**
* {@inheritdoc}
*/
public static function sanitize(string $path, string $replace = '') : string
public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;\/\[\]\(\]]/') : string
{
return \preg_replace('/[^\w\s\d\.\-_~,;\/\[\]\(\]]/', $replace, $path);
return \preg_replace($invalid, $replace, $path);
}
/**

View File

@ -59,6 +59,28 @@ final class UriFactory
return self::$uri[$key] ?? null;
}
/**
* Cleanup
*
* @param string $identifier Identifier for cleaning up (e.g. * = everything, / = only path, ? = only query parameters, # only fragment etc.)
*
* @return void
*
* @since 1.0.0
*/
public static function clean(string $identifier = '?') : void
{
if ($identifier === '*') {
self::$uri = [];
} else {
foreach (self::$uri as $key => $value) {
if (\stripos($key, $identifier) === 0) {
unset(self::$uri[$key]);
}
}
}
}
/**
* Set global query replacements.
*
@ -81,20 +103,6 @@ final class UriFactory
return false;
}
/**
* Clear all uri components
*
* @return bool
*
* @since 1.0.0
*/
public static function clearAll() : bool
{
self::$uri = [];
return true;
}
/**
* Setup uri builder based on current request
*

View File

@ -376,8 +376,6 @@ class Repository
throw new PathException($source);
}
// todo: is valid git repository?
return implode("\n", $this->run('clone --local ' . $source . ' ' . $this->path));
}
@ -392,8 +390,6 @@ class Repository
*/
public function cloneRemote(string $source) : string
{
// todo: is valid remote git repository?
return implode("\n", $this->run('clone ' . $source . ' ' . $this->path));
}

View File

@ -48,7 +48,7 @@ class UriFactoryTest extends \PHPUnit\Framework\TestCase
self::assertNull(UriFactory::getQuery('Valid'));
self::assertEquals('query4', UriFactory::getQuery('/valid2'));
self::assertTrue(UriFactory::clearAll());
self::assertTrue(UriFactory::clean('*'));
self::assertNull(UriFactory::getQuery('/valid2'));
self::assertTrue(UriFactory::setQuery('/abc', 'query1'));
@ -59,6 +59,9 @@ class UriFactoryTest extends \PHPUnit\Framework\TestCase
self::assertNull(UriFactory::getQuery('/valid2'));
self::assertNull(UriFactory::getQuery('/valid3'));
self::assertEquals('query1', UriFactory::getQuery('/abc'));
self::assertTrue(UriFactory::clean('/'));
self::assertNull(UriFactory::getQuery('/abc'));
}
public function testBuilder()

View File

@ -114,10 +114,6 @@ class ViewTest extends \PHPUnit\Framework\TestCase
$view->setTemplate('/phpOMS/tests/Views/testTemplate');
self::assertEquals('<strong>Test</strong>', $view->render());
// todo: why is this failing?
//$view->setTemplate('phpOMS/tests/Views/testArray');
//self::assertEquals([1, 2, 3], $view->render());
}
/**