Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
Abel Hoogeveen | 49e567ea30 | |
Abel Hoogeveen | 7f3341bdc2 | |
Abel Hoogeveen | 777a0fe7c5 | |
Abel Hoogeveen | 21c6cb8ae1 | |
Abel Hoogeveen | 00704f5be1 |
|
@ -0,0 +1,30 @@
|
|||
kind: pipeline
|
||||
type: docker
|
||||
name: test
|
||||
|
||||
steps:
|
||||
- name: composer
|
||||
image: composer:latest
|
||||
commands:
|
||||
- composer install
|
||||
|
||||
- name: php74test
|
||||
image: registry.i15.nl/i15/fuzephp:7.4-alpine
|
||||
commands:
|
||||
- docker-php-ext-enable xdebug
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
|
||||
- name: php80test
|
||||
image: registry.i15.nl/i15/fuzephp:8.0-alpine
|
||||
commands:
|
||||
- docker-php-ext-enable xdebug
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
|
||||
- name: coverage
|
||||
image: registry.i15.nl/i15/fuzephp:8.0-alpine
|
||||
commands:
|
||||
- docker-php-ext-enable xdebug
|
||||
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
|
||||
|
||||
image_pull_secrets:
|
||||
- dockerconfig
|
|
@ -3,4 +3,5 @@ composer.phar
|
|||
.idea/
|
||||
build/
|
||||
test/temp/
|
||||
vendor/
|
||||
vendor/
|
||||
*.cache
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
before_script:
|
||||
# Install dependencies
|
||||
- set -xe
|
||||
- apt-get update -yqq
|
||||
- apt-get install git zip unzip -yqq
|
||||
|
||||
stages:
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
|
||||
build:composer:
|
||||
image: php:7.2
|
||||
stage: build
|
||||
script:
|
||||
- curl -sS https://getcomposer.org/installer | php
|
||||
- php composer.phar install
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
test:7.1:
|
||||
stage: test
|
||||
image: php:7.1
|
||||
script:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor
|
||||
|
||||
test:7.2:
|
||||
stage: test
|
||||
image: php:7.2
|
||||
script:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
test:7.3:
|
||||
stage: test
|
||||
image: php:7.3
|
||||
script:
|
||||
- vendor/bin/phpunit -c test/phpunit.xml
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
test:coverage:
|
||||
stage: test
|
||||
image: php:7.2
|
||||
script:
|
||||
- pecl install xdebug
|
||||
- docker-php-ext-enable xdebug
|
||||
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
||||
|
||||
release:
|
||||
stage: deploy
|
||||
image: php:7.2
|
||||
only:
|
||||
- master
|
||||
script:
|
||||
- pecl install xdebug
|
||||
- docker-php-ext-enable xdebug
|
||||
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
|
||||
artifacts:
|
||||
name: "${CI_BUILD_NAME}_${CI_BUILD_REF_NAME}"
|
||||
paths:
|
||||
- build/
|
||||
expire_in: 3 weeks
|
||||
cache:
|
||||
key: "$CI_BUILD_REF_$CI_BUILD_REF_NAME"
|
||||
paths:
|
||||
- vendor/
|
12
.travis.yml
12
.travis.yml
|
@ -1,12 +0,0 @@
|
|||
language: php
|
||||
|
||||
php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
|
||||
script:
|
||||
- php vendor/bin/phpunit -v -c test/phpunit.xml --coverage-text
|
||||
|
||||
before_script:
|
||||
- composer install
|
|
@ -1,7 +1,7 @@
|
|||
FuzeWorks::Layout Component - Readme
|
||||
===================
|
||||
|
||||
Version 1.2.0
|
||||
Version 1.3.0
|
||||
|
||||
A versatile PHP Framework built to perform.
|
||||
|
||||
|
|
|
@ -4,27 +4,22 @@
|
|||
"license": ["MIT"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "TechFuze",
|
||||
"homepage": "https://techfuze.net"
|
||||
},
|
||||
{
|
||||
"name": "FuzeWorks Community",
|
||||
"homepage": "https://techfuze.net/fuzeworks/contributors"
|
||||
"name": "Abel Hoogeveen",
|
||||
"homepage": "https://i15.nl"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0",
|
||||
"fuzeworks/core": "1.2.0-RC5"
|
||||
"php": ">=7.4.0",
|
||||
"fuzeworks/core": "~1.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-json": "*",
|
||||
"smarty/smarty": "3.1.*",
|
||||
"latte/latte": "2.5.*",
|
||||
"phpunit/phpunit": "^7",
|
||||
"mikey179/vfsStream": "1.6.5"
|
||||
"latte/latte": "~2.5",
|
||||
"phpunit/phpunit": "^9",
|
||||
"mikey179/vfsstream": "~1.6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"smarty/smarty": "Template Engine that is natively supported by FuzeWorks.",
|
||||
"ext-json": "For usage with the JSON template engine",
|
||||
"latte/latte": "Template Engine that is natively supported by FuzeWorks"
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -32,5 +27,4 @@
|
|||
"FuzeWorks\\": "src/FuzeWorks/"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -51,17 +51,17 @@ class LayoutDisplayEvent extends Event
|
|||
/**
|
||||
* @var string Contents of the layout
|
||||
*/
|
||||
public $contents;
|
||||
public string $contents;
|
||||
|
||||
/**
|
||||
* @var string File. File that the contents derived from
|
||||
*/
|
||||
public $file;
|
||||
public string $file;
|
||||
|
||||
/**
|
||||
* @var array directories. Directories that the layout file might resides in.
|
||||
* @var array directories. Directories that the layout file might reside in.
|
||||
*/
|
||||
public $directories;
|
||||
public array $directories;
|
||||
|
||||
public function init(string $contents, string $file, array $directories)
|
||||
{
|
||||
|
|
|
@ -53,28 +53,28 @@ class LayoutLoadEvent extends Event
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
public $directory;
|
||||
public string $directory;
|
||||
|
||||
/**
|
||||
* The file of the layout to be loaded.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $file;
|
||||
public string $file;
|
||||
|
||||
/**
|
||||
* The engine the file will be loaded with.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $engine;
|
||||
public object $engine;
|
||||
|
||||
/**
|
||||
* The assigned variables to the template.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $assigned_variables;
|
||||
public array $assigned_variables;
|
||||
|
||||
public function init($file, $directory, $engine, $assigned_variables)
|
||||
{
|
||||
|
@ -90,7 +90,7 @@ class LayoutLoadEvent extends Event
|
|||
* @param string $key Key of the variable
|
||||
* @param mixed $value Value of the variable
|
||||
*/
|
||||
public function assign($key, $value)
|
||||
public function assign(string $key, $value)
|
||||
{
|
||||
$this->assigned_variables[$key] = $value;
|
||||
}
|
||||
|
|
|
@ -44,6 +44,4 @@ namespace FuzeWorks\Exception;
|
|||
*/
|
||||
class LanguageException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
|
@ -46,4 +46,3 @@ class LayoutException extends Exception
|
|||
{
|
||||
}
|
||||
|
||||
?>
|
|
@ -31,14 +31,14 @@
|
|||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
use FuzeWorks\Event\LayoutDisplayEvent;
|
||||
use FuzeWorks\Event\LayoutLoadEvent;
|
||||
use FuzeWorks\TemplateEngine\{JsonEngine,PHPEngine,SmartyEngine,LatteEngine,TemplateEngine};
|
||||
use FuzeWorks\TemplateEngine\{JsonEngine,PHPEngine,LatteEngine,TemplateEngine};
|
||||
use FuzeWorks\Exception\LayoutException;
|
||||
use FuzeWorks\Exception\EventException;
|
||||
|
||||
|
@ -55,56 +55,56 @@ class Layout
|
|||
/**
|
||||
* @var Factory
|
||||
*/
|
||||
protected $factory;
|
||||
protected Factory $factory;
|
||||
|
||||
/**
|
||||
* The file which the current template is loaded from
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $file = null;
|
||||
public ?string $file = null;
|
||||
|
||||
/**
|
||||
* The directory where the current template is loaded from
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $directory = null;
|
||||
public ?string $directory = null;
|
||||
|
||||
/**
|
||||
* All assigned currently assigned to the template.
|
||||
*
|
||||
* @var array Associative Assigned Variable Array
|
||||
*/
|
||||
protected $assigned_variables = array();
|
||||
protected array $assigned_variables = array();
|
||||
|
||||
/**
|
||||
* All engines that can be used for templates.
|
||||
*
|
||||
* @var array of engines
|
||||
*/
|
||||
protected $engines = array();
|
||||
protected array $engines = array();
|
||||
|
||||
/**
|
||||
* All file extensions that can be used and are bound to a template engine.
|
||||
*
|
||||
* @var array of names of engines
|
||||
*/
|
||||
protected $file_extensions = array();
|
||||
protected array $file_extensions = array();
|
||||
|
||||
/**
|
||||
* whether the template engines are already called.
|
||||
*
|
||||
* @var bool True if loaded
|
||||
*/
|
||||
protected $engines_loaded = false;
|
||||
protected bool $engines_loaded = false;
|
||||
|
||||
/**
|
||||
* The currently selected template engine.
|
||||
*
|
||||
* @var TemplateEngine
|
||||
* @var TemplateEngine|null
|
||||
*/
|
||||
protected $current_engine;
|
||||
protected ?TemplateEngine $current_engine = null;
|
||||
|
||||
/**
|
||||
* Standard Component method for initializing components after adding extensions
|
||||
|
@ -128,10 +128,10 @@ class Layout
|
|||
* @return mixed
|
||||
* @throws LayoutException On error
|
||||
* @throws EventException
|
||||
* @throws Exception\ConfigException
|
||||
*/
|
||||
public function display(string $file, array $directories = []): bool
|
||||
{
|
||||
/** @var LayoutDisplayEvent $event */
|
||||
$contents = $this->get($file, $directories);
|
||||
$event = Events::fireEvent('layoutDisplayEvent', $contents, $file, $directories);
|
||||
if (!$event->isCancelled())
|
||||
|
@ -224,7 +224,7 @@ class Layout
|
|||
* @return TemplateEngine
|
||||
* @throws LayoutException
|
||||
*/
|
||||
public function getEngineFromExtension($extension): TemplateEngine
|
||||
public function getEngineFromExtension(string $extension): TemplateEngine
|
||||
{
|
||||
if (isset($this->file_extensions[strtolower($extension)]))
|
||||
return $this->engines[ $this->file_extensions[strtolower($extension)]];
|
||||
|
@ -239,7 +239,7 @@ class Layout
|
|||
*
|
||||
* @return string Extension of the file
|
||||
*/
|
||||
public function getExtensionFromFile($fileString): string
|
||||
public function getExtensionFromFile(string $fileString): string
|
||||
{
|
||||
return substr($fileString, strrpos($fileString, '.') + 1);
|
||||
}
|
||||
|
@ -325,11 +325,11 @@ class Layout
|
|||
*
|
||||
* @param string $string The string used by a controller. eg: 'dashboard/home'
|
||||
* @param array $directories The directory to search in for the template
|
||||
* @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc.
|
||||
* @param array $extensions Extensions to use for this template. Eg array('php', 'tpl') etc.
|
||||
*
|
||||
* @throws LayoutException On error
|
||||
*/
|
||||
public function setFileFromString($string, array $directories, $extensions = array())
|
||||
public function setFileFromString(string $string, array $directories, array $extensions = array())
|
||||
{
|
||||
$arr = $this->getFileFromString($string, $directories, $extensions);
|
||||
$this->file = $arr['file'];
|
||||
|
@ -341,7 +341,7 @@ class Layout
|
|||
*
|
||||
* @return null|string Path to the file
|
||||
*/
|
||||
public function getFile()
|
||||
public function getFile(): ?string
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
|
@ -351,7 +351,7 @@ class Layout
|
|||
*
|
||||
* @param string $file Path to the file
|
||||
*/
|
||||
public function setFile($file)
|
||||
public function setFile(string $file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ class Layout
|
|||
*
|
||||
* @return null|string Path to the directory
|
||||
*/
|
||||
public function getDirectory()
|
||||
public function getDirectory(): ?string
|
||||
{
|
||||
return $this->directory;
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ class Layout
|
|||
*
|
||||
* @param string $directory Path to the directory
|
||||
*/
|
||||
public function setDirectory($directory)
|
||||
public function setDirectory(string $directory)
|
||||
{
|
||||
$this->directory = $directory;
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ class Layout
|
|||
* @param string $key Key of the variable
|
||||
* @param mixed $value Value of the variable
|
||||
*/
|
||||
public function assign($key, $value)
|
||||
public function assign(string $key, $value)
|
||||
{
|
||||
$this->assigned_variables[$key] = $value;
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ class Layout
|
|||
*
|
||||
* @param string $title title of the template
|
||||
*/
|
||||
public function setTitle($title)
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
$this->assigned_variables['title'] = $title;
|
||||
}
|
||||
|
@ -418,7 +418,7 @@ class Layout
|
|||
* @return bool true on success
|
||||
* @throws LayoutException on error
|
||||
*/
|
||||
public function setEngine($name): bool
|
||||
public function setEngine(string $name): bool
|
||||
{
|
||||
$this->loadTemplateEngines();
|
||||
if (isset($this->engines[$name])) {
|
||||
|
@ -509,10 +509,6 @@ class Layout
|
|||
if (class_exists('\Latte\Engine', true))
|
||||
$this->registerEngine(new LatteEngine(), 'Latte', array('latte'));
|
||||
|
||||
// Smarty Engine
|
||||
if (class_exists('\Smarty', true))
|
||||
$this->registerEngine(new SmartyEngine(), 'Smarty', array('tpl'));
|
||||
|
||||
$this->engines_loaded = true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -49,14 +49,14 @@ class JsonEngine implements TemplateEngine
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $assigned_variables = array();
|
||||
protected array $assigned_variables = [];
|
||||
|
||||
/**
|
||||
* Whether the JSON data should be parsed or left as is.
|
||||
*
|
||||
* @var bool true if to be parsed
|
||||
*/
|
||||
protected static $string_return = true;
|
||||
protected static bool $string_return = true;
|
||||
|
||||
/**
|
||||
* Whether the JSON data should be parsed or left as is.
|
||||
|
@ -68,33 +68,26 @@ class JsonEngine implements TemplateEngine
|
|||
self::$string_return = $boolean;
|
||||
}
|
||||
|
||||
public function setDirectory($directory)
|
||||
public function setDirectory(string $directory): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get($file, $assigned_variables)
|
||||
public function get(string $file, array $assigned_variables): string
|
||||
{
|
||||
// First set all the variables
|
||||
$this->assigned_variables = $assigned_variables;
|
||||
|
||||
// First set up the JSON array
|
||||
$json = array();
|
||||
|
||||
// Look up if a file is provided
|
||||
if (!is_null($file)) {
|
||||
// Retrieve a file
|
||||
$string = file_get_contents($file);
|
||||
$json = json_decode($string, true);
|
||||
}
|
||||
// Retrieve a file
|
||||
$string = file_get_contents($file);
|
||||
$json = json_decode($string, true);
|
||||
|
||||
// Then assign all variables
|
||||
$json['data'] = $this->assigned_variables;
|
||||
|
||||
// And return it
|
||||
if (self::$string_return) {
|
||||
if (self::$string_return)
|
||||
return json_encode($json);
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@ class LatteEngine implements TemplateEngine
|
|||
/**
|
||||
* Instance of the Latte Engine
|
||||
*
|
||||
* @var Latte\Engine The Latte Engine to be used
|
||||
* @var Latte|null The Latte Engine to be used
|
||||
*/
|
||||
protected $latte;
|
||||
protected ?Latte $latte;
|
||||
|
||||
/**
|
||||
* Set the directory of the current template.
|
||||
|
@ -62,7 +62,7 @@ class LatteEngine implements TemplateEngine
|
|||
* @param string $directory Template Directory
|
||||
* @throws LayoutException
|
||||
*/
|
||||
public function setDirectory($directory)
|
||||
public function setDirectory(string $directory)
|
||||
{
|
||||
if (class_exists('\Latte\Engine', true))
|
||||
{
|
||||
|
@ -71,20 +71,18 @@ class LatteEngine implements TemplateEngine
|
|||
$this->latte->setTempDirectory(realpath(Core::$tempDir));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new LayoutException("Could not load LatteEngine. Is it installed or Composer not loaded?", 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle and retrieve a template file.
|
||||
*
|
||||
* @param string $file Template File
|
||||
* @param array $assigned_variables All the variables used in this layout
|
||||
* @param array $assigned_variables All the variables used in this layout
|
||||
*
|
||||
* @return string Output of the template
|
||||
*/
|
||||
public function get($file, $assigned_variables)
|
||||
public function get(string $file, array $assigned_variables): string
|
||||
{
|
||||
return $this->latte->renderToString($file, $assigned_variables);
|
||||
}
|
||||
|
@ -106,7 +104,6 @@ class LatteEngine implements TemplateEngine
|
|||
{
|
||||
// If possible, load Latte\Engine
|
||||
$this->latte = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -47,23 +47,23 @@ class PHPEngine implements TemplateEngine
|
|||
/**
|
||||
* The currently used directory by the template.
|
||||
*
|
||||
* @var string
|
||||
* @var string|null
|
||||
*/
|
||||
protected $directory;
|
||||
protected ?string $directory;
|
||||
|
||||
/**
|
||||
* All the currently assigned variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $assigned_variables = array();
|
||||
protected array $assigned_variables = [];
|
||||
|
||||
public function setDirectory($directory)
|
||||
public function setDirectory(string $directory)
|
||||
{
|
||||
$this->directory = $directory;
|
||||
}
|
||||
|
||||
public function get($file, $assigned_variables)
|
||||
public function get(string $file, array $assigned_variables): string
|
||||
{
|
||||
// First set all the variables
|
||||
$this->assigned_variables = $assigned_variables;
|
||||
|
@ -75,12 +75,9 @@ class PHPEngine implements TemplateEngine
|
|||
$$key = $val;
|
||||
|
||||
// Then run the file
|
||||
if (!is_null($file)) {
|
||||
ob_start();
|
||||
include $file;
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
ob_start();
|
||||
include $file;
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function getFileExtensions(): array
|
||||
|
@ -91,7 +88,7 @@ class PHPEngine implements TemplateEngine
|
|||
public function reset(): bool
|
||||
{
|
||||
$this->directory = null;
|
||||
$this->assigned_variables = array();
|
||||
$this->assigned_variables = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,172 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework Layout Template System.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2018 TechFuze
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2018, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\TemplateEngine;
|
||||
|
||||
use FuzeWorks\Core;
|
||||
use Smarty;
|
||||
|
||||
/**
|
||||
* Wrapper for the Smarty Template Engine.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2018, TechFuze. (http://techfuze.net)
|
||||
*/
|
||||
class SmartyEngine implements TemplateEngine
|
||||
{
|
||||
/**
|
||||
* The currently used directory by the template.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* All the currently assigned variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $assigned_variables = array();
|
||||
|
||||
/**
|
||||
* Instance of the Smarty Template Engine.
|
||||
*
|
||||
* @var \Smarty
|
||||
*/
|
||||
protected $smartyInstance;
|
||||
|
||||
public function setDirectory($directory)
|
||||
{
|
||||
$this->directory = $directory;
|
||||
}
|
||||
|
||||
public function get($file, $assigned_variables)
|
||||
{
|
||||
// First set all the variables
|
||||
$this->assigned_variables = $assigned_variables;
|
||||
|
||||
// Load Smarty
|
||||
$this->loadSmarty();
|
||||
|
||||
// Set the directory
|
||||
$this->smartyInstance->setTemplateDir($this->directory);
|
||||
|
||||
// Then assign all variables
|
||||
foreach ($this->assigned_variables as $key => $value) {
|
||||
$this->smartyInstance->assign($key, $value);
|
||||
}
|
||||
|
||||
// And finally, load the template
|
||||
return $this->smartyInstance->fetch($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a Smarty instance if it is not already loaded.
|
||||
*/
|
||||
private function loadSmarty()
|
||||
{
|
||||
if (is_null($this->smartyInstance)) {
|
||||
$this->smartyInstance = new Smarty();
|
||||
|
||||
// Then prepare all variables
|
||||
$this->smartyInstance->setCompileDir(Core::$tempDir . DS . 'Smarty' . DS . 'Compile');
|
||||
$this->smartyInstance->setCacheDir(Core::$tempDir . DS . 'Smarty');
|
||||
}
|
||||
}
|
||||
|
||||
public function getFileExtensions(): array
|
||||
{
|
||||
return array('tpl');
|
||||
}
|
||||
|
||||
public function reset(): bool
|
||||
{
|
||||
$this->smartyInstance = null;
|
||||
$this->directory = null;
|
||||
$this->assigned_variables = array();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a value from Smarty.
|
||||
*
|
||||
* @param string $name Variable name
|
||||
*
|
||||
* @return mixed Variable Value
|
||||
*
|
||||
* @throws \FuzeWorks\LayoutException on error
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
// First load Smarty
|
||||
$this->loadSmarty();
|
||||
|
||||
return $this->smartyInstance->$name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a variable in Smarty.
|
||||
*
|
||||
* @param string $name Variable Name
|
||||
* @param mixed $value Variable Value
|
||||
*
|
||||
* @throws \FuzeWorks\LayoutException on error
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
// First load Smarty
|
||||
$this->loadSmarty();
|
||||
|
||||
$this->smartyInstance->$name = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a function in Smarty.
|
||||
*
|
||||
* @param string $name Name of the function to be called
|
||||
* @param Paramaters $params Parameters to be used
|
||||
*
|
||||
* @return mixed Function output
|
||||
*/
|
||||
public function __call($name, $params)
|
||||
{
|
||||
// First load Smarty
|
||||
$this->loadSmarty();
|
||||
|
||||
return call_user_func_array(array($this->smartyInstance, $name), $params);
|
||||
}
|
||||
}
|
|
@ -49,17 +49,17 @@ interface TemplateEngine
|
|||
*
|
||||
* @param string $directory Template Directory
|
||||
*/
|
||||
public function setDirectory($directory);
|
||||
public function setDirectory(string $directory);
|
||||
|
||||
/**
|
||||
* Handle and retrieve a template file.
|
||||
*
|
||||
* @param string $file Template File
|
||||
* @param array $assigned_variables All the variables used in this layout
|
||||
* @param array $assigned_variables All the variables used in this layout
|
||||
*
|
||||
* @return string Output of the template
|
||||
*/
|
||||
public function get($file, $assigned_variables);
|
||||
public function get(string $file, array $assigned_variables): string;
|
||||
|
||||
/**
|
||||
* Retrieve the file extensions that this template engine uses.
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
|
@ -41,17 +41,11 @@ chdir(dirname(__DIR__));
|
|||
|
||||
// Load the FuzeWorks container
|
||||
$container = require('bootstrap.php');
|
||||
Logger::disableHandlers();
|
||||
|
||||
// Load the test abstract
|
||||
require_once 'layout/LayoutTestAbstract.php';
|
||||
|
||||
// Reset error and exception handlers
|
||||
restore_error_handler();
|
||||
restore_exception_handler();
|
||||
|
||||
// Set logger template for output in CLI
|
||||
Logger::setLoggerTemplate('logger_cli');
|
||||
|
||||
// Display all errors
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
@ -59,4 +53,10 @@ error_reporting(E_ALL | E_STRICT);
|
|||
// Set localhost "remote" IP
|
||||
isset($_SERVER['REMOTE_ADDR']) OR $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
|
||||
// Alias vfsStream
|
||||
class_alias('org\bovigo\vfs\vfsStream', 'vfsStream');
|
||||
class_alias('org\bovigo\vfs\vfsStreamDirectory', 'vfsStreamDirectory');
|
||||
class_alias('org\bovigo\vfs\vfsStreamWrapper', 'vfsStreamWrapper');
|
||||
|
||||
// Set logger template for output in CLI
|
||||
Logger::setLoggerTemplate('logger_cli');
|
|
@ -31,9 +31,11 @@
|
|||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\LayoutComponent;
|
||||
|
||||
require_once(dirname(__DIR__) . '/vendor/autoload.php');
|
||||
|
||||
$configurator = new FuzeWorks\Configurator();
|
||||
|
@ -44,14 +46,14 @@ $configurator->setLogDirectory(dirname(__FILE__) . '/temp');
|
|||
|
||||
// Other values
|
||||
$configurator->setTimeZone('Europe/Amsterdam');
|
||||
$configurator->enableDebugMode(true);
|
||||
|
||||
// Debug related
|
||||
$configurator->enableDebugMode();
|
||||
$configurator->setDebugAddress('ALL');
|
||||
|
||||
// Implement the Layout Component
|
||||
$configurator->addComponent(new \FuzeWorks\LayoutComponent());
|
||||
$configurator->addComponent(new LayoutComponent());
|
||||
|
||||
// Create container
|
||||
$container = $configurator->createContainer();
|
||||
|
||||
// And return the result
|
||||
return $container;
|
||||
return $configurator->createContainer();
|
||||
|
||||
|
|
|
@ -31,9 +31,12 @@
|
|||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Configurator;
|
||||
use FuzeWorks\Exception\EventException;
|
||||
use FuzeWorks\Exception\LayoutException;
|
||||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\Layout;
|
||||
use FuzeWorks\Events;
|
||||
|
@ -57,11 +60,11 @@ class LayoutTest extends LayoutTestAbstract
|
|||
*/
|
||||
protected $layout;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
// Load the factory first
|
||||
$this->factory = Factory::getInstance();
|
||||
$this->layout = Factory::getInstance()->layouts;
|
||||
$this->layout = Factory::getInstance('layouts');
|
||||
$this->layout->reset();
|
||||
}
|
||||
|
||||
|
@ -75,18 +78,18 @@ class LayoutTest extends LayoutTestAbstract
|
|||
$component = new FuzeWorks\LayoutComponent();
|
||||
|
||||
// Prepare container
|
||||
$configurator = new \FuzeWorks\Configurator();
|
||||
$configurator = new Configurator();
|
||||
$configurator->addComponent($component);
|
||||
$configurator->setTempDirectory(dirname(__DIR__) . '/temp');
|
||||
$configurator->setLogDirectory(dirname(__DIR__) . '/temp');
|
||||
|
||||
|
||||
// Create container
|
||||
$container = $configurator->createContainer();
|
||||
|
||||
// Init container;
|
||||
$this->assertTrue(property_exists($container, 'layouts'));
|
||||
$this->assertInstanceOf('FuzeWorks\Layout', $container->layouts);
|
||||
$this->assertInstanceOf('FuzeWorks\Layout', Factory::getInstance('layouts'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,12 +150,13 @@ class LayoutTest extends LayoutTestAbstract
|
|||
|
||||
/**
|
||||
* @depends testGetFilePath
|
||||
* @expectedException FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::setFileFromString
|
||||
* @covers \FuzeWorks\Layout::getFileFromString
|
||||
*/
|
||||
public function testMalformedPaths()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
|
||||
// Extensions to be used in this test
|
||||
$extensions = array('php', 'json');
|
||||
|
||||
|
@ -160,33 +164,35 @@ class LayoutTest extends LayoutTestAbstract
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::setFileFromString
|
||||
* @covers \FuzeWorks\Layout::getFileFromString
|
||||
*/
|
||||
public function testMissingDirectory()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
|
||||
// Directory that does not exist
|
||||
$this->layout->setFileFromString('test', [3=>['test'.DS.'templates'.DS.'doesNotExist']], array('php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::setFileFromString
|
||||
* @covers \FuzeWorks\Layout::getFileFromString
|
||||
*/
|
||||
public function testMissingFile()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
|
||||
$this->layout->setFileFromString('test', [3=>['test'.DS.'templates'.DS.'testMissingFile']], array('php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::setFileFromString
|
||||
* @covers \FuzeWorks\Layout::getFileFromString
|
||||
*/
|
||||
public function testUnknownFileExtension()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
$this->layout->setFileFromString('test', [3=>['test'.DS.'templates'.DS.'testUnknownFileExtension']], array('php'));
|
||||
}
|
||||
|
||||
|
@ -225,12 +231,13 @@ class LayoutTest extends LayoutTestAbstract
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::get
|
||||
* @covers \FuzeWorks\Event\LayoutLoadEvent::init
|
||||
*/
|
||||
public function testLayoutGetEventWrongFile()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
|
||||
$directories = ['test'.DS.'templates'.DS.'testLayoutGetEventWrongFile'];
|
||||
Events::addListener(function($event){
|
||||
$event->file = 'does_not_exist';
|
||||
|
@ -265,7 +272,7 @@ class LayoutTest extends LayoutTestAbstract
|
|||
{
|
||||
$this->layout->setDirectories([3=>['test'.DS.'templates'.DS.'testLayoutGet']]);
|
||||
|
||||
// First the the variables
|
||||
// First the variables
|
||||
$this->layout->setTitle('Test Title');
|
||||
|
||||
// Test if they are actually set
|
||||
|
@ -289,16 +296,16 @@ class LayoutTest extends LayoutTestAbstract
|
|||
// Test all the default engines
|
||||
$this->assertInstanceOf('FuzeWorks\TemplateEngine\PHPEngine', $this->layout->getEngineFromExtension('php'));
|
||||
$this->assertInstanceOf('FuzeWorks\TemplateEngine\JsonEngine', $this->layout->getEngineFromExtension('json'));
|
||||
$this->assertInstanceOf('FuzeWorks\TemplateEngine\SmartyEngine', $this->layout->getEngineFromExtension('tpl'));
|
||||
$this->assertInstanceOf('FuzeWorks\TemplateEngine\LatteEngine', $this->layout->getEngineFromExtension('latte'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetEngineFromExtension
|
||||
* @expectedException FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::getEngineFromExtension
|
||||
*/
|
||||
public function testGetEngineFromExtensionFail()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
$this->layout->getEngineFromExtension('faulty');
|
||||
}
|
||||
|
||||
|
@ -320,13 +327,14 @@ class LayoutTest extends LayoutTestAbstract
|
|||
|
||||
/**
|
||||
* @covers \FuzeWorks\Layout::loadTemplateEngines
|
||||
* @expectedException \FuzeWorks\Exception\LayoutException
|
||||
*/
|
||||
public function testLoadLoadEngineEvent()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
|
||||
Events::addListener(function($event){
|
||||
$this->assertInstanceOf('\FuzeWorks\Event\NotifierEvent', $event);
|
||||
throw new \FuzeWorks\Exception\EventException('Forcing failure in loadTemplateEngines()');
|
||||
throw new EventException('Forcing failure in loadTemplateEngines()');
|
||||
}, 'layoutLoadEngineEvent', Priority::NORMAL);
|
||||
|
||||
$this->layout->loadTemplateEngines();
|
||||
|
@ -357,11 +365,12 @@ class LayoutTest extends LayoutTestAbstract
|
|||
|
||||
/**
|
||||
* @depends testCustomEngine
|
||||
* @expectedException \FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::registerEngine
|
||||
*/
|
||||
public function testExistingCustomEngine()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
|
||||
// Create mock
|
||||
$mock = $this->getMockBuilder('FuzeWorks\TemplateEngine\TemplateEngine')->getMock();
|
||||
$mock->method('get')->willReturn('output');
|
||||
|
@ -375,11 +384,12 @@ class LayoutTest extends LayoutTestAbstract
|
|||
|
||||
/**
|
||||
* @depends testCustomEngine
|
||||
* @expectedException \FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::registerEngine
|
||||
*/
|
||||
public function testCustomEngineWithExistingExtensions()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
|
||||
// Create mock
|
||||
$mock = $this->getMockBuilder('FuzeWorks\TemplateEngine\TemplateEngine')->getMock();
|
||||
$mock->method('get')->willReturn('output');
|
||||
|
@ -419,21 +429,21 @@ class LayoutTest extends LayoutTestAbstract
|
|||
|
||||
/**
|
||||
* @depends testSetEngine
|
||||
* @expectedException \FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::setEngine
|
||||
*/
|
||||
public function testSetInvalidEngine()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
$this->layout->setEngine('invalid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetEngine
|
||||
* @expectedException \FuzeWorks\Exception\LayoutException
|
||||
* @covers \FuzeWorks\Layout::getEngine
|
||||
*/
|
||||
public function testGetInvalidEngine()
|
||||
{
|
||||
$this->expectException(LayoutException::class);
|
||||
$this->layout->getEngine('invalid');
|
||||
}
|
||||
|
||||
|
@ -453,8 +463,8 @@ class LayoutTest extends LayoutTestAbstract
|
|||
$this->assertEquals('JSON Template Check', json_decode($this->layout->get('json', $directories), true)[0]);
|
||||
$this->layout->reset();
|
||||
|
||||
// And the Smarty Engine
|
||||
$this->assertEquals('Smarty Template Check', $this->layout->get('smarty', $directories));
|
||||
// And the Latte Engine
|
||||
$this->assertEquals("Latte Template Check", $this->layout->get('latte', $directories));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -475,10 +485,11 @@ class LayoutTest extends LayoutTestAbstract
|
|||
$this->assertEquals('value', json_decode($this->layout->get('json', $directories), true)['data']['key']);
|
||||
$this->layout->reset();
|
||||
|
||||
// And the Smarty Engine
|
||||
// And the Latte Engine
|
||||
$this->layout->assign('key', 'value');
|
||||
$this->assertEquals('value', $this->layout->get('smarty', $directories));
|
||||
$this->assertEquals('value', $this->layout->get('latte', $directories));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MockEngine {
|
||||
|
|
|
@ -31,9 +31,10 @@
|
|||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
* @version Version 1.3.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Config;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use FuzeWorks\Events;
|
||||
use FuzeWorks\Factory;
|
||||
|
@ -51,15 +52,21 @@ abstract class LayoutTestAbstract extends TestCase
|
|||
*
|
||||
* Reset the layout manager
|
||||
*/
|
||||
public function tearDown()
|
||||
public function tearDown(): void
|
||||
{
|
||||
// Clear all events created by tests
|
||||
Events::$listeners = array();
|
||||
|
||||
// Reset all config files
|
||||
Factory::getInstance()->config->discardConfigFiles();
|
||||
Factory::getInstance('config')->discardConfigFiles();
|
||||
|
||||
// Re-enable events, in case they have been disabled
|
||||
Events::enable();
|
||||
|
||||
// Remove COnfig overrides
|
||||
Config::$configOverrides = [];
|
||||
|
||||
// Remove autoloader
|
||||
Core::clearAutoloader();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,17 @@
|
|||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
|
||||
bootstrap="autoload.php"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
stopOnError="false"
|
||||
stopOnFailure="false"
|
||||
stopOnIncomplete="false"
|
||||
stopOnSkipped="false"
|
||||
colors="false">
|
||||
|
||||
<?xml version="1.0"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="autoload.php" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" colors="false">
|
||||
<coverage processUncoveredFiles="false">
|
||||
<include>
|
||||
<directory suffix=".php">../</directory>
|
||||
</include>
|
||||
<exclude>
|
||||
<directory suffix=".php">../vendor/</directory>
|
||||
<directory suffix=".php">../test/</directory>
|
||||
</exclude>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Core Functionality">
|
||||
<testsuite name="Layout Suite">
|
||||
<directory>./</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<logging>
|
||||
<log type="json" target="../build/phpunit/logfile.json"/>
|
||||
<log type="junit" target="../build/phpunit/logfile.xml"/>
|
||||
<log type="testdox-html" target="../build/phpunit/testdox.html"/>
|
||||
<log type="testdox-text" target="../build/phpunit/testdox.txt"/>
|
||||
</logging>
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="false">
|
||||
<directory suffix=".php">../</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">../vendor/</directory>
|
||||
<directory suffix=".php">../test/</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
|
@ -0,0 +1 @@
|
|||
Latte Template Check
|
|
@ -1 +0,0 @@
|
|||
Smarty Template Check
|
Loading…
Reference in New Issue