Old Version
This commit is contained in:
@ -1,2 +0,0 @@
|
|||||||
ADMINER_DESIGN=dracula
|
|
||||||
ADMINER_PLUGINS=dump-json
|
|
@ -1,2 +0,0 @@
|
|||||||
ADMINER_DESIGN=dracula
|
|
||||||
ADMINER_PLUGINS=dump-json
|
|
5
.db.env
5
.db.env
@ -1,5 +0,0 @@
|
|||||||
MYSQL_DATABASE=incoviba
|
|
||||||
MYSQL_PASSWORD=5GQYFvRjVw2A4KcD
|
|
||||||
MYSQL_ROOT_PASSWORD=password
|
|
||||||
MYSQL_USER=incoviba
|
|
||||||
MYSQL_PORT=3307
|
|
@ -1,4 +0,0 @@
|
|||||||
MYSQL_DATABASE=
|
|
||||||
MYSQL_PASSWORD=
|
|
||||||
MYSQL_ROOT_PASSWORD=
|
|
||||||
MYSQL_USER=
|
|
@ -1,3 +0,0 @@
|
|||||||
COMPOSE_PROFILES=
|
|
||||||
BASE_URL=
|
|
||||||
MYSQL_HOST=
|
|
11
aldarien/asset/.gitignore
vendored
11
aldarien/asset/.gitignore
vendored
@ -1,11 +0,0 @@
|
|||||||
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
|
|
@ -1,21 +0,0 @@
|
|||||||
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.
|
|
@ -1,2 +0,0 @@
|
|||||||
# asset
|
|
||||||
Asset manager module for my apps
|
|
@ -1,21 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
function asset($identifier) {
|
|
||||||
return \App\Contract\Asset::get($identifier);
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,88 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"name" : "aldarien/asset",
|
|
||||||
"description" : "Asset manager module for my apps",
|
|
||||||
"type" : "library",
|
|
||||||
"require" : {
|
|
||||||
"aldarien/config" : "*",
|
|
||||||
"aldarien/contract" : "*"
|
|
||||||
},
|
|
||||||
"require-dev" : {
|
|
||||||
"phpunit/phpunit" : "*"
|
|
||||||
},
|
|
||||||
"license" : "MIT",
|
|
||||||
"authors" : [{
|
|
||||||
"name" : "Aldarien",
|
|
||||||
"email" : "aldarien85@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"autoload" : {
|
|
||||||
"psr-4" : {
|
|
||||||
"App\\" : "app"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"app/Helper/functions.php"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,25 +0,0 @@
|
|||||||
<?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
13
aldarien/config/.gitignore
vendored
@ -1,13 +0,0 @@
|
|||||||
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
|
|
@ -1,3 +0,0 @@
|
|||||||
language: php
|
|
||||||
php: '7.1'
|
|
||||||
install: composer update
|
|
@ -1,21 +0,0 @@
|
|||||||
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.
|
|
@ -1,4 +0,0 @@
|
|||||||
# config
|
|
||||||
Config module that recovers configuration files
|
|
||||||
|
|
||||||
[](https://travis-ci.org/Aldarien/config)
|
|
@ -1,31 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,21 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
function config($name = null, $value = null) {
|
|
||||||
if ($value == null) {
|
|
||||||
return App\Contract\Config::get($name);
|
|
||||||
} else {
|
|
||||||
return App\Contract\Config::set($name, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,150 +0,0 @@
|
|||||||
<?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);
|
|
||||||
$new = $this->get($rep);
|
|
||||||
if ($new === null) {
|
|
||||||
$new = '';
|
|
||||||
}
|
|
||||||
$value = str_replace('{' . $rep . '}', $new, $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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,3 +0,0 @@
|
|||||||
<?php
|
|
||||||
include_once dirname(__DIR__) . '/vendor/autoload.php';
|
|
||||||
?>
|
|
@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "aldarien/config",
|
|
||||||
"description": "Config module for my apps",
|
|
||||||
"type": "library",
|
|
||||||
"license": "MIT",
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Aldarien",
|
|
||||||
"email": "aldarien85@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"require": {
|
|
||||||
"aldarien/contract": "*",
|
|
||||||
"aldarien/root": "*",
|
|
||||||
"symfony/yaml": "*"
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"App\\": "app"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"app/Helper/functions.php"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"phpunit/phpunit": "^6.3"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,90 +0,0 @@
|
|||||||
<?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
6
aldarien/contract/.gitignore
vendored
@ -1,6 +0,0 @@
|
|||||||
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
|
|
@ -1,21 +0,0 @@
|
|||||||
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.
|
|
@ -1,20 +0,0 @@
|
|||||||
<?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();
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"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
11
aldarien/format/.gitignore
vendored
@ -1,11 +0,0 @@
|
|||||||
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
|
|
@ -1,21 +0,0 @@
|
|||||||
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.
|
|
@ -1,2 +0,0 @@
|
|||||||
# format
|
|
||||||
Module for formatting data, mostly numbers
|
|
@ -1,43 +0,0 @@
|
|||||||
<?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²' : '');
|
|
||||||
}
|
|
||||||
public static function percent(float $number, bool $print = false)
|
|
||||||
{
|
|
||||||
return self::number($number, 2) . (($print) ? '%' : '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"name" : "aldarien/format",
|
|
||||||
"description" : "Module for formatting data, mostly numbers",
|
|
||||||
"type" : "library",
|
|
||||||
"require-dev" : {
|
|
||||||
"phpunit/phpunit" : "*",
|
|
||||||
"aldarien/config": "*"
|
|
||||||
},
|
|
||||||
"license" : "MIT",
|
|
||||||
"authors" : [{
|
|
||||||
"name" : "Aldarien",
|
|
||||||
"email" : "aldarien85@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"autoload" : {
|
|
||||||
"psr-4" : {
|
|
||||||
"App\\" : "app"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"nesbot/carbon": "^2"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
'timezone' => 'America/Santiago'
|
|
||||||
];
|
|
||||||
?>
|
|
@ -1,17 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,59 +0,0 @@
|
|||||||
<?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²';
|
|
||||||
$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
7
aldarien/response/.gitignore
vendored
@ -1,7 +0,0 @@
|
|||||||
#Eclipse IDE
|
|
||||||
.settings
|
|
||||||
.buildpath
|
|
||||||
.project
|
|
||||||
|
|
||||||
#Composer
|
|
||||||
vendor
|
|
@ -1,21 +0,0 @@
|
|||||||
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.
|
|
@ -1,2 +0,0 @@
|
|||||||
# response
|
|
||||||
Response handler module for my apps
|
|
@ -1,27 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,11 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,62 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,3 +0,0 @@
|
|||||||
<?php
|
|
||||||
include_once dirname(__DIR__) . '/vendor/autoload.php';
|
|
||||||
?>
|
|
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"name" : "aldarien/response",
|
|
||||||
"description" : "Response handler module for my apps",
|
|
||||||
"type" : "library",
|
|
||||||
"require" : {
|
|
||||||
"wixel/gump" : "^2.0.0",
|
|
||||||
"aldarien/contract" : "*"
|
|
||||||
},
|
|
||||||
"require-dev" : {
|
|
||||||
"phpunit/phpunit" : "*"
|
|
||||||
},
|
|
||||||
"license" : "MIT",
|
|
||||||
"authors" : [{
|
|
||||||
"name" : "Aldarien",
|
|
||||||
"email" : "jpvial@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"autoload" : {
|
|
||||||
"psr-4" : {
|
|
||||||
"App\\" : "app"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"app/Helper/functions.php"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,22 +0,0 @@
|
|||||||
<?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
5
aldarien/root/.gitignore
vendored
@ -1,5 +0,0 @@
|
|||||||
.buildpath
|
|
||||||
.project
|
|
||||||
.settings
|
|
||||||
*.lock
|
|
||||||
vendor
|
|
@ -1,21 +0,0 @@
|
|||||||
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.
|
|
@ -1,22 +0,0 @@
|
|||||||
# 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`
|
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
function root(string $proyect_name = '') {
|
|
||||||
return \Proyect\Root\Root::root($proyect_name);
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"name" : "aldarien/root",
|
|
||||||
"description" : "Find the root path for your proyect",
|
|
||||||
"authors" : [{
|
|
||||||
"name" : "Aldarien"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
|
||||||
"require-dev" : {
|
|
||||||
"phpunit/phpunit" : "*",
|
|
||||||
"kint-php/kint" : "*"
|
|
||||||
},
|
|
||||||
"autoload" : {
|
|
||||||
"psr-4" : {
|
|
||||||
"Proyect\\Root\\" : "src"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"app/Helper/functions.php"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,48 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,61 +0,0 @@
|
|||||||
<?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
11
aldarien/session/.gitignore
vendored
@ -1,11 +0,0 @@
|
|||||||
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
|
|
@ -1,21 +0,0 @@
|
|||||||
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.
|
|
@ -1,2 +0,0 @@
|
|||||||
# session
|
|
||||||
Session wrapper for aura/session
|
|
@ -1,29 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "aldarien/session",
|
|
||||||
"description": "Session wrapper for aura/session",
|
|
||||||
"type": "library",
|
|
||||||
"require": {
|
|
||||||
"aura/session": "*",
|
|
||||||
"aldarien/contract": "*"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"phpunit/phpunit": "*"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Aldarien",
|
|
||||||
"email": "aldarien85@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"App\\": "app"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
12
aldarien/url/.gitignore
vendored
12
aldarien/url/.gitignore
vendored
@ -1,12 +0,0 @@
|
|||||||
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
|
|
@ -1,21 +0,0 @@
|
|||||||
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.
|
|
@ -1,2 +0,0 @@
|
|||||||
# url
|
|
||||||
Get relative path url
|
|
@ -1,21 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
function url($path = '', $variables = null) {
|
|
||||||
return App\Contract\URL::url($path, $variables);
|
|
||||||
}
|
|
||||||
function baseUrl() {
|
|
||||||
return url();
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Service;
|
|
||||||
|
|
||||||
use League\Uri\Uri as Http;
|
|
||||||
use League\Uri\Components\Domain as 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'] : '');
|
|
||||||
$scheme = 'http';
|
|
||||||
if (isset($_SERVER['REQUEST_SCHEME'])) {
|
|
||||||
$scheme = $_SERVER['REQUEST_SCHEME'];
|
|
||||||
}
|
|
||||||
if (isset($_SERVER['HTTPS'])) {
|
|
||||||
$scheme = 'https';
|
|
||||||
}
|
|
||||||
$uri = Http::createFromString(\Sabre\Uri\resolve($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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"name" : "aldarien/url",
|
|
||||||
"description" : "Get relative path uri",
|
|
||||||
"type" : "library",
|
|
||||||
"require" : {
|
|
||||||
"aldarien/contract" : "*",
|
|
||||||
"aldarien/root" : "*",
|
|
||||||
"league/uri": "*",
|
|
||||||
"league/uri-components": "*",
|
|
||||||
"sabre/uri": "*"
|
|
||||||
},
|
|
||||||
"require-dev" : {
|
|
||||||
"phpunit/phpunit" : "*"
|
|
||||||
},
|
|
||||||
"license" : "MIT",
|
|
||||||
"authors" : [{
|
|
||||||
"name" : "Aldarien",
|
|
||||||
"email" : "jpvial@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"autoload" : {
|
|
||||||
"psr-4" : {
|
|
||||||
"App\\" : "app"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"app/Helper/functions.php"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
10
aldarien/view/.gitignore
vendored
10
aldarien/view/.gitignore
vendored
@ -1,10 +0,0 @@
|
|||||||
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
|
|
@ -1,21 +0,0 @@
|
|||||||
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.
|
|
@ -1,2 +0,0 @@
|
|||||||
# view
|
|
||||||
View module for my apps
|
|
@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Contract;
|
|
||||||
|
|
||||||
use App\Alias\RemoteConnection;
|
|
||||||
use App\Definition\Contract;
|
|
||||||
use App\Service\Money;
|
|
||||||
use App\Service\Remote;
|
|
||||||
use App\Service\View as ViewService;
|
|
||||||
use GuzzleHttp\Client;
|
|
||||||
|
|
||||||
class View
|
|
||||||
{
|
|
||||||
use Contract;
|
|
||||||
|
|
||||||
protected static function newInstance()
|
|
||||||
{
|
|
||||||
$remote = new Remote(new RemoteConnection());
|
|
||||||
$money = (new Money(new Client([
|
|
||||||
'base_uri' => "http://{$remote->getIP()}:8008",
|
|
||||||
'headers' => ['Accept' => 'application/json']
|
|
||||||
])));
|
|
||||||
return new ViewService(['money' => $money]);
|
|
||||||
}
|
|
||||||
public static function show($template, $variables = null)
|
|
||||||
{
|
|
||||||
$instance = self::getInstance();
|
|
||||||
return $instance->show($template, $variables);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
function view($template, $variables = null) {
|
|
||||||
return \App\Contract\View::show($template, $variables);
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Service;
|
|
||||||
|
|
||||||
use eftec\bladeone\BladeOne;
|
|
||||||
|
|
||||||
class View
|
|
||||||
{
|
|
||||||
protected $views;
|
|
||||||
protected $cache;
|
|
||||||
protected $blade;
|
|
||||||
|
|
||||||
public function __construct(array $variables = [])
|
|
||||||
{
|
|
||||||
$this->views = config('locations.views');
|
|
||||||
$this->cache = config('locations.cache');
|
|
||||||
|
|
||||||
$this->blade = new BladeOne($this->views, $this->cache, null, $variables);
|
|
||||||
}
|
|
||||||
public function show($template, $vars = null)
|
|
||||||
{
|
|
||||||
if ($vars) {
|
|
||||||
return $this->blade->run($template, $vars);
|
|
||||||
}
|
|
||||||
return $this->blade->run($template);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,9 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>View</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
View test
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "aldarien/view",
|
|
||||||
"description": "View module for my apps",
|
|
||||||
"type": "library",
|
|
||||||
"require": {
|
|
||||||
"eftec/bladeone": "*",
|
|
||||||
"aldarien/contract": "*",
|
|
||||||
"aldarien/config": "*"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Aldarien",
|
|
||||||
"email": "aldarien85@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"App\\": "app"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"app/Helper/functions.php"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"phpunit/phpunit": "*"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
return [
|
|
||||||
'base' => root(),
|
|
||||||
'cache' => '{locations.base}/cache',
|
|
||||||
'resources' => '{locations.base}/resources',
|
|
||||||
'views' => '{locations.resources}/views'
|
|
||||||
];
|
|
||||||
?>
|
|
@ -1,17 +0,0 @@
|
|||||||
<?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>
|
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
include_once dirname(__DIR__) . '/vendor/autoload.php';
|
|
||||||
|
|
||||||
echo view('base');
|
|
||||||
?>
|
|
@ -1,9 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>View</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
View test
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,22 +0,0 @@
|
|||||||
<?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'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Alias;
|
|
||||||
|
|
||||||
use PDO;
|
|
||||||
use PDOException;
|
|
||||||
|
|
||||||
class Connection
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
protected string $host,
|
|
||||||
protected string $database,
|
|
||||||
protected string $username,
|
|
||||||
protected string $password,
|
|
||||||
protected ?int $port = null,
|
|
||||||
protected int $retries = 5
|
|
||||||
) {}
|
|
||||||
|
|
||||||
protected PDO $connection;
|
|
||||||
public function connect(): PDO
|
|
||||||
{
|
|
||||||
if (!isset($this->connection)) {
|
|
||||||
$r = 0;
|
|
||||||
$exception = null;
|
|
||||||
while ($r < $this->retries) {
|
|
||||||
try {
|
|
||||||
$dsn = $this->getDsn();
|
|
||||||
$this->connection = new PDO($dsn, $this->username, $this->password);
|
|
||||||
return $this->connection;
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
if ($exception !== null) {
|
|
||||||
$e = new PDOException($e->getMessage(), $e->getCode(), $exception);
|
|
||||||
}
|
|
||||||
$exception = $e;
|
|
||||||
usleep(500);
|
|
||||||
}
|
|
||||||
$r ++;
|
|
||||||
}
|
|
||||||
throw $exception;
|
|
||||||
}
|
|
||||||
return $this->connection;
|
|
||||||
}
|
|
||||||
protected function getDsn(): string
|
|
||||||
{
|
|
||||||
$dsn = "mysql:host={$this->host};dbname={$this->database}";
|
|
||||||
if (isset($this->port)) {
|
|
||||||
$dsn .= ";port={$this->port}";
|
|
||||||
}
|
|
||||||
return $dsn;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Alias\Excel\Style;
|
|
||||||
|
|
||||||
use Slam\Excel\Helper\CellStyleInterface;
|
|
||||||
use Slam\Excel\Pear\Writer\Format;
|
|
||||||
|
|
||||||
class Mes implements CellStyleInterface
|
|
||||||
{
|
|
||||||
public function decorateValue($value)
|
|
||||||
{
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
public function styleCell(Format $format): void
|
|
||||||
{
|
|
||||||
$format->setNumFormat('mmm-YY');
|
|
||||||
$format->setAlign('center');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
use App\Helper\Format as F;
|
|
||||||
class Format
|
|
||||||
{
|
|
||||||
public static function __callstatic($name, $params)
|
|
||||||
{
|
|
||||||
if (method_exists(F, $name)) {
|
|
||||||
return F::$name($params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,87 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Alias;
|
|
||||||
|
|
||||||
use Stringy\Stringy;
|
|
||||||
use App\Contract\Auth;
|
|
||||||
|
|
||||||
class Model extends \Model
|
|
||||||
{
|
|
||||||
public function getTable()
|
|
||||||
{
|
|
||||||
return parent::_get_table_name(static::class);
|
|
||||||
}
|
|
||||||
protected function log()
|
|
||||||
{
|
|
||||||
if (strpos(get_called_class(), 'Incoviba\\common\\') !== false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$user = Auth::User()->id;
|
|
||||||
$orm = $this->orm;
|
|
||||||
$ref = new \ReflectionObject($orm);
|
|
||||||
if (!$ref->hasProperty('_dirty_fields')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$dirty = $ref->getProperty('_dirty_fields');
|
|
||||||
$dirty->setAccessible(true);
|
|
||||||
$new_values = $dirty->getValue($orm);
|
|
||||||
$changes = array_combine(array_keys($new_values), array_fill(0, count($new_values), ['old' => '', 'new' => '']));
|
|
||||||
if ($this->isNew()) {
|
|
||||||
$old = (object) array_combine(array_keys($new_values), array_fill(0, count($new_values), ''));
|
|
||||||
} else {
|
|
||||||
$old = model(get_called_class())->findOne($this->{$this->getId()});
|
|
||||||
}
|
|
||||||
foreach ($new_values as $column => $value) {
|
|
||||||
$changes[$column] = ['column' => $column, 'old' => $old->$column, 'new' => $value];
|
|
||||||
}
|
|
||||||
$action = '[' . get_called_class() . ']';
|
|
||||||
doLog($user, $action, $changes);
|
|
||||||
}
|
|
||||||
public function getId()
|
|
||||||
{
|
|
||||||
if (property_exists(get_called_class(), '_id_column')) {
|
|
||||||
return static::$_id_column;
|
|
||||||
}
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
public function save()
|
|
||||||
{
|
|
||||||
$ref = new \ReflectionObject($this);
|
|
||||||
if ($ref->hasProperty('_timestamps')) {
|
|
||||||
$ref = $ref->getProperty('_timestamps');
|
|
||||||
$ref->setAccessible(true);
|
|
||||||
if ($ref->getValue()) {
|
|
||||||
if ($this->is_new()) {
|
|
||||||
$this->setExpr('created_at', 'NOW()');
|
|
||||||
}
|
|
||||||
$this->setExpr('updated_at', 'NOW()');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!\ORM::getDb()->inTransaction()) {
|
|
||||||
\ORM::getDb()->beginTransaction();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
parent::save();
|
|
||||||
if (\ORM::getDb()->inTransaction()) {
|
|
||||||
\ORM::getDb()->commit();
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
if (\ORM::getDb()->inTransaction()) {
|
|
||||||
\ORM::getDb()->rollBack();
|
|
||||||
}
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
$this->log();
|
|
||||||
}
|
|
||||||
public function __call($method, $args)
|
|
||||||
{
|
|
||||||
if (!method_exists($this, $method)) {
|
|
||||||
$str = '' . Stringy::create($method)->underscored();
|
|
||||||
if (method_exists($this, $str)) {
|
|
||||||
return call_user_func_array([$this, $str], $args);
|
|
||||||
}
|
|
||||||
throw new \BadMethodCallException($method . ' not found in ' . get_class($this));
|
|
||||||
}
|
|
||||||
return call_user_func_array([$this, $str], $args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Alias;
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Aldarien
|
|
||||||
* @property int id
|
|
||||||
* @property Date fecha
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class NewEstado extends NewModel
|
|
||||||
{
|
|
||||||
public function fecha()
|
|
||||||
{
|
|
||||||
return Carbon::parse($this->fecha, config('app.timezone'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Alias;
|
|
||||||
|
|
||||||
class NewModel extends Model
|
|
||||||
{
|
|
||||||
protected static $_connection_name = 'mysql_copy';
|
|
||||||
protected static $_timestamps = true;
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Alias;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Aldarien
|
|
||||||
* @property int id
|
|
||||||
* @property string descripcion
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class NewTipo extends NewModel
|
|
||||||
{
|
|
||||||
protected static $_timestamps = true;
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Alias;
|
|
||||||
|
|
||||||
class OldModel extends Model
|
|
||||||
{
|
|
||||||
protected static $_connection_name = 'mysql';
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,155 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Alias;
|
|
||||||
|
|
||||||
use Slam\Excel\Helper as ExcelHelper;
|
|
||||||
|
|
||||||
class PHPExcel
|
|
||||||
{
|
|
||||||
protected $name;
|
|
||||||
protected $filename;
|
|
||||||
protected $columns;
|
|
||||||
protected $data;
|
|
||||||
|
|
||||||
public function __construct($name, $filename)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
$this->filename = $filename;
|
|
||||||
}
|
|
||||||
public function addColumns($fields)
|
|
||||||
{
|
|
||||||
$columns = [];
|
|
||||||
foreach ($fields as $i => $field) {
|
|
||||||
if (is_object($field)) {
|
|
||||||
if (isset($field->style)) {
|
|
||||||
$style = $this->getExcelStyle($field->style);
|
|
||||||
} else {
|
|
||||||
$style = $this->getExcelStyle();
|
|
||||||
}
|
|
||||||
$column = new ExcelHelper\Column($field->name, $field->name, 10, $style);
|
|
||||||
} elseif (is_array($field)) {
|
|
||||||
if (isset($field['style'])) {
|
|
||||||
$style = $this->getExcelStyle($field['style']);
|
|
||||||
} else {
|
|
||||||
$style = $this->getExcelStyle();
|
|
||||||
}
|
|
||||||
$column = new ExcelHelper\Column($field['name'], $field['name'], 10, $style);
|
|
||||||
} else {
|
|
||||||
$style = $this->getExcelStyle();
|
|
||||||
$column = new ExcelHelper\Column($field, $field, 10, $style);
|
|
||||||
}
|
|
||||||
$columns []= $column;
|
|
||||||
}
|
|
||||||
$collection = new ExcelHelper\ColumnCollection($columns);
|
|
||||||
$this->columns = $collection;
|
|
||||||
}
|
|
||||||
protected function getExcelStyle($style = 'text')
|
|
||||||
{
|
|
||||||
switch (strtolower($style)) {
|
|
||||||
case 'date':
|
|
||||||
return new ExcelHelper\CellStyle\Date();
|
|
||||||
case 'mes':
|
|
||||||
return new Excel\Style\Mes();
|
|
||||||
case 'currency':
|
|
||||||
case 'amount':
|
|
||||||
return new ExcelHelper\CellStyle\Amount();
|
|
||||||
case 'number':
|
|
||||||
case 'integer':
|
|
||||||
return new ExcelHelper\CellStyle\Integer();
|
|
||||||
case 'percent':
|
|
||||||
case 'percentage':
|
|
||||||
return new ExcelHelper\CellStyle\Percentage();
|
|
||||||
case 'text':
|
|
||||||
case 'string':
|
|
||||||
default:
|
|
||||||
return new ExcelHelper\CellStyle\Text();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function addData($data)
|
|
||||||
{
|
|
||||||
if ($this->data == null) {
|
|
||||||
$this->data = [];
|
|
||||||
}
|
|
||||||
$this->data = array_merge($data);
|
|
||||||
}
|
|
||||||
public function addRow($rowData)
|
|
||||||
{
|
|
||||||
if ($this->data == null) {
|
|
||||||
$this->data = [];
|
|
||||||
}
|
|
||||||
$this->data []= $rowData;
|
|
||||||
}
|
|
||||||
public function addTotals($totals)
|
|
||||||
{
|
|
||||||
$columns = (array) $this->columns;
|
|
||||||
$columns = array_pop($columns);
|
|
||||||
$ts = [];
|
|
||||||
foreach ($columns as $column) {
|
|
||||||
$col = $column->getHeading();
|
|
||||||
if (isset($totals[$col])) {
|
|
||||||
$ts[$col] = $this->getTotal($col, $totals[$col]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$ts[$col] = '';
|
|
||||||
}
|
|
||||||
$this->data []= $ts;
|
|
||||||
}
|
|
||||||
protected function getTotal($col, $aggr)
|
|
||||||
{
|
|
||||||
$col_num = $this->getColNumber($col);
|
|
||||||
$col = $this->getColName($col_num);
|
|
||||||
switch(strtolower($aggr)) {
|
|
||||||
case 'sum':
|
|
||||||
$num = 109;
|
|
||||||
break;
|
|
||||||
case 'count':
|
|
||||||
$num = 102;
|
|
||||||
break;
|
|
||||||
case 'counta':
|
|
||||||
$num = 103;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$num = 0;
|
|
||||||
}
|
|
||||||
if ($num > 0) {
|
|
||||||
$end = count($this->data) + 2;
|
|
||||||
$str = "=SUBTOTAL({$num};{$col}3:{$col}{$end})";
|
|
||||||
return $str;
|
|
||||||
}
|
|
||||||
return $aggr;
|
|
||||||
}
|
|
||||||
protected function getColNumber($col)
|
|
||||||
{
|
|
||||||
$columns = (array) $this->columns;
|
|
||||||
$columns = array_keys(array_pop($columns));
|
|
||||||
return array_search($col, $columns);
|
|
||||||
}
|
|
||||||
protected function getColName($col_num)
|
|
||||||
{
|
|
||||||
$cols = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
||||||
$N = strlen($cols);
|
|
||||||
$name = '';
|
|
||||||
if ($col_num > $N) {
|
|
||||||
$name .= $cols[floor($col_num / $N)];
|
|
||||||
$col_num = $N * ($col_num / $N - floor($col_num / $N));
|
|
||||||
}
|
|
||||||
$name .= $cols[$col_num];
|
|
||||||
return $name;
|
|
||||||
}
|
|
||||||
public function informe()
|
|
||||||
{
|
|
||||||
header("Content-Type: application/octet-stream; charset=utf-8");
|
|
||||||
header('Content-Transfer-Encoding: binary');
|
|
||||||
header('Content-Disposition: attachment; filename="' . $this->filename . '"');
|
|
||||||
header('Cache-Control: max-age=0');
|
|
||||||
|
|
||||||
$pE = new ExcelHelper\TableWorkbook('php://output');
|
|
||||||
$ws = $pE->addWorksheet($this->name);
|
|
||||||
|
|
||||||
$table = new ExcelHelper\Table($ws, 0, 0, $this->name, new \ArrayIterator($this->data));
|
|
||||||
$table->setColumnCollection($this->columns);
|
|
||||||
|
|
||||||
$pE->writeTable($table);
|
|
||||||
|
|
||||||
$pE->close();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Alias;
|
|
||||||
|
|
||||||
class RemoteConnection extends Connection
|
|
||||||
{
|
|
||||||
public function __construct(protected int $retries = 5)
|
|
||||||
{
|
|
||||||
parent::__construct(
|
|
||||||
$_ENV['REMOTE_HOST'],
|
|
||||||
$_ENV['REMOTE_DATABASE'],
|
|
||||||
$_ENV['REMOTE_USER'],
|
|
||||||
$_ENV['REMOTE_PASSWORD'],
|
|
||||||
$_ENV['REMOTE_PORT'] ?? null,
|
|
||||||
$this->retries
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Command\Money;
|
|
||||||
|
|
||||||
use DateTimeInterface;
|
|
||||||
use DateTimeImmutable;
|
|
||||||
use PDO;
|
|
||||||
use PDOException;
|
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
||||||
use App\Alias\Connection;
|
|
||||||
use App\Service\Money;
|
|
||||||
|
|
||||||
#[AsCommand(
|
|
||||||
name: 'money:uf:get',
|
|
||||||
hidden: false
|
|
||||||
)]
|
|
||||||
class Get extends Command
|
|
||||||
{
|
|
||||||
public function __construct(protected Money $service, protected Connection $connection, string $name = null)
|
|
||||||
{
|
|
||||||
parent::__construct($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
|
||||||
{
|
|
||||||
$io = new SymfonyStyle($input, $output);
|
|
||||||
$io->title('Get Money');
|
|
||||||
|
|
||||||
$dates = $this->getDates();
|
|
||||||
foreach ($dates as $date_string => $ids) {
|
|
||||||
$date = $this->parseDate($date_string);
|
|
||||||
$response = $this->service->getUF($date);
|
|
||||||
if ($response->total === 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
foreach ($ids as $id) {
|
|
||||||
$this->queueUpdate($id, $response->uf->value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->updateUF();
|
|
||||||
return Command::SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getDates(): array
|
|
||||||
{
|
|
||||||
$query = "SELECT id, fecha FROM pago WHERE uf IS NULL AND fecha BETWEEN 0 AND DATE_ADD(CURDATE(), INTERVAL 9 DAY) ORDER BY fecha";
|
|
||||||
$statement = $this->connection->connect()->query($query);
|
|
||||||
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
if (count($rows) === 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
$dates = [];
|
|
||||||
foreach ($rows as $row) {
|
|
||||||
if (!isset($dates[$row['fecha']])) {
|
|
||||||
$dates[$row['fecha']] = [];
|
|
||||||
}
|
|
||||||
$dates[$row['fecha']] []= (int) $row['id'];
|
|
||||||
}
|
|
||||||
return $dates;
|
|
||||||
}
|
|
||||||
protected function parseDate(string $date_string): DateTimeInterface
|
|
||||||
{
|
|
||||||
return new DateTimeImmutable($date_string);
|
|
||||||
}
|
|
||||||
protected array $rows;
|
|
||||||
protected function queueUpdate(int $id, float $value): void
|
|
||||||
{
|
|
||||||
$this->rows []= [$value, $id];
|
|
||||||
}
|
|
||||||
protected function updateUF(): void
|
|
||||||
{
|
|
||||||
$query = "UPDATE pago SET uf = ? WHERE id = ?";
|
|
||||||
$statement = $this->connection->connect()->prepare($query);
|
|
||||||
foreach ($this->rows as $row) {
|
|
||||||
$this->connection->connect()->beginTransaction();
|
|
||||||
try {
|
|
||||||
$statement->execute($row);
|
|
||||||
$this->connection->connect()->commit();
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
$this->connection->connect()->rollBack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Command\Money;
|
|
||||||
|
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
||||||
use App\Alias\Connection;
|
|
||||||
|
|
||||||
#[AsCommand(
|
|
||||||
name: 'money:lookup',
|
|
||||||
hidden: false
|
|
||||||
)]
|
|
||||||
class Lookup extends Command
|
|
||||||
{
|
|
||||||
public function __construct(protected Connection $connection, string $name = null)
|
|
||||||
{
|
|
||||||
parent::__construct($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output)
|
|
||||||
{
|
|
||||||
$io = new SymfonyStyle($input, $output);
|
|
||||||
$io->title('Lookup Money');
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
$io->info('Checking pending');
|
|
||||||
if ($this->hasPendingMoney()) {
|
|
||||||
$io->success('Running money get UF');
|
|
||||||
$io->note($this->runGetUF());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Command::SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function hasPendingMoney(): bool
|
|
||||||
{
|
|
||||||
$query = "SELECT 1 FROM pago WHERE uf IS NULL AND fecha BETWEEN 0 AND DATE_ADD(CURDATE(), INTERVAL 9 DAY)";
|
|
||||||
$statement = $this->connection->connect()->query($query);
|
|
||||||
return $statement->rowCount() > 0;
|
|
||||||
}
|
|
||||||
protected function runGetUF(): string
|
|
||||||
{
|
|
||||||
$command = "/code/bin/console money:uf:get";
|
|
||||||
$result = shell_exec($command);
|
|
||||||
if (!$result or $result === null) {
|
|
||||||
throw new \Exception();
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Contract;
|
|
||||||
|
|
||||||
use App\Definition\Contract;
|
|
||||||
use App\Service\Auth as AuthService;
|
|
||||||
|
|
||||||
class Auth
|
|
||||||
{
|
|
||||||
use Contract;
|
|
||||||
|
|
||||||
protected static function newInstance()
|
|
||||||
{
|
|
||||||
return new AuthService();
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Contract;
|
|
||||||
|
|
||||||
use App\Definition\Contract;
|
|
||||||
use App\Service\Route as RouteService;
|
|
||||||
|
|
||||||
class Route
|
|
||||||
{
|
|
||||||
use Contract;
|
|
||||||
|
|
||||||
protected static function newInstance()
|
|
||||||
{
|
|
||||||
return new RouteService();
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Controller\API;
|
|
||||||
|
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
|
||||||
use Incoviba\old\Proyecto\Proyecto;
|
|
||||||
|
|
||||||
class Unidades {
|
|
||||||
public function no_reservadas(Request $request, Response $response, $id_proyecto, $id_tipo) {
|
|
||||||
$proyecto = model(Proyecto::class)->findOne($id_proyecto);
|
|
||||||
if (!$proyecto) {
|
|
||||||
throw new \InvalidArgumentException('Proyecto identificado por ' . $id_proyecto . ' no existe.');
|
|
||||||
}
|
|
||||||
$unidades = $proyecto->unidades($id_tipo);
|
|
||||||
$unidades = array_filter($unidades, function($item) {
|
|
||||||
return !$item->isVendida() and !$item->isReservada();
|
|
||||||
});
|
|
||||||
$unidades = array_map(function($item) {
|
|
||||||
return $item->asArray();
|
|
||||||
}, $unidades);
|
|
||||||
usort($unidades, function($a, $b) {
|
|
||||||
$ap = strpos($a['descripcion'], ' ');
|
|
||||||
$ad = $a['descripcion'];
|
|
||||||
if ($ap != false) {
|
|
||||||
$ad = substr($ad, 0, $ap);
|
|
||||||
}
|
|
||||||
$bd = $b['descripcion'];
|
|
||||||
$bp = strpos($b['descripcion'], ' ');
|
|
||||||
if ($bp != false) {
|
|
||||||
$bd = substr($bd, 0, $bp);
|
|
||||||
}
|
|
||||||
return strcmp(
|
|
||||||
str_pad($ad, 4, '0', \STR_PAD_LEFT),
|
|
||||||
str_pad($bd, 4, '0', \STR_PAD_LEFT)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
$output = array_values($unidades);
|
|
||||||
$response->getBody()->write(\json_encode($output));
|
|
||||||
return $response->withHeader('Content-Type', 'application/json');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,233 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Controller;
|
|
||||||
|
|
||||||
use App\Service\DBToModel;
|
|
||||||
use App\Definition\Controller;
|
|
||||||
use Incoviba\common\Action;
|
|
||||||
|
|
||||||
class Admin
|
|
||||||
{
|
|
||||||
use Controller;
|
|
||||||
|
|
||||||
protected static function setDefault()
|
|
||||||
{
|
|
||||||
self::$default = view('admin.base');
|
|
||||||
}
|
|
||||||
public static function models()
|
|
||||||
{
|
|
||||||
$data = config('databases');
|
|
||||||
$databases = array_keys($data);
|
|
||||||
return view('admin.models', compact('databases'));
|
|
||||||
}
|
|
||||||
public static function listModels()
|
|
||||||
{
|
|
||||||
$db = post('database');
|
|
||||||
$modeler = new DBToModel($db);
|
|
||||||
echo $modeler->list();
|
|
||||||
}
|
|
||||||
public static function listNamespaces()
|
|
||||||
{
|
|
||||||
$base = [
|
|
||||||
'Common',
|
|
||||||
'Inmobiliaria',
|
|
||||||
'Proyecto',
|
|
||||||
'Venta'
|
|
||||||
];
|
|
||||||
$nss = [
|
|
||||||
'Incoviba' => [
|
|
||||||
'old' => $base,
|
|
||||||
'new' => $base
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
echo json_encode(['namespaces' => self::collapseMultiArray($nss)]);
|
|
||||||
}
|
|
||||||
protected static function collapseMultiArray($array, $level = '')
|
|
||||||
{
|
|
||||||
$output = [];
|
|
||||||
foreach ($array as $key => $subarray) {
|
|
||||||
if (is_array($subarray)) {
|
|
||||||
$output = array_merge($output, self::collapseMultiArray($subarray, $level . '\\' . $key));
|
|
||||||
} else {
|
|
||||||
$output []= $level . '\\' . $subarray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
public static function createModel()
|
|
||||||
{
|
|
||||||
$db = post('database');
|
|
||||||
$ns = post('namespace');
|
|
||||||
$table = post('table');
|
|
||||||
|
|
||||||
$modeler = new DBToModel($db);
|
|
||||||
echo $modeler->create($ns, $table);
|
|
||||||
}
|
|
||||||
public static function list_roles()
|
|
||||||
{
|
|
||||||
$roles = \Model::factory(\Incoviba\common\Role::class)->findMany();
|
|
||||||
echo view('admin.roles.list', compact('roles'));
|
|
||||||
}
|
|
||||||
public static function add_role()
|
|
||||||
{
|
|
||||||
echo view('admin.roles.add');
|
|
||||||
}
|
|
||||||
public static function do_add_role()
|
|
||||||
{
|
|
||||||
$role = \Model::factory(\Incoviba\common\Role::class)->where('description', post('description'))->findOne();
|
|
||||||
if ($role === false) {
|
|
||||||
$role = \Model::factory(\Incoviba\common\Role::class)->create(['description' => post('description')]);
|
|
||||||
$role->save();
|
|
||||||
}
|
|
||||||
header('Location: ' . nUrl('admin', 'add_role'));
|
|
||||||
}
|
|
||||||
public static function role()
|
|
||||||
{
|
|
||||||
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
|
|
||||||
$actions = model(Action::class)->orderByAsc('description')->findMany();
|
|
||||||
$permissions = [];
|
|
||||||
foreach ($actions as $action) {
|
|
||||||
$permissions []= (object) ['description' => $action->description, 'status' => false, 'inherited' => false];
|
|
||||||
}
|
|
||||||
array_walk($permissions, function(&$el, $i, $role) {
|
|
||||||
if ($role->checkAccess($el->description)) {
|
|
||||||
$el->status = true;
|
|
||||||
if ($role->isInherited($el->description)) {
|
|
||||||
$el->inherited = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, $role);
|
|
||||||
echo view('admin.roles.show', compact('role', 'permissions'));
|
|
||||||
}
|
|
||||||
public static function add_role_permissions()
|
|
||||||
{
|
|
||||||
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
|
|
||||||
$locations = \Model::factory(\Incoviba\common\Location::class)->findMany();
|
|
||||||
$actions = model(\Incoviba\common\Action::class)->findMany();
|
|
||||||
echo view('admin.roles.add_permissions', compact('role', 'locations', 'actions'));
|
|
||||||
}
|
|
||||||
public static function do_add_role_permissions()
|
|
||||||
{
|
|
||||||
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
|
|
||||||
$actions = model(\Incoviba\common\Action::class)->findMany();
|
|
||||||
foreach ($actions as $action) {
|
|
||||||
$p = \Model::factory(\Incoviba\common\Permission::class)->where('type', 2)->where('ext_id', $role->id)->where('action_id', $action->id)->findOne();
|
|
||||||
if (array_search($action->id, post('allowed'))) {
|
|
||||||
if (!$p) {
|
|
||||||
$data = [
|
|
||||||
'type' => 2,
|
|
||||||
'ext_id' => $role->id,
|
|
||||||
'action_id' => $action->id
|
|
||||||
];
|
|
||||||
$p = model(\Incoviba\common\Permission::class)->create($data);
|
|
||||||
}
|
|
||||||
$p->status = 1;
|
|
||||||
} else {
|
|
||||||
if ($p !== false) {
|
|
||||||
$p->status = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($p !== false) {
|
|
||||||
$p->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header('Location: ' . nUrl('admin', 'role', ['role' => $role->id]));
|
|
||||||
}
|
|
||||||
public static function list_users()
|
|
||||||
{
|
|
||||||
$users = \Model::factory(\Incoviba\common\User::class)->orderByAsc('name')->findMany();
|
|
||||||
echo view('admin.users.list', compact('users'));
|
|
||||||
}
|
|
||||||
public static function add_user()
|
|
||||||
{
|
|
||||||
echo view('admin.users.add');
|
|
||||||
}
|
|
||||||
public static function do_add_user()
|
|
||||||
{
|
|
||||||
$user = \Model::factory(\Incoviba\common\User::class)->where('name', post('name'))->findOne();
|
|
||||||
if ($user === false) {
|
|
||||||
$user = \Model::factory(\Incoviba\common\User::class)->create();
|
|
||||||
$user->name = post('name');
|
|
||||||
$user->password(post('password'));
|
|
||||||
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
header('Location: ' . url('', ['p' => 'admin', 'a' => 'add_user']));
|
|
||||||
}
|
|
||||||
public static function user()
|
|
||||||
{
|
|
||||||
$user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user'));
|
|
||||||
echo view('admin.users.show', compact('user'));
|
|
||||||
}
|
|
||||||
public static function add_user_role()
|
|
||||||
{
|
|
||||||
if (get('user') !== false) {
|
|
||||||
$user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user'));
|
|
||||||
$roles = \Model::factory(\Incoviba\common\Role::class)->findMany();
|
|
||||||
return view('admin.users.add_role', compact('user', 'roles'));
|
|
||||||
} elseif (get('role') !== false) {
|
|
||||||
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
|
|
||||||
$users = \Model::factory(\Incoviba\common\User::class)->findMany();
|
|
||||||
return view('admin.roles.add_users', compact('users', 'role'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static function do_add_user_role()
|
|
||||||
{
|
|
||||||
if (get('user') !== false) {
|
|
||||||
$user = \Model::factory(\Incoviba\common\User::class)->findOne(get('user'));
|
|
||||||
foreach (post('role') as $r_id) {
|
|
||||||
$role = \Model::factory(\Incoviba\common\Role::class)->findOne($r_id);
|
|
||||||
|
|
||||||
$usrRl = \Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne();
|
|
||||||
if ($usrRl === false) {
|
|
||||||
$usrRl = \Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]);
|
|
||||||
$usrRl->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header('Location: ' . url('', ['p' => 'admin', 'a' => 'user', 'user' => $user->id]));
|
|
||||||
} elseif (get('role') !== false) {
|
|
||||||
$role = \Model::factory(\Incoviba\common\Role::class)->findOne(get('role'));
|
|
||||||
foreach (post('users') as $u_id) {
|
|
||||||
$user = \Model::factory(\Incoviba\common\User::class)->findOne($u_id);
|
|
||||||
|
|
||||||
$usrRl = \Model::factory(\Incoviba\common\UserRole::class)->where('user', $user->id)->where('role', $role->id)->findOne();
|
|
||||||
if ($usrRl === false) {
|
|
||||||
$usrRl = \Model::factory(\Incoviba\common\UserRole::class)->create(['user' => $user->id, 'role' => $role->id]);
|
|
||||||
$usrRl->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header('Location: ' . url('', ['p' => 'admin', 'a' => 'role', 'role' => $role->id]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static function remove_user_role()
|
|
||||||
{
|
|
||||||
$q = "DELETE FROM user_roles WHERE user = ? AND role = ?";
|
|
||||||
$st = \ORM::getDb()->prepare($q);
|
|
||||||
$st->execute([get('user'), get('role')]);
|
|
||||||
header('Location: ' . nUrl('admin'));
|
|
||||||
}
|
|
||||||
public static function delete_user()
|
|
||||||
{
|
|
||||||
$q = "DELETE FROM user_roles WHERE user = ?";
|
|
||||||
$st = \ORM::getDb()->prepare($q);
|
|
||||||
$st->execute([get('user')]);
|
|
||||||
$q = "DELETE FROM logins WHERE user = ?";
|
|
||||||
$st = \ORM::getDb()->prepare($q);
|
|
||||||
$st->execute([get('user')]);
|
|
||||||
$q = "DELETE FROM permissions WHERE type = 1 AND ext_id = ?";
|
|
||||||
$st = \ORM::getDb()->prepare($q);
|
|
||||||
$st->execute([get('user')]);
|
|
||||||
$user = \model(\Incoviba\common\User::class)->findOne(get('user'));
|
|
||||||
$user->delete();
|
|
||||||
header('Location: ' . nUrl('admin', 'list_users'));
|
|
||||||
}
|
|
||||||
public static function reset_user()
|
|
||||||
{
|
|
||||||
$user = model(\Incoviba\common\User::class)->findOne(get('user'));
|
|
||||||
$user->password('123456');
|
|
||||||
$user->save();
|
|
||||||
header('Location: ' . nUrl('admin', 'user', ['user' => $user->id]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,215 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Controller;
|
|
||||||
|
|
||||||
use App\Definition\Controller;
|
|
||||||
use Incoviba\old\Venta\Propietario;
|
|
||||||
use Incoviba\old\Common\Direccion;
|
|
||||||
use Incoviba\old\Inmobiliaria\Inmobiliaria;
|
|
||||||
|
|
||||||
class Ajax
|
|
||||||
{
|
|
||||||
use Controller;
|
|
||||||
|
|
||||||
protected static function setDefault()
|
|
||||||
{
|
|
||||||
self::$default = '';
|
|
||||||
}
|
|
||||||
public static function buscar()
|
|
||||||
{
|
|
||||||
$t = get('t');
|
|
||||||
if ($t == null) {
|
|
||||||
$t = get('tipo');
|
|
||||||
if ($t == null) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$method = 'buscar' . str_replace(' ', '', ucwords(str_replace('_', ' ', $t)));
|
|
||||||
if (is_callable('self', $method)) {
|
|
||||||
return self::$method();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected static function buscarBancos()
|
|
||||||
{
|
|
||||||
$bancos = \Model::factory(\Incoviba\old\Common\Banco::class)->whereNotEqual('nombre', '')->order_by_asc('nombre')->findMany();
|
|
||||||
foreach ($bancos as &$banco) {
|
|
||||||
$banco = $banco->as_array('nombre')['nombre'];
|
|
||||||
}
|
|
||||||
return json_encode($bancos);
|
|
||||||
}
|
|
||||||
protected static function buscarBanco()
|
|
||||||
{
|
|
||||||
$q = get('q');
|
|
||||||
if ($q == null) {
|
|
||||||
$q = get('query');
|
|
||||||
if ($q == null) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$bancos = \Model::factory(\Incoviba\old\Common\Banco::class)->whereLike('nombre', '%' . $q . '%')->order_by_asc('nombre')->findMany();
|
|
||||||
foreach ($bancos as &$banco) {
|
|
||||||
$banco = $banco->as_array('nombre')['nombre'];
|
|
||||||
}
|
|
||||||
return json_encode($bancos);
|
|
||||||
}
|
|
||||||
public static function comunas()
|
|
||||||
{
|
|
||||||
$id = post('region');
|
|
||||||
$comunas = \Model::factory(\Incoviba\old\Common\Comuna::class)
|
|
||||||
->select('comuna.*')
|
|
||||||
->join('provincia', ['provincia.id', '=', 'comuna.provincia'])
|
|
||||||
->where('provincia.region', $id)
|
|
||||||
->order_by_asc('comuna.descripcion')
|
|
||||||
->findMany();
|
|
||||||
|
|
||||||
foreach ($comunas as &$comuna) {
|
|
||||||
$comuna = $comuna->as_array('id', 'descripcion');
|
|
||||||
}
|
|
||||||
return json_encode($comunas);
|
|
||||||
}
|
|
||||||
public static function propietario()
|
|
||||||
{
|
|
||||||
$id = post('rut');
|
|
||||||
$propietario = \Model::factory(\Incoviba\old\Venta\Propietario::class)->where('rut', $id)->findOne();
|
|
||||||
if ($propietario) {
|
|
||||||
$propietario = $propietario->as_array();
|
|
||||||
return json_encode($propietario);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public static function direccion()
|
|
||||||
{
|
|
||||||
$id = post('direccion');
|
|
||||||
$direccion = \Model::factory(\Incoviba\old\Common\Direccion::class)->findOne($id);
|
|
||||||
$comuna = $direccion->comuna();
|
|
||||||
$provincia = $comuna->provincia();
|
|
||||||
$region = $provincia->region();
|
|
||||||
$direccion = $direccion->as_array();
|
|
||||||
$direccion['comuna'] = $comuna->as_array();
|
|
||||||
$direccion['comuna']['provincia'] = $provincia->as_array();
|
|
||||||
$direccion['comuna']['provincia']['region'] = $region->as_array();
|
|
||||||
return json_encode($direccion);
|
|
||||||
}
|
|
||||||
public static function tipo_unidades()
|
|
||||||
{
|
|
||||||
$id = post('proyecto');
|
|
||||||
$proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id);
|
|
||||||
$tipos = $proyecto->tipoUnidades();
|
|
||||||
foreach ($tipos as &$tipo) {
|
|
||||||
$tipo = $tipo->as_array();
|
|
||||||
}
|
|
||||||
return json_encode($tipos);
|
|
||||||
}
|
|
||||||
public static function unidades()
|
|
||||||
{
|
|
||||||
$id_proyecto = post('proyecto');
|
|
||||||
$id_tipo = post('tipo');
|
|
||||||
|
|
||||||
$proyecto = model(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id_proyecto);
|
|
||||||
$unidades = $proyecto->unidadesDisponibles($id_tipo);
|
|
||||||
foreach ($unidades as &$unidad) {
|
|
||||||
$tipologia = $unidad->tipologia();
|
|
||||||
$unidad = $unidad->as_array();
|
|
||||||
$unidad['tipologia'] = $tipologia->as_array();
|
|
||||||
if ($tipologia->tipologia()) {
|
|
||||||
$unidad['tipologia']['tipologia'] = (array) $tipologia->tipologia();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$unidad['tipologia']['tipologia'] = ['descripcion' => $tipologia->abreviacion];
|
|
||||||
}
|
|
||||||
return json_encode($unidades);
|
|
||||||
}
|
|
||||||
public static function unidades_precios()
|
|
||||||
{
|
|
||||||
$proyecto = model(\Incoviba\old\Proyecto\Proyecto::class)->findOne(post('proyecto'));
|
|
||||||
$unidades = $proyecto->unidades();
|
|
||||||
usort($unidades, function($a, $b) {
|
|
||||||
$t = $a->tipo - $b->tipo;
|
|
||||||
if ($t == 0) {
|
|
||||||
return (int) $a->descripcion - (int) $b->descripcion;
|
|
||||||
}
|
|
||||||
return $t;
|
|
||||||
});
|
|
||||||
$output = [];
|
|
||||||
foreach ($unidades as $u) {
|
|
||||||
$info = [
|
|
||||||
'id' => $u->id,
|
|
||||||
'abreviacion' => $u->abreviacion,
|
|
||||||
'descripcion' => $u->descripcion,
|
|
||||||
'valor' => '--'
|
|
||||||
];
|
|
||||||
if ($u->precio()) {
|
|
||||||
$info['valor'] = format('ufs', $u->precio()->valor, null, true);
|
|
||||||
}
|
|
||||||
$output []= $info;
|
|
||||||
}
|
|
||||||
return json_encode($output);
|
|
||||||
}
|
|
||||||
public static function operadores()
|
|
||||||
{
|
|
||||||
$id_proyecto = post('proyecto');
|
|
||||||
$proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id_proyecto);
|
|
||||||
$operadores = $proyecto->operadores();
|
|
||||||
foreach ($operadores as &$operador) {
|
|
||||||
$operador = [
|
|
||||||
'id' => $operador->id,
|
|
||||||
'abreviacion' => $operador->abreviacion
|
|
||||||
];
|
|
||||||
}
|
|
||||||
return json_encode($operadores);
|
|
||||||
}
|
|
||||||
public static function promociones()
|
|
||||||
{
|
|
||||||
$id = post('proyecto');
|
|
||||||
$proyecto = \Model::factory(\Incoviba\old\Proyecto\Proyecto::class)->findOne($id);
|
|
||||||
$promociones = $proyecto->promociones();
|
|
||||||
foreach ($promociones as &$promocion) {
|
|
||||||
$promocion = $promocion->as_array();
|
|
||||||
}
|
|
||||||
return json_encode($promociones);
|
|
||||||
}
|
|
||||||
public static function nombres()
|
|
||||||
{
|
|
||||||
$nss = model(Propietario::class)->select('nombres')->orderByAsc('nombres')->findMany();
|
|
||||||
$nombres = [];
|
|
||||||
foreach ($nss as $n) {
|
|
||||||
$ns = explode(' ', $n->nombres);
|
|
||||||
foreach ($ns as $nombre) {
|
|
||||||
$nombres []= $nombre;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$nombres = array_values(array_unique($nombres));
|
|
||||||
return json_encode($nombres);
|
|
||||||
}
|
|
||||||
public static function apellidos()
|
|
||||||
{
|
|
||||||
$aps = model(Propietario::class)->select('apellido_paterno')->orderByAsc('apellido_paterno')->findMany();
|
|
||||||
$apellidos = [];
|
|
||||||
foreach ($aps as $ap) {
|
|
||||||
$apellidos []= $ap->apellido_paterno;
|
|
||||||
}
|
|
||||||
$aps = model(Propietario::class)->select('apellido_materno')->orderByAsc('apellido_materno')->findMany();
|
|
||||||
foreach ($aps as $ap) {
|
|
||||||
$apellidos []= $ap->apellido_paterno;
|
|
||||||
}
|
|
||||||
$apellidos = array_values(array_unique($apellidos));
|
|
||||||
sort($apellidos);
|
|
||||||
return json_encode($apellidos);
|
|
||||||
}
|
|
||||||
public static function calles()
|
|
||||||
{
|
|
||||||
$results = model(Direccion::class)->select('calle')->orderByAsc('calle')->findMany();
|
|
||||||
$calles = [];
|
|
||||||
foreach ($results as $result) {
|
|
||||||
$calles []= $result->calle;
|
|
||||||
}
|
|
||||||
$calles = array_values(array_unique($calles));
|
|
||||||
return json_encode($calles);
|
|
||||||
}
|
|
||||||
public static function inmobiliarias()
|
|
||||||
{
|
|
||||||
$q = post('rut');
|
|
||||||
$inmobiliaria = model(Inmobiliaria::class)->findOne($q);
|
|
||||||
return json_encode($inmobiliaria->as_array());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,56 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Controller;
|
|
||||||
|
|
||||||
use App\Definition\Controller;
|
|
||||||
use App\Contract\Auth as sAuth;
|
|
||||||
|
|
||||||
class Auth
|
|
||||||
{
|
|
||||||
use Controller;
|
|
||||||
|
|
||||||
public static function login()
|
|
||||||
{
|
|
||||||
return view('auth.login');
|
|
||||||
}
|
|
||||||
public static function do_login()
|
|
||||||
{
|
|
||||||
$name = post('name');
|
|
||||||
$password = post('password');
|
|
||||||
$bool = sAuth::login($name, $password);
|
|
||||||
if ($bool) {
|
|
||||||
header('Location: .');
|
|
||||||
} else {
|
|
||||||
header('Location: ' . url('', ['p' => 'auth', 'a' => 'login']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static function logout()
|
|
||||||
{
|
|
||||||
sAuth::logout();
|
|
||||||
header('Location: .');
|
|
||||||
}
|
|
||||||
public static function check_pass()
|
|
||||||
{
|
|
||||||
if (\password_verify(post('password'), sAuth::User()->password)) {
|
|
||||||
return 'OK';
|
|
||||||
}
|
|
||||||
return 'KO';
|
|
||||||
}
|
|
||||||
public static function change_pass()
|
|
||||||
{
|
|
||||||
return view('auth.change_pass');
|
|
||||||
}
|
|
||||||
public static function do_change_pass()
|
|
||||||
{
|
|
||||||
if (\password_verify(post('old'), sAuth::User()->password)) {
|
|
||||||
if (post('new') == post('new2')) {
|
|
||||||
$user = sAuth::User();
|
|
||||||
$user->password(post('new'));
|
|
||||||
$user->save();
|
|
||||||
header('Location: .');
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header('Location: ' . url('', ['p' => 'auth', 'a' => 'change_pass']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,67 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Controller;
|
|
||||||
|
|
||||||
use App\Definition\Controller;
|
|
||||||
use Incoviba\old\Venta\Venta;
|
|
||||||
use Incoviba\old\Venta\BonoPie;
|
|
||||||
use Incoviba\old\Venta\Pago;
|
|
||||||
|
|
||||||
class Bonos
|
|
||||||
{
|
|
||||||
use Controller;
|
|
||||||
|
|
||||||
public static function add()
|
|
||||||
{
|
|
||||||
$id_venta = get('venta');
|
|
||||||
$venta = model(Venta::class)->findOne($id_venta);
|
|
||||||
return view('ventas.bonos.add', compact('venta'));
|
|
||||||
}
|
|
||||||
public static function do_add()
|
|
||||||
{
|
|
||||||
$id_venta = get('venta');
|
|
||||||
$venta = model(Venta::class)->findOne($id_venta);
|
|
||||||
if ($venta->bono_pie != 0) {
|
|
||||||
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$uf = uf($venta->fecha());
|
|
||||||
$valor = post('valor');
|
|
||||||
$data = [
|
|
||||||
'fecha' => $venta->fecha,
|
|
||||||
'valor' => $valor * $uf->uf->value,
|
|
||||||
'tipo' => 8,
|
|
||||||
'uf' => $uf->uf->value
|
|
||||||
];
|
|
||||||
$pago = model(Pago::class)->create($data);
|
|
||||||
$pago->save();
|
|
||||||
$data = [
|
|
||||||
'valor' => $valor,
|
|
||||||
'pago' => $pago->id
|
|
||||||
];
|
|
||||||
$bono = model(BonoPie::class)->create($data);
|
|
||||||
$bono->save();
|
|
||||||
$venta->bono_pie = $bono->id;
|
|
||||||
$venta->save();
|
|
||||||
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
|
|
||||||
}
|
|
||||||
public static function edit()
|
|
||||||
{
|
|
||||||
$id_venta = get('venta');
|
|
||||||
$venta = model(Venta::class)->findOne($id_venta);
|
|
||||||
return view('ventas.bonos.edit', compact('venta'));
|
|
||||||
}
|
|
||||||
public static function do_edit()
|
|
||||||
{
|
|
||||||
$id_venta = get('venta');
|
|
||||||
$venta = model(Venta::class)->findOne($id_venta);
|
|
||||||
$bono = $venta->bonoPie();
|
|
||||||
$valor = post('valor') * $bono->pago()->uf();
|
|
||||||
$pago = $bono->pago();
|
|
||||||
if ($valor != $bono->pago()->valor()) {
|
|
||||||
$pago->valor = $valor;
|
|
||||||
$pago->save();
|
|
||||||
}
|
|
||||||
header('Location: ' . nUrl('ventas', 'show', ['venta' => $venta->id]));
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user