From 441e5d84742eb807b2cacd6eacf87af92cc5fac7 Mon Sep 17 00:00:00 2001 From: Lionel Vinceslas Date: Mon, 30 Dec 2019 14:56:50 +0100 Subject: [PATCH] :heavy_plus_sign: update: add .gitignore file --- .gitignore | 1 + README.md | 2 +- composer.json | 4 +- composer.lock | 4 +- src/lvincesl/html/Html_template.php | 70 ++++++++++++++++++++----- vendor/autoload.php | 2 +- vendor/composer/ClassLoader.php | 74 +++++++++++++++++++-------- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_real.php | 38 +++++++------- 9 files changed, 139 insertions(+), 57 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42cd73d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ \ No newline at end of file diff --git a/README.md b/README.md index feafcc9..87563f8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # html_template -A simple template class +A simple template engine for PHP diff --git a/composer.json b/composer.json index 4441a8d..2cb37c1 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { "name": "lvincesl/html_template", - "description": "A simple template manager", + "description": "A simple template engine for PHP", "license": "CECILL-C", "authors": [ { "name": "Lionel Vinceslas", - "email": "lionel.vinceslas@eurower.net" + "email": "lionel.vinceslas@gmail.com" } ], "minimum-stability": "dev", diff --git a/composer.lock b/composer.lock index 3093329..32df00e 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "hash": "547de3f4ecd88ca0ba70e259584e33d8", + "content-hash": "54d89374becdc4e01986f13a7ab0acb8", "packages": [], "packages-dev": [], "aliases": [], diff --git a/src/lvincesl/html/Html_template.php b/src/lvincesl/html/Html_template.php index 61a730d..de949f4 100755 --- a/src/lvincesl/html/Html_template.php +++ b/src/lvincesl/html/Html_template.php @@ -1,45 +1,91 @@ + * + * This software is a simple template engine to write clear php code + * without imbricated html. + * + * This software is governed by the CeCILL-C license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/ or redistribute the software under the terms of the CeCILL-C + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL-C license and that you accept its terms. + */ namespace lvincesl\html; /** - * Classe de gestion simple de Templates HTML + * Simple HTML template management class * * @category Template * @package Lvincesl - * @author Lionel Vinceslas - * @license CECILL http://www.cecill.info/licences/Licence_CeCILL-C_V1-fr.txt - * @link lionel-vinceslas.eurower.net - * - * @date 02/09/2007 - * @return string + * @author Lionel Vinceslas + * @license CeCILL-C https://cecill.info/licences/Licence_CeCILL-C_V1-en.txt + * @link https://packagist.org/packages/lvincesl/html_template */ -class Html_Template +class Html_template { var $templatePath; var $templateContent; + /** + * @param string $path the HTML template url + */ public function __construct($path) { $this->templatePath = $path; $this->templateContent = file_get_contents($path); } + /** + * Get the current HTML template code + * @return string + */ public function toString() { return $this->templateContent; } - public function set($name, $value) + /** + * Set the value of the given tag name + * @param string $tag + * @param string $value + * @return void + */ + public function set($tag, $value) { - $this->templateContent = str_replace("{%".$name."%}", $value, $this->templateContent); + $this->templateContent = str_replace("{%".$tag."%}", $value, $this->templateContent); } + /** + * Show the current HTML template + * @return void + */ public function show() { echo $this->templateContent; } } - -?> diff --git a/vendor/autoload.php b/vendor/autoload.php index fb9c0a0..464306d 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -2,6 +2,6 @@ // autoload.php @generated by Composer -require_once __DIR__ . '/composer' . '/autoload_real.php'; +require_once __DIR__ . '/composer/autoload_real.php'; return ComposerAutoloaderInit72cd98100f657bdd681c0c43791222f4::getLoader(); diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index 4e05d3b..fce8549 100644 --- a/vendor/composer/ClassLoader.php +++ b/vendor/composer/ClassLoader.php @@ -13,9 +13,7 @@ namespace Composer\Autoload; /** - * ClassLoader implements a PSR-0 class loader - * - * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. * * $loader = new \Composer\Autoload\ClassLoader(); * @@ -39,6 +37,8 @@ * * @author Fabien Potencier * @author Jordi Boggiano + * @see http://www.php-fig.org/psr/psr-0/ + * @see http://www.php-fig.org/psr/psr-4/ */ class ClassLoader { @@ -53,8 +53,9 @@ class ClassLoader private $useIncludePath = false; private $classMap = array(); - private $classMapAuthoritative = false; + private $missingClasses = array(); + private $apcuPrefix; public function getPrefixes() { @@ -147,7 +148,7 @@ public function add($prefix, $paths, $prepend = false) * appending or prepending to the ones previously set for this namespace. * * @param string $prefix The prefix/namespace, with trailing '\\' - * @param array|string $paths The PSR-0 base directories + * @param array|string $paths The PSR-4 base directories * @param bool $prepend Whether to prepend the directories * * @throws \InvalidArgumentException @@ -271,6 +272,26 @@ public function isClassMapAuthoritative() return $this->classMapAuthoritative; } + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + /** * Registers this instance as an autoloader. * @@ -313,29 +334,34 @@ public function loadClass($class) */ public function findFile($class) { - // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 - if ('\\' == $class[0]) { - $class = substr($class, 1); - } - // class map lookup if (isset($this->classMap[$class])) { return $this->classMap[$class]; } - if ($this->classMapAuthoritative) { + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { return false; } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } $file = $this->findFileWithExtension($class, '.php'); // Search for Hack files if we are running on HHVM - if ($file === null && defined('HHVM_VERSION')) { + if (false === $file && defined('HHVM_VERSION')) { $file = $this->findFileWithExtension($class, '.hh'); } - if ($file === null) { + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { // Remember that this class does not exist. - return $this->classMap[$class] = false; + $this->missingClasses[$class] = true; } return $file; @@ -348,10 +374,14 @@ private function findFileWithExtension($class, $ext) $first = $class[0]; if (isset($this->prefixLengthsPsr4[$first])) { - foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { - if (0 === strpos($class, $prefix)) { - foreach ($this->prefixDirsPsr4[$prefix] as $dir) { - if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { return $file; } } @@ -361,7 +391,7 @@ private function findFileWithExtension($class, $ext) // PSR-4 fallback dirs foreach ($this->fallbackDirsPsr4 as $dir) { - if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { return $file; } } @@ -380,7 +410,7 @@ private function findFileWithExtension($class, $ext) foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { if (0 === strpos($class, $prefix)) { foreach ($dirs as $dir) { - if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { return $file; } } @@ -390,7 +420,7 @@ private function findFileWithExtension($class, $ext) // PSR-0 fallback dirs foreach ($this->fallbackDirsPsr0 as $dir) { - if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { return $file; } } @@ -399,6 +429,8 @@ private function findFileWithExtension($class, $ext) if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { return $file; } + + return false; } } diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 7a91153..b9c3dfe 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -6,4 +6,5 @@ $baseDir = dirname($vendorDir); return array( + 'lvincesl\\html\\Html_template' => $baseDir . '/src/lvincesl/html/Html_template.php', ); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index beeb89e..a01e989 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -23,19 +23,26 @@ public static function getLoader() self::$loader = $loader = new \Composer\Autoload\ClassLoader(); spl_autoload_unregister(array('ComposerAutoloaderInit72cd98100f657bdd681c0c43791222f4', 'loadClassLoader')); - $map = require __DIR__ . '/autoload_namespaces.php'; - foreach ($map as $namespace => $path) { - $loader->set($namespace, $path); - } - - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } - - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); + $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit72cd98100f657bdd681c0c43791222f4::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } } $loader->register(true); @@ -43,8 +50,3 @@ public static function getLoader() return $loader; } } - -function composerRequire72cd98100f657bdd681c0c43791222f4($file) -{ - require $file; -}