Moved minify to powers. Improved the mapper class.

This commit is contained in:
2023-01-08 12:01:14 +02:00
parent e771e7d243
commit e8abe8e3cf
42 changed files with 2874 additions and 930 deletions

View File

@@ -0,0 +1,259 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Abstraction;
use VDM\Joomla\Componentbuilder\Interfaces\Mapperdoubleinterface;
use VDM\Joomla\Componentbuilder\Interfaces\Mappersingleinterface;
/**
* Compiler Mapper
*
* @since 3.2.0
*/
abstract class Mapper implements Mapperdoubleinterface, Mappersingleinterface
{
/**
* The Content
*
* @var array
* @since 3.2.0
**/
public array $active = [];
/**
* Set content
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function set(string $key, $value)
{
$this->active[$this->key($key)] = $value;
}
/**
* Get content
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return mixed
* @since 3.2.0
*/
public function get(string $key)
{
return $this->active[$this->key($key)] ?? null;
}
/**
* Does key exist
*
* @param string $key The main string key
*
* @return bool
* @since 3.2.0
*/
public function exist(string $key): bool
{
if (isset($this->active[$this->key($key)]))
{
return true;
}
return false;
}
/**
* Add content
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add(string $key, $value)
{
if (isset($this->active[$this->key($key)]))
{
$this->active[$this->key($key)] .= $value;
}
else
{
$this->active[$this->key($key)] = $value;
}
}
/**
* Remove content
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove(string $key)
{
unset($this->active[$this->key($key)]);
}
/**
* Model the key
*
* @param string $key The key to model
*
* @return string
* @since 3.2.0
*/
abstract protected function key(string $key): string;
/**
* The Dynamic Content
*
* @var array
* @since 3.2.0
**/
public array $_active = [];
/**
* Set dynamic content
*
* @param string $firstKey The first key
* @param string $secondKey The second key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function set_(string $firstKey, string $secondKey, $value)
{
$this->_active[$this->firstKey($firstKey)]
[$this->secondKey($secondKey)] = $value;
}
/**
* Get dynamic content
*
* @param string $firstKey The first key
* @param string $secondKey The second key
*
* @return mixed
* @since 3.2.0
*/
public function get_(string $firstKey, ?string $secondKey = null)
{
if (is_string($secondKey))
{
return $this->_active[$this->firstKey($firstKey)]
[$this->secondKey($secondKey)] ?? null;
}
return $this->_active[$this->firstKey($firstKey)] ?? null;
}
/**
* Does keys exist
*
* @param string $firstKey The first key
* @param string|null $secondKey The second key
*
* @return bool
* @since 3.2.0
*/
public function exist_(string $firstKey, ?string $secondKey = null): bool
{
if (is_string($secondKey) && isset($this->_active[$this->firstKey($firstKey)]) &&
isset($this->_active[$this->firstKey($firstKey)]
[$this->secondKey($secondKey)]))
{
return true;
}
elseif (is_null($secondKey) && isset($this->_active[$this->firstKey($firstKey)]))
{
return true;
}
return false;
}
/**
* Add dynamic content
*
* @param string $firstKey The first key
* @param string $secondKey The second key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add_(string $firstKey, string $secondKey, $value)
{
if (isset($this->_active[$this->firstKey($firstKey)]) &&
isset($this->_active[$this->firstKey($firstKey)]
[$this->secondKey($secondKey)]))
{
$this->_active[$this->firstKey($firstKey)]
[$this->secondKey($secondKey)] .= $value;
}
else
{
$this->_active[$this->firstKey($firstKey)]
[$this->secondKey($secondKey)] = $value;
}
}
/**
* Remove dynamic content
*
* @param string $firstKey The first key
* @param string|null $secondKey The second key
*
* @return void
* @since 3.2.0
*/
public function remove_(string $firstKey, ?string $secondKey = null)
{
if (is_string($secondKey))
{
unset($this->_active[$this->firstKey($firstKey)]
[$this->secondKey($secondKey)]);
}
else
{
unset($this->_active[$this->firstKey($firstKey)]);
}
}
/**
* Model the first key
*
* @param string $key The first key to model
*
* @return string
* @since 3.2.0
*/
abstract protected function firstKey(string $key): string;
/**
* Model the second key
*
* @param string $key The second key to model
*
* @return string
* @since 3.2.0
*/
abstract protected function secondKey(string $key): string;
}

View File

