-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04aa59b
commit 441e5d8
Showing
9 changed files
with
139 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# html_template | ||
A simple template class | ||
A simple template engine for PHP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,91 @@ | ||
<?php | ||
|
||
/** | ||
* © 2017 - 2019 | ||
* | ||
* Lionel Vinceslas <[email protected]> | ||
* | ||
* 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 <[email protected]> | ||
* @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 <[email protected]> | ||
* @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; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
* @author Jordi Boggiano <[email protected]> | ||
* @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; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters