Skip to content

Commit

Permalink
Merge branch 'v2.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
dlepera committed Mar 22, 2021
2 parents 2a41365 + bab2d0d commit e5c7682
Show file tree
Hide file tree
Showing 27 changed files with 1,339 additions and 461 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
vendor
56 changes: 30 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
{
"name": "dlepera88-php/vilex",
"version": "1.1.0",
"license": "MIT",
"authors": [
{"name": "Diego Lepera", "email": "dlepera88@gmail.com"}
],
"require": {
"php": ">=7.1",
"zendframework/zend-diactoros": "2.0.1"
},
"require-dev": {
"phpunit/phpunit": "^7.5"
},
"suggest": {
"dlepera88-php/dlx": "Micro-framework que utiliza a arquitetura Hexagonal (em desenvolvimento)",
"dlepera88-php/painel-dlx": "Painel de administração"
},
"autoload": {
"psr-4": {
"Vilex\\": "src/"
"name": "dlepera88-php/vilex",
"description": "Redenrizador de views.",
"version": "2.1.0",
"license": "MIT",
"authors": [
{
"name": "Diego Lepera",
"email": "dlepera88@gmail.com"
}
],
"require": {
"php": ">=7.1",
"laminas/laminas-diactoros": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5"
},
"suggest": {
"dlepera88-php/dlx": "Micro-framework que utiliza a arquitetura Hexagonal (em desenvolvimento)",
"painel-dlx/painel-dlx": "Painel de administração"
},
"autoload": {
"psr-4": {
"Vilex\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Vilex\\Tests\\": "tests/"
}
}
},
"autoload-dev": {
"psr-4": {
"Vilex\\Tests\\": "tests/"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@

namespace Vilex\Exceptions;

use Exception;

class ViewNaoEncontradaException extends \Exception
class PaginaMestraInvalidaException extends Exception
{
public function __construct(string $view)
/**
* @param string $nome_arquivo
* @return static
*/
public static function naoEncontrada(string $nome_arquivo): self
{
parent::__construct("View {$view} não encontrada!", 404);
return new self("Página mestra {$nome_arquivo} não encontrada!", 10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@

namespace Vilex\Exceptions;

use Exception;

class PaginaMestraNaoEncontradaException extends \Exception
class TemplateInvalidoException extends Exception
{
public function __construct(string $pagina_mestra)
/**
* @param string $nome_arquivo
* @return static
*/
public static function naoEncontrado(string $nome_arquivo): self
{
parent::__construct("Página mestra {$pagina_mestra} não encontrada.", 404);
return new self("Template {$nome_arquivo} não encontrado!", 10);
}
}
69 changes: 69 additions & 0 deletions src/Recursos/AbstractRecurso.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* MIT License
*
* Copyright (c) 2018 PHP DLX
*
* 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 NON INFRINGEMENT. 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.
*/

namespace Vilex\Recursos;


abstract class AbstractRecurso
{
/** @var string */
private $src;

/** @var string|null */
private $versao;

/**
* AbstractRecurso constructor.
* @param string $src
* @param string $versao
*/
public function __construct(string $src, ?string $versao = null)
{
$this->src = $src;
$this->versao = $versao;
}

/**
* @return string
*/
public function getSrc(): string
{
return $this->src;
}

/**
* @return string|null
*/
public function getVersao(): ?string
{
return $this->versao;
}

/**
* Gerar TAG HTML desse recurso
* @return string
*/
abstract function getTagHtml(): string;
}
82 changes: 82 additions & 0 deletions src/Recursos/Javascript.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* MIT License
*
* Copyright (c) 2018 PHP DLX
*
* 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 NON INFRINGEMENT. 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.
*/

namespace Vilex\Recursos;

use Vilex\Services\Array2AtributosHtml;

/**
* Class Javascript
* @package Vilex\Recursos
* @covers JavascriptTest
*/
class Javascript extends AbstractRecurso
{
/** @var null|string */
private $type = null;

/**
* Javascript constructor.
* @param string $src
* @param string $versao
* @param string|null $type
*/
public function __construct(string $src, ?string $versao = null, ?string $type = null)
{
parent::__construct($src, $versao);
$this->type = $type;
}

/**
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}

/**
* @inheritDoc
*/
function getTagHtml(): string
{
$tag_script = '<script %s></script>';
$src_com_versao = $this->getSrc();

if (!empty($this->getVersao())) {
$src_com_versao .= "?{$this->getVersao()}";
}

$atributos = ['src' => $src_com_versao];

if (!empty($this->getType())) {
$atributos['type'] = $this->getType();
}

$attr_html = (new Array2AtributosHtml())->execute($atributos);

return sprintf($tag_script, $attr_html);
}
}
83 changes: 83 additions & 0 deletions src/Recursos/Stylesheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* MIT License
*
* Copyright (c) 2018 PHP DLX
*
* 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 NON INFRINGEMENT. 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.
*/

namespace Vilex\Recursos;

use Vilex\Services\Array2AtributosHtml;

/**
* Class Stylesheet
* @package Vilex\Recursos
* @covers StylesheetTest
*/
class Stylesheet extends AbstractRecurso
{
/** @var string */
private $media = 'all';

/**
* Stylesheet constructor.
* @param string $src
* @param string|null $versao
* @param string $media
*/
public function __construct(string $src, ?string $versao = null, string $media = 'all')
{
parent::__construct($src, $versao);
$this->media = $media;
}

/**
* @return string
*/
public function getMedia(): string
{
return $this->media;
}

/**
* @inheritDoc
*/
function getTagHtml(): string
{
$tag_link = '<link rel="stylesheet" %s>';

$src_com_versao = $this->getSrc();

if (!empty($this->getVersao())) {
$src_com_versao .= "?{$this->getVersao()}";
}

$atributos = ['href' => $src_com_versao];

if (!empty($this->getMedia())) {
$atributos['media'] = $this->getMedia();
}

$attr_html = (new Array2AtributosHtml())->execute($atributos);

return sprintf($tag_link, $attr_html);
}
}
Loading

0 comments on commit e5c7682

Please sign in to comment.