@@ -13,6 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Compiler;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
use VDM\Joomla\Componentbuilder\Interfaces\Mapperdoubleinterface;
use VDM\Joomla\Componentbuilder\Interfaces\Mappersingleinterface;
use VDM\Joomla\Componentbuilder\Abstraction\Mapper;
/**
@@ -20,202 +23,45 @@ use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
*
* @since 3.2.0
*/
class Content
class Content extends Mapper implements Mapperdoubleinterface, Mappersingleinterface
{
/**
* The Content
* Model the key
*
* @var array
* @since 3.2.0
**/
public array $active = [];
/**
* The Dynamic Content
* @param string $key The key to model
*
* @var array
* @since 3.2.0
**/
public array $_active = [];
/**
* Set content
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @return string
* @since 3.2.0
*/
public function set(string $key, $value)
protected function key(string $key): string
{
$this->active[Placefix::_h($key)] = $value;
return Placefix::_h($key);
}
/**
* Get content
* Model the first key
*
* @param string $key The main string key
* @param mixed $value The values to set
* @param string $key The first key to model
*
* @return mixed
* @return string
* @since 3.2.0
*/
public function get(string $key)
protected function firstKey(string $key): string
{
return $this->active[Placefix::_h($key)] ?? null;
return $key;
}
/**
* Does key exist
* Model the second key
*
* @param string $key The main string key
* @param string $key The second key to model
*
* @return bool
* @return string
* @since 3.2.0
*/
public function exist(string $key): bool
protected function secondKey(string $key): string
{
if (isset($this->active[Placefix::_h($key)]))
{
return true;
}
return false;
}
/**
* Add content
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add(string $key, $value)
{
if (isset($this->active[Placefix::_h($key)]))
{
$this->active[Placefix::_h($key)] .= $value;
}
else
{
$this->active[Placefix::_h($key)] = $value;
}
}
/**
* Remove content
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove(string $key)
{
unset($this->active[Placefix::_h($key)]);
}
/**
* Set dynamic content
*
* @param string $view The view key
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function set_(string $view, string $key, $value)
{
$this->_active[$view][Placefix::_h($key)] = $value;
}
/**
* Get dynamic content
*
* @param string $view The view key
* @param string|null $key The main string key
*
* @return mixed
* @since 3.2.0
*/
public function get_(string $view, ?string $key = null)
{
if (is_string($key))
{
return $this->_active[$view][Placefix::_h($key)] ?? null;
}
return $this->_active[$view] ?? null;
}
/**
* Does view key exist
*
* @param string $view The view key
* @param string|null $key The main string key
*
* @return bool
* @since 3.2.0
*/
public function exist_(string $view, ?string $key = null): bool
{
if (is_string($key) && isset($this->_active[$view]) &&
isset($this->_active[$view][Placefix::_h($key)]))
{
return true;
}
elseif (is_null($key) && isset($this->_active[$view]))
{
return true;
}
return false;
}
/**
* Add dynamic content
*
* @param string $view The view key
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add_(string $view, string $key, $value)
{
if (isset($this->_active[$view]) &&
isset($this->_active[$view][Placefix::_h($key)]))
{
$this->_active[$view][Placefix::_h($key)] .= $value;
}
else
{
$this->_active[$view][Placefix::_h($key)] = $value;
}
}
/**
* Remove dynamic content
*
* @param string $view The view key
* @param string|null $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove_(string $view, ?string $key = null)
{
if (is_string($key))
{
unset($this->_active[$view][Placefix::_h($key)]);
}
else
{
unset($this->_active[$view]);
}
}
return Placefix::_h($key);
}
}

View File

@@ -17,6 +17,7 @@ use VDM\Joomla\Componentbuilder\Service\Crypt;
use VDM\Joomla\Componentbuilder\Service\Server;
use VDM\Joomla\Componentbuilder\Compiler\Service\Database;
use VDM\Joomla\Componentbuilder\Compiler\Service\Model;
use VDM\Joomla\Componentbuilder\Compiler\Service\Mapper;
use VDM\Joomla\Componentbuilder\Compiler\Service\Compiler;
use VDM\Joomla\Componentbuilder\Compiler\Service\Event;
use VDM\Joomla\Componentbuilder\Compiler\Service\History;
@@ -113,6 +114,7 @@ abstract class Factory implements FactoryInterface
->registerServiceProvider(new Server())
->registerServiceProvider(new Database())
->registerServiceProvider(new Model())
->registerServiceProvider(new Mapper())
->registerServiceProvider(new Compiler())
->registerServiceProvider(new Event())
->registerServiceProvider(new History())

View File

@@ -16,7 +16,6 @@ use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Registry;
use VDM\Joomla\Componentbuilder\Compiler\Content;
/**
@@ -41,9 +40,6 @@ class Compiler implements ServiceProviderInterface
$container->alias(Registry::class, 'Registry')
->share('Registry', [$this, 'getRegistry'], true);
$container->alias(Content::class, 'Content')
->share('Content', [$this, 'getContent'], true);
}
/**
@@ -71,19 +67,6 @@ class Compiler implements ServiceProviderInterface
{
return new Registry();
}
/**
* Get the Compiler Content
*
* @param Container $container The DI container.
*
* @return Content
* @since 3.2.0
*/
public function getContent(Container $container): Content
{
return new Content();
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Service;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Compiler\Content;
/**
* Mapper Service Provider
*
* @since 3.2.0
*/
class Mapper implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
* @since 3.2.0
*/
public function register(Container $container)
{
$container->alias(Content::class, 'Content')
->share('Content', [$this, 'getContent'], true);
}
/**
* Get the Compiler Content
*
* @param Container $container The DI container.
*
* @return Content
* @since 3.2.0
*/
public function getContent(Container $container): Content
{
return new Content();
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Utilities;
use VDM\Minify\Css;
use VDM\Minify\JavaScript;
/**
* Compiler Minifier
*
* @since 3.2.0
*/
abstract class Minify
{
/**
* Minify JavaScript Class
*
* @var JavaScript
* @since 3.2.0
*/
public static JavaScript $js;
/**
* Minify Css Class
*
* @var Css
* @since 3.2.0
*/
public static Css $css;
/**
* Minify JavaScript
*
* @param string $data
*
* @return string
* @since 3.2.0
*/
public static function js(string $data): string
{
// check if instance already set
if (empty(self::$js))
{
// set instanceof on JavaScript
self::$js = new JavaScript;
}
// add the data
self::$js->add($data);
// return minified
return self::$js->minify();
}
/**
* Minify Css
*
* @param string $data
*
* @return string
* @since 3.2.0
*/
public static function css(string $data): string
{
// check if instance already set
if (empty(self::$css))
{
// set instanceof on Css
self::$css = new Css;
}
// add the data
self::$css->add($data);
// return minified
return self::$css->minify();
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Interfaces;
/**
* The Double Mapper Interface
*/
interface Mapperdoubleinterface
{
/**
* Set dynamic content
*
* @param string $firstKey The first key
* @param string $secondKey The second key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function set_(string $firstKey, string $secondKey, $value);
/**
* Get dynamic content
*
* @param string $firstKey The first key
* @param string $secondKey The second key
*
* @return mixed
* @since 3.2.0
*/
public function get_(string $firstKey, ?string $secondKey = null);
/**
* Does keys exist
*
* @param string $firstKey The first key
* @param string|null $secondKey The second key
*
* @return bool
* @since 3.2.0
*/
public function exist_(string $firstKey, ?string $secondKey = null): bool;
/**
* Add dynamic content
*
* @param string $firstKey The first key
* @param string $secondKey The second key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add_(string $firstKey, string $secondKey, $value);
/**
* Remove dynamic content
*
* @param string $firstKey The first key
* @param string|null $secondKey The second key
*
* @return void
* @since 3.2.0
*/
public function remove_(string $firstKey, ?string $secondKey = null);
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Interfaces;
/**
* The Single Mapper Interface
*/
interface Mappersingleinterface
{
/**
* Set content
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function set(string $key, $value);
/**
* Get content
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return mixed
* @since 3.2.0
*/
public function get(string $key);
/**
* Does key exist
*
* @param string $key The main string key
*
* @return bool
* @since 3.2.0
*/
public function exist(string $key): bool;
/**
* Add content
*
* @param string $key The main string key
* @param mixed $value The values to set
*
* @return void
* @since 3.2.0
*/
public function add(string $key, $value);
/**
* Remove content
*
* @param string $key The main string key
*
* @return void
* @since 3.2.0
*/
public function remove(string $key);
}

View File

@@ -101,6 +101,7 @@ class Load extends Model implements ModelInterface
break;
}
}
return $value;
}

View File

@@ -24,9 +24,9 @@ abstract class ArrayHelper
*
* @input array The array to check
*
* @returns bool/int number of items in array on success
* @returns int|false number of items in array on success
*
* @since 3.0.9
* @since 3.2.0
*/
public static function check($array, $removeEmptyString = false)
{
@@ -35,17 +35,19 @@ abstract class ArrayHelper
// also make sure the empty strings are removed
if ($removeEmptyString)
{
foreach ($array as $key => $string)
$array = array_filter($array);
if (empty($array))
{
if (empty($string))
{
unset($array[$key]);
}
return false;
}
return self::check($array, false);
return count($array);
}
return $nr;
}
return false;
}
@@ -54,25 +56,25 @@ abstract class ArrayHelper
*
* @input array The arrays you would like to merge
*
* @returns array on success
* @returns array|null merged array on success
*
* @since 3.0.9
*/
public static function merge($arrays)
public static function merge($arrays): ?array
{
if(self::check($arrays))
{
$arrayBuket = array();
$merged = [];
foreach ($arrays as $array)
{
if (self::check($array))
{
$arrayBuket = array_merge($arrayBuket, $array);
$merged = array_merge($merged, $array);
}
}
return $arrayBuket;
return $merged;
}
return false;
return null;
}
/**