From 15dfefe5178a6751528ad69b7b08297ceee6cafa Mon Sep 17 00:00:00 2001 From: Aldarien Date: Fri, 16 Jun 2023 00:53:21 +0000 Subject: [PATCH] Version produccion --- PHP.Dockerfile | 7 ++ aldarien/common/Alias/ConfigFile.php | 138 ++++++++++++++++++++++ aldarien/common/Alias/Model.php | 8 ++ aldarien/common/Definition/ConfigFile.php | 14 +++ aldarien/common/Service/Config.php | 86 ++++++++++++++ aldarien/src/Config/JSON.php | 17 +++ aldarien/src/Config/PHP.php | 24 ++++ aldarien/src/Config/YAML.php | 18 +++ bootstrap/api/config.php | 8 ++ bootstrap/app.php | 48 ++++++++ bootstrap/common/config.php | 18 +++ bootstrap/common/setup.php | 14 +++ bootstrap/composer.php | 6 + bootstrap/web/config.php | 30 +++++ bootstrap/web/setup.php | 17 +++ common/Controller/API/UF/Value.php | 40 +++++++ common/Controller/Web/Base.php | 16 +++ common/Definition/Handler.php | 9 ++ common/Implementation/Handler.php | 13 ++ composer.json | 36 ++++++ docker-compose.yml | 65 ++++++++++ nginx.conf | 28 +++++ public/.htaccess | 4 + public/api/.htaccess | 4 + public/api/index.php | 8 ++ public/index.php | 8 ++ resources/routes/api.php | 14 +++ resources/routes/api/uf.php | 16 +++ resources/routes/api/uf/value.php | 7 ++ resources/routes/router.php | 10 ++ resources/routes/web.php | 18 +++ resources/views/home.blade.php | 14 +++ resources/views/layout/base.blade.php | 5 + resources/views/layout/body.blade.php | 3 + resources/views/layout/head.blade.php | 5 + resources/views/layout/styles.blade.php | 14 +++ src/UF/Handler.php | 37 ++++++ src/UF/Model.php | 21 ++++ 38 files changed, 848 insertions(+) create mode 100644 PHP.Dockerfile create mode 100644 aldarien/common/Alias/ConfigFile.php create mode 100644 aldarien/common/Alias/Model.php create mode 100644 aldarien/common/Definition/ConfigFile.php create mode 100644 aldarien/common/Service/Config.php create mode 100644 aldarien/src/Config/JSON.php create mode 100644 aldarien/src/Config/PHP.php create mode 100644 aldarien/src/Config/YAML.php create mode 100644 bootstrap/api/config.php create mode 100644 bootstrap/app.php create mode 100644 bootstrap/common/config.php create mode 100644 bootstrap/common/setup.php create mode 100644 bootstrap/composer.php create mode 100644 bootstrap/web/config.php create mode 100644 bootstrap/web/setup.php create mode 100644 common/Controller/API/UF/Value.php create mode 100644 common/Controller/Web/Base.php create mode 100644 common/Definition/Handler.php create mode 100644 common/Implementation/Handler.php create mode 100644 composer.json create mode 100644 docker-compose.yml create mode 100644 nginx.conf create mode 100644 public/.htaccess create mode 100644 public/api/.htaccess create mode 100644 public/api/index.php create mode 100644 public/index.php create mode 100644 resources/routes/api.php create mode 100644 resources/routes/api/uf.php create mode 100644 resources/routes/api/uf/value.php create mode 100644 resources/routes/router.php create mode 100644 resources/routes/web.php create mode 100644 resources/views/home.blade.php create mode 100644 resources/views/layout/base.blade.php create mode 100644 resources/views/layout/body.blade.php create mode 100644 resources/views/layout/head.blade.php create mode 100644 resources/views/layout/styles.blade.php create mode 100644 src/UF/Handler.php create mode 100644 src/UF/Model.php diff --git a/PHP.Dockerfile b/PHP.Dockerfile new file mode 100644 index 0000000..8bd46bb --- /dev/null +++ b/PHP.Dockerfile @@ -0,0 +1,7 @@ +FROM php:7.4-fpm + +RUN docker-php-ext-install pdo pdo_mysql + +#RUN pecl install xdebug-3.0.3 \ +# && docker-php-ext-enable xdebug + diff --git a/aldarien/common/Alias/ConfigFile.php b/aldarien/common/Alias/ConfigFile.php new file mode 100644 index 0000000..a2fc627 --- /dev/null +++ b/aldarien/common/Alias/ConfigFile.php @@ -0,0 +1,138 @@ +name = $name; + } + public function getName(): string { + return $this->name; + } + protected $filename; + public function setFilename(string $filename) { + if (!file_exists($filename)) { + throw new \DomainException('File not found: ' . $filename . ' in ' . get_called_class() . '.'); + } + $this->filename = $filename; + } + protected $data; + public function get(string $name, $default = null) { + $result = $default; + if ($this->has($name)) { + $result = $this->data[$name]; + } + if (is_array($result)) { + foreach ($result as $k => $v) { + $result[$k] = $this->translate($v); + } + return $result; + } + if (is_object($result)) { + foreach ($result as $k => $v) { + $result->$k = $this->translate($v); + } + return $result; + } + $result = $this->translate($result); + return $result; + } + protected function translate($value) { + if (is_object($value)) { + foreach ($value as $k => $v) { + $value->$k = $this->translate($v); + } + return $value; + } + if (is_array($value)) { + foreach ($value as $k => $v) { + $value[$k] = $this->translate($v); + } + return $value; + } + if (strpos($value, '{') !== false) { + preg_match_all('/{(.*)}/', $value, $matches, \PREG_SET_ORDER); + foreach ($matches as $match) { + $value = str_replace($match[0], $this->get($match[1]), $value); + } + } + return $value; + } + public function set(string $name, $value): void { + if ($this->data === null) { + $this->data = []; + } + if (strpos($name, '.') === false) { + $name = implode('.', [$this->name, $name]); + } + $this->data[$name] = $value; + if (is_array($value)) { + $is_object = false; + foreach ($value as $k => $v) { + if (is_numeric($k)) { + continue; + } + $is_object = true; + $n = implode('.', [$name, $k]); + $this->set($n, $v); + } + if ($is_object) { + $this->data[$name] = (object) $this->parse($value); + } + } + if (is_object($value)) { + foreach ($value as $k => $v) { + $n = implode('.', [$name, $k]); + $this->set($n, $v); + } + } + } + protected function parse($value) { + if (is_array($value)) { + $is_object = false; + foreach ($value as $k => $v) { + if (!is_numeric($k)) { + $is_object = true; + } + $value[$k] = $this->parse($v); + } + $value = (object) $value; + } + return $value; + } + public function has(string $name): bool { + if (isset($this->data[$name])) { + return true; + } + return false; + } + protected $loaded; + public function isLoaded(): bool { + return ($this->loaded !== null and $this->loaded); + } + public function toArray() { + $arr = []; + foreach ($this->data as $key => $value) { + $arr[$key] = $this->translate($value); + } + return $arr; + } + protected $position; + public function current() { + return $this->data[array_keys($this->data)[$this->position]]; + } + public function key(): scalar { + return array_keys($this->data)[$this->position]; + } + public function rewind() { + $this->position = 0; + } + public function next() { + $this->position ++; + } + public function valid() { + return isset(array_keys($this->data)[$this->position]); + } +} diff --git a/aldarien/common/Alias/Model.php b/aldarien/common/Alias/Model.php new file mode 100644 index 0000000..cbd0a04 --- /dev/null +++ b/aldarien/common/Alias/Model.php @@ -0,0 +1,8 @@ +folder = $config_folder; + } + public function load() { + $files = new \DirectoryIterator($this->folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + $this->loadFile($file); + } + return $this; + } + protected $files; + protected function loadFile(\SplFileInfo $file): void { + $ext = $file->getExtension(); + $name = strtolower(str_replace(' ', '_', $file->getBasename('.' . $ext))); + $class = implode("\\", [ + 'Aldarien', + 'Config', + str_replace('YML', 'YAML', strtoupper($ext)) + ]); + if (!class_exists($class)) { + return; + } + $obj = new $class(); + $obj->setName($name); + $obj->setFilename($file->getRealPath()); + if ($this->files === null) { + $this->files = []; + } + $this->files []= $obj; + } + public function get(string $name, $default = null) { + foreach ($this->files as $obj) { + if (!$obj->isLoaded()) { + $obj->load(); + } + if ($obj->has($name)) { + return $obj->get($name); + } + } + return $default; + } + public function set(string $name, $value) { + if (strpos($name, '.') === false) { + return false; + } + $arr = explode('.', $name); + $file = array_shift($arr); + $name = implode('.', $arr); + $this->files[$file]->set($name, $value); + } + public function remove(string $name) { + } + public function toArray() { + $arr = []; + foreach ($this->files as $obj) { + if (!$obj->isLoaded()) { + $obj->load(); + } + $arr = array_merge($arr, $obj->toArray()); + } + return $arr; + } + public function offsetExists($offset): bool { + return $this->has($offset); + } + public function offsetGet($offset) { + return $this->get($offset); + } + public function offsetSet($offset, $value) { + $this->set($offset, $value); + } + public function offsetUnset ($offset) { + $this->remove($offset); + } +} diff --git a/aldarien/src/Config/JSON.php b/aldarien/src/Config/JSON.php new file mode 100644 index 0000000..5e10178 --- /dev/null +++ b/aldarien/src/Config/JSON.php @@ -0,0 +1,17 @@ +filename)); + foreach ($data as $k => $v) { + $this->set($k, $v); + } + $this->loaded = true; + } + public function save() { + file_put_contents($this->filename, json_encode($this->data, \JSON_PRETTY_PRINT || \JSON_NUMERIC_CHECK || \JSON_PRESERVE_ZERO_FRACTION)); + } +} diff --git a/aldarien/src/Config/PHP.php b/aldarien/src/Config/PHP.php new file mode 100644 index 0000000..87a6048 --- /dev/null +++ b/aldarien/src/Config/PHP.php @@ -0,0 +1,24 @@ +filename); + foreach ($data as $k => $v) { + $this->set($k, $v); + } + $this->loaded = true; + } + public function save() { + $str = []; + $str []= 'data as $k => $v) { + $str []= "'" . $k . "' => " . $v; + } + $str []= '];'; + $str []= ''; + file_put_contents($this->filename, implode(PHP_EOL, $str)); + } +} diff --git a/aldarien/src/Config/YAML.php b/aldarien/src/Config/YAML.php new file mode 100644 index 0000000..5b7be36 --- /dev/null +++ b/aldarien/src/Config/YAML.php @@ -0,0 +1,18 @@ +filename); + foreach ($data as $k => $v) { + $this->set($k, $v); + } + $this->loaded = true; + } + public function save() { + file_put_contents($this->filename, Spyc::YAMLDump($this->data)); + } +} diff --git a/bootstrap/api/config.php b/bootstrap/api/config.php new file mode 100644 index 0000000..4519773 --- /dev/null +++ b/bootstrap/api/config.php @@ -0,0 +1,8 @@ + DI\decorate(function($prev, Container $c) { + return implode('/', [$prev, 'api']); + }) +]; diff --git a/bootstrap/app.php b/bootstrap/app.php new file mode 100644 index 0000000..bc90528 --- /dev/null +++ b/bootstrap/app.php @@ -0,0 +1,48 @@ +addDefinitions($filename); + } + } +} +$container = $builder->build(); +$app = Bridge::create($container); +$app->setBasePath($container->get('urls.base')); + +foreach ($folders as $folder) { + $filename = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + $folder, + 'middleware.php' + ]); + if (file_exists($filename)) { + include_once $filename; + } +} + +$app->addErrorMiddleware(true, true, true); + +include_once implode(DIRECTORY_SEPARATOR, [ + $container->get('folders.routes'), + 'router.php' +]); diff --git a/bootstrap/common/config.php b/bootstrap/common/config.php new file mode 100644 index 0000000..f1e58af --- /dev/null +++ b/bootstrap/common/config.php @@ -0,0 +1,18 @@ + dirname(__DIR__, 2), + 'folders.config' => DI\string(implode(DIRECTORY_SEPARATOR, [ + '{folders.base}', + 'config' + ])), + 'folders.resources' => DI\string(implode(DIRECTORY_SEPARATOR, [ + '{folders.base}', + 'resources' + ])), + 'folders.routes' => DI\string(implode(DIRECTORY_SEPARATOR, [ + '{folders.resources}', + 'routes' + ])), + //'urls.base' => '/optimus/money' + 'urls.base' => '' +]; diff --git a/bootstrap/common/setup.php b/bootstrap/common/setup.php new file mode 100644 index 0000000..49c3b5f --- /dev/null +++ b/bootstrap/common/setup.php @@ -0,0 +1,14 @@ + function(Container $c) { + return (new Aldarien\Common\Service\Config($c->get('folders.config')))->load(); + }, + GuzzleHttp\ClientInterface::class => function(Container $c) { + return new GuzzleHttp\Client(); + }, + Aldarien\Money\UF\Handler::class => function(Container $c) { + return new Aldarien\Money\UF\Handler($c->get(GuzzleHttp\ClientInterface::class), 'https://mindicador.cl/api/uf'); + } +]; diff --git a/bootstrap/composer.php b/bootstrap/composer.php new file mode 100644 index 0000000..b1e7879 --- /dev/null +++ b/bootstrap/composer.php @@ -0,0 +1,6 @@ + DI\string(implode(DIRECTORY_SEPARATOR, [ + '{folders.resources}', + 'cache' + ])), + 'folders.templates' => DI\string(implode(DIRECTORY_SEPARATOR, [ + '{folders.resources}', + 'views' + ])), + 'web.assets' => (object) [ + 'styles' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/semantic.min.css' + ], + 'scripts' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js', + 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/semantic.min.js' + ], + 'fonts' => [ + 'text/css' => [ + 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/brand-icons.woff', + 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/brand-icons.woff2', + 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/icons.woff', + 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/icons.woff2', + 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/outline-icons.woff', + 'https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.4/themes/default/assets/fonts/outline-icons.woff2' + ] + ] + ] +]; diff --git a/bootstrap/web/setup.php b/bootstrap/web/setup.php new file mode 100644 index 0000000..4c641fa --- /dev/null +++ b/bootstrap/web/setup.php @@ -0,0 +1,17 @@ + function(Container $c) { + return new Slim\Views\Blade( + $c->get('folders.templates'), + $c->get('folders.cache'), + null, + [ + 'base_url' => $c->get('urls.base'), + 'page_language' => 'es', + 'assets' => $c->get('web.assets') + ] + ); + } +]; diff --git a/common/Controller/API/UF/Value.php b/common/Controller/API/UF/Value.php new file mode 100644 index 0000000..ac1cb79 --- /dev/null +++ b/common/Controller/API/UF/Value.php @@ -0,0 +1,40 @@ +get($fecha); + $output = [ + 'uf' => [ + 'date' => $fecha->format('Y-m-d'), + 'value' => $valor + ], + 'total' => 1 + ]; + $response->getBody()->write(json_encode($output)); + return $response + ->withHeader('Content-Type', 'application/json') + ->withStatus(201); + } + public function fecha(Request $request, Response $response, UFHandler $handler, $fecha): Response { + $fecha = Carbon::parse($fecha); + $valor = $handler->get($fecha); + $output = [ + 'uf' => [ + 'date' => $fecha->format('Y-m-d'), + 'value' => $valor + ], + 'total' => 1 + ]; + $response->getBody()->write(json_encode($output)); + return $response + ->withHeader('Content-Type', 'application/json') + ->withStatus(201); + } +} diff --git a/common/Controller/Web/Base.php b/common/Controller/Web/Base.php new file mode 100644 index 0000000..a9e8a1a --- /dev/null +++ b/common/Controller/Web/Base.php @@ -0,0 +1,16 @@ +get($fecha); + return $view->render($response, 'home', compact('fecha', 'valor')); + } +} diff --git a/common/Definition/Handler.php b/common/Definition/Handler.php new file mode 100644 index 0000000..f1bf936 --- /dev/null +++ b/common/Definition/Handler.php @@ -0,0 +1,9 @@ +client = $client; + $this->url = $api_url; + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c200b1c --- /dev/null +++ b/composer.json @@ -0,0 +1,36 @@ +{ + "name": "aldarien/money", + "description": "Money handler", + "type": "project", + "require": { + "slim/slim": "^4.4", + "zeuxisoo/slim-whoops": "^0.7.2", + "rubellum/slim-blade-view": "^0.1.1", + "nyholm/psr7": "^1.2", + "nyholm/psr7-server": "^0.4.1", + "php-di/slim-bridge": "^3.0", + "nesbot/carbon": "^2.32", + "j4mie/paris": "^1.5", + "rmoiseev/spyc": "^0.5.1", + "guzzlehttp/guzzle": "^6.5" + }, + "require-dev": { + "phpunit/phpunit": "^8.5", + "kint-php/kint": "^3.3" + }, + "license": "MIT", + "authors": [ + { + "name": "Aldarien", + "email": "aldarien85@gmail.com" + } + ], + "autoload": { + "psr-4": { + "Aldarien\\Money\\Common\\": "common", + "Aldarien\\Money\\": "src", + "Aldarien\\Common\\": "aldarien/common", + "Aldarien\\": "aldarien/src" + } + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..15a4d3c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,65 @@ +version: '3' + +services: + money-web: + profiles: + - proxy + container_name: money_server + image: nginx:alpine + restart: unless-stopped + ports: + - 8008:80 + volumes: + - .:/code + - ./nginx.conf:/etc/nginx/conf.d/default.conf + depends_on: + - money-php + + money-php: + profiles: + - app + container_name: money_php + build: + context: . + dockerfile: PHP.Dockerfile + restart: unless-stopped + volumes: + - .:/code +# ports: +# - 9124:9000 + + money-db: + profiles: + - db + container_name: money_db + image: mariadb:latest + restart: unless-stopped +# ports: +# - 3307:3306 + environment: + MYSQL_ROOT_PASSWORD: 'money' + MYSQL_DATABASE: 'money' + MYSQL_USER: 'money' + MYSQL_PASSWORD: 'money_pass' + volumes: + - dbdata:/var/lib/mysql + + adminer: + profiles: + - testing + container_name: money_adminer + image: adminer:latest + restart: unless-stopped + ports: + - 8009:8080 + environment: + ADMINER_DESIGN: 'rmsoft_blue' + ADMINER_PLUGINS: 'dump-json' + +networks: + default: + external: true + name: incoviba_network + +volumes: + dbdata: diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..618163f --- /dev/null +++ b/nginx.conf @@ -0,0 +1,28 @@ +server { + listen 80; + server_name money; + index index.php; +# error_log /code/logs/error.log; +# access_log /code/logs/access.log; + root /code/public; + + location / { + try_files $uri /index.php$is_args$args; + } + location /api { + try_files $uri /api/index.php$is_args$args; +# add_header "Content-Type" "application/json"; + } + + location ~ \.php { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + fastcgi_param CONTENT_TYPE $content_type; + fastcgi_index index.php; + fastcgi_pass money-php:9000; + } +} + diff --git a/public/.htaccess b/public/.htaccess new file mode 100644 index 0000000..ead0cf1 --- /dev/null +++ b/public/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^ index.php [QSA,L] diff --git a/public/api/.htaccess b/public/api/.htaccess new file mode 100644 index 0000000..ead0cf1 --- /dev/null +++ b/public/api/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^ index.php [QSA,L] diff --git a/public/api/index.php b/public/api/index.php new file mode 100644 index 0000000..eda88b3 --- /dev/null +++ b/public/api/index.php @@ -0,0 +1,8 @@ +run(); diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..cca2686 --- /dev/null +++ b/public/index.php @@ -0,0 +1,8 @@ +run(); diff --git a/resources/routes/api.php b/resources/routes/api.php new file mode 100644 index 0000000..d9a3cdd --- /dev/null +++ b/resources/routes/api.php @@ -0,0 +1,14 @@ +isDir()) { + continue; + } + include_once $file->getRealPath(); + } +} diff --git a/resources/routes/api/uf.php b/resources/routes/api/uf.php new file mode 100644 index 0000000..b1cfe00 --- /dev/null +++ b/resources/routes/api/uf.php @@ -0,0 +1,16 @@ +group('/uf', function($app) { + $folder = implode(DIRECTORY_SEPARATOR, [ + __DIR__, + 'uf' + ]); + if (file_exists($folder)) { + $files = new DirectoryIterator($folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; + } + include_once $file->getRealPath(); + } + } +}); diff --git a/resources/routes/api/uf/value.php b/resources/routes/api/uf/value.php new file mode 100644 index 0000000..51a89f1 --- /dev/null +++ b/resources/routes/api/uf/value.php @@ -0,0 +1,7 @@ +group('/value', function($app) { + $app->get('/{fecha}', [Value::class, 'fecha']); + $app->get('[/]', Value::class); +}); diff --git a/resources/routes/router.php b/resources/routes/router.php new file mode 100644 index 0000000..4298342 --- /dev/null +++ b/resources/routes/router.php @@ -0,0 +1,10 @@ +isDir()) { + continue; + } + include_once $file->getRealPath(); + } +} + +$app->get('/', Base::class); diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php new file mode 100644 index 0000000..7d03a55 --- /dev/null +++ b/resources/views/home.blade.php @@ -0,0 +1,14 @@ +@extends('layout.base') + +@section('page_content') +
+
+
+ $ {{number_format($valor, 2, ',', '.')}} +
+
+ {{$fecha->format('d/m/Y')}} +
+
+
+@endsection diff --git a/resources/views/layout/base.blade.php b/resources/views/layout/base.blade.php new file mode 100644 index 0000000..14b780a --- /dev/null +++ b/resources/views/layout/base.blade.php @@ -0,0 +1,5 @@ + + +@include('layout.head') +@include('layout.body') + diff --git a/resources/views/layout/body.blade.php b/resources/views/layout/body.blade.php new file mode 100644 index 0000000..1acc349 --- /dev/null +++ b/resources/views/layout/body.blade.php @@ -0,0 +1,3 @@ + + @yield('page_content') + diff --git a/resources/views/layout/head.blade.php b/resources/views/layout/head.blade.php new file mode 100644 index 0000000..34ef0a6 --- /dev/null +++ b/resources/views/layout/head.blade.php @@ -0,0 +1,5 @@ + + + Money + @include('layout.styles') + diff --git a/resources/views/layout/styles.blade.php b/resources/views/layout/styles.blade.php new file mode 100644 index 0000000..ad959dc --- /dev/null +++ b/resources/views/layout/styles.blade.php @@ -0,0 +1,14 @@ +@if (isset($assets->styles)) + @foreach ($assets->styles as $style) + + @endforeach +@endif +@if (isset($assets->fonts)) + @foreach ($assets->fonts as $type => $fonts) + @foreach ($fonts as $font) + + @endforeach + @endforeach +@endif + +@stack('styles') diff --git a/src/UF/Handler.php b/src/UF/Handler.php new file mode 100644 index 0000000..e626557 --- /dev/null +++ b/src/UF/Handler.php @@ -0,0 +1,37 @@ +history === null or !isset($this->history[$date->format('Y-m-d')])) { + $response = $this->client->request('GET', implode('/', [ + $this->url, + $date->format('d-m-Y') + ]), ['verify' => false]); + /* + { + "version": "1.6.0", + "autor": "mindicador.cl", + "codigo": "uf", + "nombre": "Unidad de fomento (UF)", + "unidad_medida": "Pesos", + "serie": [ + { + "fecha": "2020-04-08T04:00:00.000Z", + "valor": 28626.94 + } + ] + } + */ + if ($response->getStatusCode() < 200 or $response->getStatusCode() >= 300) { + $this->history[$date->format('Y-m-d')] = false; + return false; + } + $this->history[$date->format('Y-m-d')] = json_decode($response->getBody())->serie[0]->valor; + } + return $this->history[$date->format('Y-m-d')]; + } +} diff --git a/src/UF/Model.php b/src/UF/Model.php new file mode 100644 index 0000000..074a89e --- /dev/null +++ b/src/UF/Model.php @@ -0,0 +1,21 @@ +date); + } + $this->date = $date->format('Y-m-d'); + } +}