Dependencies

This commit is contained in:
2021-03-25 21:23:29 -03:00
parent 15e1eecc76
commit 5e0e7d1d55
76 changed files with 1687 additions and 0 deletions

11
aldarien/asset/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
composer.phar
/vendor/
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
#Eclipse IDE
.settings
.buildpath
.project

21
aldarien/asset/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Aldarien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2
aldarien/asset/README.md Normal file
View File

@ -0,0 +1,2 @@
# asset
Asset manager module for my apps

View File

@ -0,0 +1,21 @@
<?php
namespace App\Contract;
use App\Definition\Contract;
use App\Service\Asset as AssetService;
class Asset
{
use Contract;
protected static function newInstance()
{
return new AssetService();
}
public static function get($identifier)
{
$instance = self::getInstance();
return $instance->get($identifier);
}
}
?>

View File

@ -0,0 +1,5 @@
<?php
function asset($identifier) {
return \App\Contract\Asset::get($identifier);
}
?>

View File

@ -0,0 +1,88 @@
<?php
namespace App\Service;
class Asset
{
protected $assets;
protected $dir;
public function __construct()
{
$this->dir = config('locations.public');
}
public function get($identifier)
{
$asset = $this->find($identifier);
return $asset->url;
}
protected function find($identifier)
{
$type = $this->getType($identifier);
$asset = null;
if ($type == false) {
foreach (array_keys($this->assets) as $type) {
if (($asset = $this->getAsset($identifier, $type))) {
break;
}
}
} else {
$asset = $this->getAsset($identifier, $type);
}
return $asset;
}
protected function getType($identifier)
{
if (strpos($identifier, '.') !== false) {
list($name, $ext) = explode('.', $identifier);
return $ext;
}
return false;
}
protected function getAsset($identifier, $type)
{
if (!isset($this->assets[$type])) {
$this->loadAssets($type);
}
if (!isset($this->assets[$type])) {
return null;
}
foreach ($this->assets[$type] as $asset) {
if ($this->compareIdentifier($asset, $identifier)) {
return $asset;
}
}
return null;
}
protected function loadAssets($type)
{
$dir = $this->dir . '/' . $type . '/*.' . $type;
$files = glob($dir);
foreach ($files as $file) {
$url = $this->url($file);
$identifier = pathinfo($file)['filename'];
$this->assets[$type] []= (object) ['identifier' => $identifier, 'url' => $url, 'type' => $type];
}
}
protected function url($file)
{
$url = '/' . config('app.project') . '/' . str_replace('\\', '/', str_replace(realpath(config('locations.public')), '', dirname(realpath($file)))) . '/' . basename(realpath($file));
$url = preg_replace('/\/+/', '/', $url);
return $url;
}
protected function compareIdentifier($asset, $identifier)
{
if (strpos($identifier, '.') !== false) {
list($name, $ext) = explode('.', $identifier);
if ($asset->identifier == $name and $asset->type == $ext) {
return true;
}
} else {
if ($asset->identifier == $identifier) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,26 @@
{
"name" : "aldarien/asset",
"description" : "Asset manager module for my apps",
"type" : "library",
"require" : {
"aldarien/config" : "dev-master",
"aldarien/contract" : "dev-master"
},
"require-dev" : {
"phpunit/phpunit" : "^6.3"
},
"license" : "MIT",
"authors" : [{
"name" : "Aldarien",
"email" : "aldarien85@gmail.com"
}
],
"autoload" : {
"psr-4" : {
"App\\" : "app"
},
"files": [
"app/Helper/functions.php"
]
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
verbose="true"
bootstrap="./vendor/autoload.php"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./app</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1,25 @@
<?php
use PHPUnit\Framework\TestCase;
class AssetTest extends TestCase
{
public function setUp()
{
mkdir(root() . '/public');
mkdir(root() . '/public/css');
config('locations.public', root() . '/public');
file_put_contents(root() . '/public/css/style.css', 'body {color: black;}');
}
public function tearDown()
{
unlink(root() . '/public/css/style.css');
rmdir(root() . '/public/css');
rmdir(root() . '/public');
}
public function testAsset()
{
$this->assertEquals(asset('style.css'), '/css/style.css');
}
}
?>

13
aldarien/config/.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
composer.phar
/vendor/
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
config
# Eclipse IDE
.settings
.buildpath
.project

View File

@ -0,0 +1,3 @@
language: php
php: '7.1'
install: composer update

21
aldarien/config/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Aldarien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,4 @@
# config
Config module that recovers configuration files
[![Build Status](https://travis-ci.org/Aldarien/config.svg?branch=1.0.1)](https://travis-ci.org/Aldarien/config)

View File

@ -0,0 +1,31 @@
<?php
namespace App\Contract;
use App\Definition\Contract;
use App\Service\Config AS ConfigService;
class Config
{
use Contract;
protected static function newInstance()
{
return new ConfigService();
}
public static function get($name = null)
{
$instance = self::getInstance();
return $instance->get($name);
}
public static function set($name, $value)
{
$instance = self::getInstance();
return $instance->set($name, $value);
}
public static function addFile($filename)
{
$instance = self::getInstance();
return $instance->loadFile($filename);
}
}
?>

View File

@ -0,0 +1,21 @@
<?php
namespace App\Contract;
use Symfony\Component\Yaml\Yaml;
class YamlWrapper
{
public static function load($filename, $flags = 0)
{
return self::parse(file_get_contents($filename), $flags);
}
public static function parse($input, $flags = 0)
{
return Yaml::parse($input, $flags);
}
public static function dump($array, $inline = 2, $indent = 4, $flags = 0)
{
return Yaml::dump($array, $inline, $indent, $flags);
}
}
?>

View File

@ -0,0 +1,9 @@
<?php
function config($name = null, $value = null) {
if ($value == null) {
return App\Contract\Config::get($name);
} else {
return App\Contract\Config::set($name, $value);
}
}
?>

View File

@ -0,0 +1,146 @@
<?php
namespace App\Service;
use App\Contract\YamlWrapper;
class Config
{
protected $dir;
protected $data;
public function __construct($dir = null)
{
if ($dir == null) {
$dir = realpath(root() . '/config');
}
$this->dir = $dir;
$this->load();
}
protected function load()
{
$files = glob($this->dir . '/*.{php,json,yml}', GLOB_BRACE);
foreach ($files as $file) {
$info = pathinfo($file);
$name = $info['filename'];
$d = $this->getData($file);
$data[$name] = $d;
$data = array_merge($data, $this->translateArray($d, $name));
foreach ($data as $key => $value) {
$this->add($key, $value);
}
}
}
public function loadFile(string $filename)
{
if (!file_exists(realpath($filename))) {
return false;
}
$info = pathinfo($filename);
$name = $info['filename'];
$d = $this->getData($filename);
$data[$name] = $d;
$data = array_merge($data, $this->translateArray($d, $name));
foreach ($data as $key => $value) {
$this->add($key, $value);
}
return true;
}
protected function getData($filename)
{
$info = pathinfo($filename);
switch ($info['extension']) {
case 'php':
return include_once $filename;
case 'json':
return json_decode(file_get_contents($filename), true);
case 'yml':
return YamlWrapper::load($filename);
default:
throw new \DomainException('Invalid file extension for ' . $filename);
}
}
protected function translateArray($array, $level)
{
$output = [];
foreach ($array as $k1 => $l1) {
$key = $level . '.' . $k1;
if (is_array($l1)) {
$output[$key] = $l1;
$output = array_merge($output, $this->translateArray($l1, $key));
} else {
$output[$key] = $l1;
}
}
return $output;
}
protected function add($field, $value)
{
if (isset($this->data[$field])) {
if ($this->data[$field] == $value) {
return;
}
if (is_array($this->data[$field])) {
$this->data[$field] = $this->merge($this->data[$field], $this->replace($value));
} else {
$this->data[$field] = $this->replace($value);
}
} else {
$this->data[$field] = $this->replace($value);
}
}
protected function merge($arr1, $arr2)
{
$output = $arr1;
foreach ($arr2 as $k => $value) {
if (isset($arr1[$k])) {
if ($arr1[$k] == $value) {
continue;
}
if (is_array($arr1[$k])) {
$output[$k] = $this->merge($arr1[$k], $value);
} else {
$output[$k] = array_merge([$arr1[$k]], $value);
}
} else {
$output[$k] = $value;
}
}
return $output;
}
protected function replace($value)
{
if (is_array($value)) {
foreach ($value as $k => $v) {
$value[$k] = $this->replace($v);
}
return $value;
}
if (strpos($value, '{') !== false) {
while(strpos($value, '{') !== false) {
$ini = strpos($value, '{') + 1;
$end = strpos($value, '}', $ini);
$rep = substr($value, $ini, $end - $ini);
$value = str_replace('{' . $rep . '}', $this->get($rep), $value);
}
}
return $value;
}
public function get($name = null)
{
if ($name == null) {
return $this->data;
}
if (isset($this->data[$name])) {
return $this->data[$name];
}
return null;
}
public function set($name, $value)
{
$this->add($name, $value);
}
}
?>

View File

@ -0,0 +1,3 @@
<?php
include_once dirname(__DIR__) . '/vendor/autoload.php';
?>

View File

@ -0,0 +1,28 @@
{
"name": "aldarien/config",
"description": "Config module for my apps",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Aldarien",
"email": "aldarien85@gmail.com"
}
],
"require": {
"aldarien/contract": "dev-master",
"aldarien/root": "dev-master",
"symfony/yaml": "^3.3"
},
"autoload": {
"psr-4": {
"App\\": "app"
},
"files": [
"app/Helper/functions.php"
]
},
"require-dev": {
"phpunit/phpunit": "^6.3"
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
verbose="true"
bootstrap="./bootstrap/autoload.php"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./app</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1,90 @@
<?php
use PHPUnit\Framework\TestCase;
use App\Contract\YamlWrapper;
class ConfigTest extends TestCase
{
public function setUp()
{
mkdir(dirname(__DIR__) . '/config');
$str = "<?php return ['name' => 'Config', 'test_array' => ['data1' => 1, 'data2' => 2]]; ?>";
file_put_contents(dirname(__DIR__) . '/config/app.php', $str);
$data = ['name' => 'Config', 'test_array' => ['data1' => 1, 'data2' => 2]];
file_put_contents(dirname(__DIR__) . '/config/json.json', json_encode($data));
file_put_contents(dirname(__DIR__) . '/config/yaml.yml', YamlWrapper::dump($data));
$data = ['last_name' => 'Config'];
file_put_contents(dirname(__DIR__) . '/config/yaml.json', json_encode($data));
}
public function testGetNamePhp()
{
$name = 'Config';
$this->assertEquals($name, config('app.name'));
}
public function testGetNameJson()
{
$name = 'Config';
$this->assertEquals($name, config('json.name'));
}
public function testGetNameYaml()
{
$name = 'Config';
$this->assertEquals($name, config('yaml.name'));
}
public function testSetNamehp()
{
$new_name = 'Config_Test';
config('app.name', $new_name);
$this->assertEquals($new_name, config('app.name'));
}
public function testSetNameJson()
{
$new_name = 'Config_Test';
config('json.name', $new_name);
$this->assertEquals($new_name, config('json.name'));
}
public function testSetNameYaml()
{
$new_name = 'Config_Test';
config('yaml.name', $new_name);
$this->assertEquals($new_name, config('yaml.name'));
}
public function testArrayGetPhp()
{
$this->assertArrayHasKey('data1', config('app.test_array'));
}
public function testArrayGetJson()
{
$this->assertArrayHasKey('data1', config('json.test_array'));
}
public function testArrayGetYaml()
{
$this->assertArrayHasKey('data1', config('yaml.test_array'));
}
public function testSameSectionName()
{
$this->assertEquals('Config', config('yaml.last_name'));
}
public function testDuplicateValue()
{
config('json.name', 'Config2');
$this->assertEquals('Config2', config('json.name'));
}
public function testAddFile()
{
$filename = dirname(__DIR__) . '/composer.json';
App\Contract\Config::addFile($filename);
$this->assertEquals('aldarien/config', config('composer.name'));
}
public function tearDown()
{
unlink(dirname(__DIR__) . '/config/app.php');
unlink(dirname(__DIR__) . '/config/json.json');
unlink(dirname(__DIR__) . '/config/yaml.yml');
unlink(dirname(__DIR__) . '/config/yaml.json');
rmdir(dirname(__DIR__) . '/config');
}
}
?>

6
aldarien/contract/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
composer.phar
/vendor/
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock

21
aldarien/contract/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Aldarien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,20 @@
<?php
namespace App\Definition;
trait Contract
{
protected static $instance = null;
private function __construct() {}
protected static function getInstance()
{
if (self::$instance == null) {
self::$instance = static::newInstance();
}
return self::$instance;
}
abstract protected static function newInstance();
}
?>

View File

@ -0,0 +1,18 @@
{
"name": "aldarien/contract",
"description": "Contract trait for my apps",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Aldarien",
"email": "aldarien85@gmail.com"
}
],
"require": {},
"autoload": {
"psr-4": {
"App\\": "app"
}
}
}

11
aldarien/format/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
composer.phar
/vendor/
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
# Eclipse IDE
.settings
.buildpath
.project

21
aldarien/format/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Aldarien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,2 @@
# format
Module for formatting data, mostly numbers

View File

@ -0,0 +1,43 @@
<?php
namespace App\Helper;
class Format
{
public static function number(float $number, $decimals)
{
return number_format($number, $decimals, ',', '.');
}
public static function pesos(float $number, bool $print = false)
{
return (($print) ? '$ ' : '') . self::number($number, 0);
}
public static function ufs(float $number, bool $print = false)
{
return self::number($number, 2) . (($print) ? ' UF' : '');
}
public static function date(string $date)
{
$d = \Carbon\Carbon::parse($date, config('app.timezone'));
return $d->format("d \d\\e F Y");
}
public static function shortDate(string $date)
{
$d = \Carbon\Carbon::parse($date, config('app.timezone'));
return $d->format('d-m-Y');
}
public static function localDate(string $date)
{
$d = \Carbon\Carbon::parse($date, config('app.timezone'));
setlocale(LC_TIME, 'es');
return $d->formatLocalized('%d de %B de %Y');
}
public static function m2(float $number, bool $print = false)
{
return self::number($number, 2) . (($print) ? ' m&#0178;' : '');
}
public static function percent(float $number, bool $print = false)
{
return self::number($number, 2) . (($print) ? '%' : '');
}
}
?>

View File

@ -0,0 +1,23 @@
{
"name" : "aldarien/format",
"description" : "Module for formatting data, mostly numbers",
"type" : "library",
"require-dev" : {
"phpunit/phpunit" : "^6",
"aldarien/config": "dev-master"
},
"license" : "MIT",
"authors" : [{
"name" : "Aldarien",
"email" : "aldarien85@gmail.com"
}
],
"autoload" : {
"psr-4" : {
"App\\" : "app"
}
},
"require": {
"nesbot/carbon": "^2"
}
}

View File

@ -0,0 +1,5 @@
<?php
return [
'timezone' => 'America/Santiago'
];
?>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
verbose="true"
bootstrap="./vendor/autoload.php"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./app</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1,59 @@
<?php
use PHPUnit\Framework\TestCase;
use App\Helper\Format;
class FormatTest extends TestCase
{
protected $number = 5049872.31567;
protected $date = '2016-03-25';
public function testFormat()
{
$output = '5.049.872,316';
$result = Format::number($this->number, 3);
$this->assertEquals($output, $result);
}
public function testPesosPrint()
{
$output = '$ 5.049.872';
$result = Format::pesos($this->number, true);
$this->assertEquals($output, $result);
}
public function testUFPrint()
{
$output = '5.049.872,32 UF';
$result = Format::ufs($this->number, true);
$this->assertEquals($output, $result);
}
public function testDate()
{
$output = '25 de March 2016';
$result = Format::date($this->date);
$this->assertEquals($output, $result);
}
public function testShortDate()
{
$output = '25-03-2016';
$result = Format::shortDate($this->date);
$this->assertEquals($output, $result);
}
public function testLocalDate()
{
$output = '25 de marzo de 2016';
$result = Format::localDate($this->date);
$this->assertEquals($output, $result);
}
public function testM2Print()
{
$output = '5.049.872,32 m&#0178;';
$result = Format::m2($this->number, true);
$this->assertEquals($output, $result);
}
public function testPercentPrint()
{
$output = '5.049.872,32%';
$result = Format::percent($this->number, true);
$this->assertEquals($output, $result);
}
}
?>

7
aldarien/response/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
#Eclipse IDE
.settings
.buildpath
.project
#Composer
vendor

21
aldarien/response/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Aldarien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,2 @@
# response
Response handler module for my apps

View File

@ -0,0 +1,27 @@
<?php
namespace App\Contract;
use App\Definition\Contract;
use App\Service\Response as ResponseService;
class Response
{
use Contract;
protected static function newInstance()
{
return new ResponseService();
}
public static function __callStatic($name, $params)
{
if (!method_exists(Response::class, $name)) {
$instance = self::getInstance();
if (method_exists($instance, $name)) {
return call_user_func_array([$instance, $name], $params);
}
return null;
}
return call_user_func_array([self, $name], $params);
}
}
?>

View File

@ -0,0 +1,11 @@
<?php
function sanitize() {
App\Contract\Response::sanitize();
}
function get($query = null) {
return App\Contract\Response::get($query);
}
function post($query = null) {
return App\Contract\Response::post($query);
}
?>

View File

@ -0,0 +1,62 @@
<?php
namespace App\Service;
class Response
{
protected $post;
protected $get;
protected $gump;
public function __construct()
{
$this->gump = new \GUMP();
}
public function sanitize()
{
if ($_POST) {
$this->post = $this->correctNumbers($this->gump->sanitize($_POST));
}
if ($_GET) {
$this->get = $this->correctNumbers($this->gump->sanitize($_GET));
}
}
public function correctNumbers(array $data)
{
$output = [];
foreach ($data as $key => $value) {
if (is_float(str_replace(',', '.', $value))) {
$output[$key] = str_replace(',', '.', $value);
} else {
$output[$key] = $value;
}
}
return $output;
}
public function get($query = null)
{
if ($this->get == null) {
$this->sanitize();
}
if ($query == null) {
return $this->get;
}
if (isset($this->get[$query])) {
return $this->get[$query];
}
return false;
}
public function post($query = null)
{
if ($this->post == null) {
$this->sanitize();
}
if ($query == null) {
return $this->post;
}
if (isset($this->post[$query])) {
return $this->post[$query];
}
return false;
}
}
?>

View File

@ -0,0 +1,3 @@
<?php
include_once dirname(__DIR__) . '/vendor/autoload.php';
?>

View File

@ -0,0 +1,26 @@
{
"name" : "aldarien/response",
"description" : "Response handler module for my apps",
"type" : "library",
"require" : {
"wixel/gump" : "^1.5",
"aldarien/contract" : "dev-master"
},
"require-dev" : {
"phpunit/phpunit" : "^6.3"
},
"license" : "MIT",
"authors" : [{
"name" : "Aldarien",
"email" : "jpvial@gmail.com"
}
],
"autoload" : {
"psr-4" : {
"App\\" : "app"
},
"files": [
"app/Helper/functions.php"
]
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
verbose="true"
bootstrap="./bootstrap/autoload.php"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./app</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1,22 @@
<?php
use PHPUnit\Framework\TestCase;
class ResponseTest extends TestCase
{
protected $value = 'Test';
public function setUp()
{
$_GET['test'] = $this->value;
$_POST['test'] = $this->value;
}
public function testGet()
{
$this->assertEquals($this->value, get('test'));
}
public function testPost()
{
$this->assertEquals($this->value, post('test'));
}
}
?>

5
aldarien/root/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.buildpath
.project
.settings
*.lock
vendor

21
aldarien/root/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Aldarien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

22
aldarien/root/README.md Normal file
View File

@ -0,0 +1,22 @@
# root
get root directory path for your project
## Usage
add `Root::root('project')` or `root('project')` or `Root::root()` or `root()` where you need the root directory of your proyect.
## Example
For the structure:
~~~
/usr/share/www/projects
- myProject
-- src
-- tests
~~~
using `Root::root('myProject')`
outputs:
`/usr/share/www/projects/myProject`

View File

@ -0,0 +1,5 @@
<?php
function root(string $proyect_name = '') {
return \Proyect\Root\Root::root($proyect_name);
}
?>

View File

@ -0,0 +1,21 @@
{
"name" : "aldarien/root",
"description" : "Find the root path for your proyect",
"authors" : [{
"name" : "Aldarien"
}
],
"license": "MIT",
"require-dev" : {
"phpunit/phpunit" : "~6",
"kint-php/kint" : "~2"
},
"autoload" : {
"psr-4" : {
"Proyect\\Root\\" : "src"
},
"files": [
"app/Helper/functions.php"
]
}
}

19
aldarien/root/phpunit.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuite>
<directory suffix="Test.php">tests</directory>
</testsuite>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1,48 @@
<?php
namespace Proyect\Root;
class Root
{
/**
* gives base path for your proyect.
* eg. <code>$proyect_name/public/index.php</code> calls for <code>$proyect_name/bootstrap/autoload.php</code>,
* you just need to
*
* <code>include root() . '/bootstrap/autoload.php'</code>
*
* @param string $proyect_name
* @return string
*/
public static function root(string $proyect_name = '')
{
$dir = realpath(__DIR__);
if ($proyect_name == '') {
return self::findComposerFile($dir);
} else {
$ini = strpos($dir, $proyect_name) + strlen($proyect_name);
}
$path = substr($dir, $ini);
$cnt = substr_count($path, DIRECTORY_SEPARATOR);
$root = DIRECTORY_SEPARATOR;
for ($i = 0; $i < $cnt; $i ++) {
$root .= '..' . DIRECTORY_SEPARATOR;
}
return realpath($dir . $root);
}
protected static function findComposerFile($dir)
{
if (file_exists($dir . '/vendor/')) {
return $dir;
}
$root = realpath('/');
if (realpath($dir) == $root) {
return null;
}
$dir = dirname($dir);
return self::findComposerFile($dir);
}
}
?>

View File

@ -0,0 +1,61 @@
<?php
use PHPUnit\Framework\TestCase;
use Proyect\Root\Root;
class RootTest extends TestCase
{
private $proyect_name = 'root';
private $current_dir;
public function testBaseRoot()
{
$this->getCurrentDir();
$this->assertEquals($this->getRoot(), $this->current_dir);
$this->assertEquals($this->getBaseRoot(), $this->current_dir);
}
public function testBaseRootFunction()
{
$this->getCurrentDir();
$this->assertEquals($this->getFRoot(), $this->current_dir);
$this->assertEquals($this->getFBaseRoot(), $this->current_dir);
}
public function testSrcRoot()
{
$this->changeDir('src');
$this->assertEquals(realpath($this->getRoot() . '/src'), $this->current_dir);
$this->assertEquals(realpath($this->getBaseRoot() . '/src'), $this->current_dir);
}
public function testSrcRootFunction()
{
$this->changeDir('src');
$this->assertEquals(realpath($this->getFRoot() . '/src'), $this->current_dir);
$this->assertEquals(realpath($this->getFBaseRoot() . '/src'), $this->current_dir);
}
private function getCurrentDir()
{
$this->current_dir = getcwd();
}
private function changeDir($dir)
{
chdir($dir);
$this->getCurrentDir();
}
private function getRoot()
{
return Root::root($this->proyect_name);
}
private function getBaseRoot()
{
return Root::root();
}
private function getFRoot()
{
return root($this->proyect_name);
}
private function getFBaseRoot()
{
return root();
}
}
?>

11
aldarien/session/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
composer.phar
/vendor/
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
# Eclipse IDE
.settings
.buildpath
.project

21
aldarien/session/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Aldarien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,2 @@
# session
Session wrapper for aura/session

View File

@ -0,0 +1,29 @@
<?php
namespace App\Contract;
use Aura\Session\SessionFactory;
use App\Definition\Contract;
class Session
{
use Contract;
protected static function newInstance()
{
$session_factory = new SessionFactory();
return $session_factory->newInstance($_COOKIE);
}
public static function get($segment, $name)
{
$instance = self::getInstance();
$segment = $instance->getSegment($segment);
return $segment->get($name);
}
public static function set($segment, $name, $value)
{
$instance = self::getInstance();
$segment = $instance->getSegment($segment);
$segment->set($name, $value);
}
}
?>

View File

@ -0,0 +1,24 @@
{
"name": "aldarien/session",
"description": "Session wrapper for aura/session",
"type": "library",
"require": {
"aura/session": "^2.1",
"aldarien/contract": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^6.3"
},
"license": "MIT",
"authors": [
{
"name": "Aldarien",
"email": "aldarien85@gmail.com"
}
],
"autoload": {
"psr-4": {
"App\\": "app"
}
}
}

12
aldarien/url/.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
composer.phar
/vendor/
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
.settings
.buildpath
.project
# Eclipse IDE

21
aldarien/url/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Aldarien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2
aldarien/url/README.md Normal file
View File

@ -0,0 +1,2 @@
# url
Get relative path url

View File

@ -0,0 +1,21 @@
<?php
namespace App\Contract;
use App\Definition\Contract;
use App\Service\URL as URLService;
class URL
{
use Contract;
protected static function newInstance()
{
return new URLService();
}
public static function url($path = '', $variables = null)
{
$instance = self::getInstance();
return $instance->url($path, $variables);
}
}
?>

View File

@ -0,0 +1,8 @@
<?php
function url($path = '', $variables = null) {
return App\Contract\URL::url($path, $variables);
}
function baseUrl() {
return url();
}
?>

View File

@ -0,0 +1,76 @@
<?php
namespace App\Service;
use League\Uri\Http;
use League\Uri\Components\Host;
use League\Uri\Components\HierarchicalPath;
class URL
{
protected $root;
protected $relative;
public function __construct()
{
$this->root = $this->findRoot();
$this->relative = $this->findRelative();
}
protected function findRoot()
{
$base = $_SERVER['HTTP_HOST'] . ((isset($_SERVER['HTTP_PORT'])) ? ':' . $_SERVER['HTTP_PORT'] : '');
$uri = Http::createFromString(\Sabre\Uri\resolve($_SERVER['REQUEST_SCHEME'] . '://' . $base, $_SERVER['SCRIPT_NAME']));
$host = new Host($uri->getHost());
if ($host->isAbsolute()) {
return $host->getRegistrableDomain();
}
$base = $host . (($uri->getPort()) ? ':' . $uri->getPort() : '');
return ($uri->getScheme() ?: 'http') . '://' . $base;
}
protected function findRelative()
{
$uri = Http::createFromString($_SERVER['SCRIPT_NAME']);
$normalized = (new HierarchicalPath($uri->getPath()))->withoutLeadingSlash()->withoutTrailingSlash()->withoutDotSegments()->withoutEmptySegments();
if ($normalized->getDirname() == '.') {
return '';
}
return $normalized->getDirname();
}
public function url($path = '', $variables = null)
{
$uri = Http::createFromString($path);
if ($uri->getHost() != $this->root and $uri->getHost() != '') {
return $path;
}
$uri = \Sabre\Uri\resolve($this->getBaseUrl(), $path);
try {
$host = new Host(Http::createFromString($uri)->getHost());
} catch (\League\Uri\Exception $e) {
$uri = \Sabre\Uri\resolve($this->getBaseUrl(), '../../') . '/' . basename($path);
$host = new Host(Http::createFromString($uri)->getHost());
}
$base = new Host(Http::createFromString($this->root)->getHost());
if ($host . '' != $base . '') {
$host = new Host(Http::createFromString($this->root)->getHost());
$page = str_replace($this->root, '', $uri);
$uri = \Sabre\Uri\resolve(Http::createFromString($this->root)->getScheme() . '://' . $host->getRegistrableDomain(). '/', $page);
}
if ($variables != null) {
$uri = \Sabre\Uri\resolve($uri, '?' . http_build_query($variables));
}
$uri = \Sabre\Uri\normalize($uri);
return $uri;
}
protected function getBaseUrl()
{
$url = \Sabre\Uri\normalize(trim($this->root . '/' . $this->relative, '/') . '/');
return $url;
}
}
?>

View File

@ -0,0 +1,28 @@
{
"name" : "aldarien/url",
"description" : "Get relative path uri",
"type" : "library",
"require" : {
"aldarien/contract" : "dev-master",
"aldarien/root" : "dev-master",
"league/uri": "^5.2",
"sabre/uri": "^2.1"
},
"require-dev" : {
"phpunit/phpunit" : "^6.3"
},
"license" : "MIT",
"authors" : [{
"name" : "Aldarien",
"email" : "jpvial@gmail.com"
}
],
"autoload" : {
"psr-4" : {
"App\\" : "app"
},
"files": [
"app/Helper/functions.php"
]
}
}

10
aldarien/view/.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
composer.phar
/vendor/
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
.settings
.buildpath
.project

21
aldarien/view/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Aldarien
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2
aldarien/view/README.md Normal file
View File

@ -0,0 +1,2 @@
# view
View module for my apps

View File

@ -0,0 +1,21 @@
<?php
namespace App\Contract;
use App\Definition\Contract;
use App\Service\View as ViewService;
class View
{
use Contract;
protected static function newInstance()
{
return new ViewService();
}
public static function show($template, $variables = null)
{
$instance = self::getInstance();
return $instance->show($template, $variables);
}
}
?>

View File

@ -0,0 +1,5 @@
<?php
function view($template, $variables = null) {
return \App\Contract\View::show($template, $variables);
}
?>

View File

@ -0,0 +1,27 @@
<?php
namespace App\Service;
use Philo\Blade\Blade;
class View
{
protected $views;
protected $cache;
protected $blade;
public function __construct()
{
$this->views = config('locations.views');
$this->cache = config('locations.cache');
$this->blade = new Blade($this->views, $this->cache);
}
public function show($template, $vars = null)
{
if ($vars) {
return $this->blade->view()->make($template, $vars)->render();
}
return $this->blade->view()->make($template)->render();
}
}
?>

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>View</title>
</head>
<body>
View test
</body>
</html>

View File

@ -0,0 +1,28 @@
{
"name": "aldarien/view",
"description": "View module for my apps",
"type": "library",
"require": {
"philo/laravel-blade": "^3.1",
"aldarien/contract": "dev-master",
"aldarien/config": "dev-master"
},
"license": "MIT",
"authors": [
{
"name": "Aldarien",
"email": "aldarien85@gmail.com"
}
],
"autoload": {
"psr-4": {
"App\\": "app"
},
"files": [
"app/Helper/functions.php"
]
},
"require-dev": {
"phpunit/phpunit": "^6.3"
}
}

View File

@ -0,0 +1,8 @@
<?php
return [
'base' => root(),
'cache' => '{locations.base}/cache',
'resources' => '{locations.base}/resources',
'views' => '{locations.resources}/views'
];
?>

17
aldarien/view/phpunit.xml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
verbose="true"
bootstrap="./vendor/autoload.php"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./app</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1,5 @@
<?php
include_once dirname(__DIR__) . '/vendor/autoload.php';
echo view('base');
?>

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>View</title>
</head>
<body>
View test
</body>
</html>

View File

@ -0,0 +1,22 @@
<?php
use PHPUnit\Framework\TestCase;
class ViewTest extends TestCase
{
public function testView()
{
$output = <<<DATA
<!DOCTYPE html>
<html>
<head>
<title>View</title>
</head>
<body>
View test
</body>
</html>
DATA;
$this->assertEquals($output, view('base'));
}
}
?>