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
Showing
12 changed files
with
370 additions
and
15 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
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,39 @@ | ||
<?php | ||
|
||
/** | ||
* 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. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
* | ||
* Copyright (c) 2014-2016 Yuuki Takezawa | ||
* | ||
*/ | ||
namespace Ytake\LaravelSmarty\Compilers; | ||
|
||
use Illuminate\Contracts\View\Factory; | ||
|
||
/** | ||
* Class Compilable | ||
* | ||
* @author yuuki.takezawa <yuuki.takezawa@comnect.jp.net> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
*/ | ||
interface Compilable | ||
{ | ||
/** | ||
* @param Factory $factory | ||
*/ | ||
public function setViewFactory(Factory $factory); | ||
|
||
/** | ||
* @param array $data | ||
*/ | ||
public function setLaravelViewData(array $data); | ||
} |
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,97 @@ | ||
<?php | ||
|
||
/** | ||
* 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. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
* | ||
* Copyright (c) 2014-2016 Yuuki Takezawa | ||
* | ||
*/ | ||
namespace Ytake\LaravelSmarty\Compilers; | ||
|
||
use Illuminate\View\View; | ||
use Illuminate\Contracts\View\Factory; | ||
|
||
/** | ||
* Class CompileInclude | ||
* | ||
* @author yuuki.takezawa <yuuki.takezawa@comnect.jp.net> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
*/ | ||
class CompileInclude extends \Smarty_Internal_Compile_Include implements Compilable | ||
{ | ||
/** @var Factory|\Ytake\LaravelSmarty\SmartyFactory */ | ||
protected $viewFactory; | ||
|
||
/** @var array */ | ||
protected $laravelViewData; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function compile($args, \Smarty_Internal_SmartyTemplateCompiler $compiler, $parameter) | ||
{ | ||
foreach ($args as $arg) { | ||
if (isset($arg['file'])) { | ||
$viewName = $this->normalizeTemplateName($arg['file']); | ||
$this->dispatch($viewName); | ||
} | ||
} | ||
|
||
return parent::compile($args, $compiler, $parameter); | ||
} | ||
|
||
/** | ||
* @param Factory $factory | ||
*/ | ||
public function setViewFactory(Factory $factory) | ||
{ | ||
$this->viewFactory = $factory; | ||
} | ||
|
||
/** | ||
* @param array $data | ||
*/ | ||
public function setLaravelViewData(array $data) | ||
{ | ||
$this->laravelViewData = $data; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return string | ||
*/ | ||
protected function normalizeTemplateName($name) | ||
{ | ||
$fileInfo = new \SplFileInfo($name); | ||
$path = ($fileInfo->getPath() === '') ? null : $fileInfo->getPath() . '/'; | ||
$viewPathInfo = $path . $fileInfo->getBasename('.' . $fileInfo->getExtension()); | ||
|
||
return trim(str_replace('/', '.', $viewPathInfo), '"'); | ||
} | ||
|
||
/** | ||
* @param $name | ||
*/ | ||
protected function dispatch($name) | ||
{ | ||
$view = new View( | ||
$this->viewFactory, | ||
$this->viewFactory->getEngineResolver()->resolve('smarty'), | ||
$name, | ||
null, | ||
[] | ||
); | ||
$this->viewFactory->callCreator($view); | ||
$this->viewFactory->callComposer($view); | ||
} | ||
} |
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,84 @@ | ||
<?php | ||
|
||
/** | ||
* 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. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
* | ||
* Copyright (c) 2014-2016 Yuuki Takezawa | ||
* | ||
*/ | ||
namespace Ytake\LaravelSmarty\Compilers; | ||
|
||
/** | ||
* Class TemplateCompiler | ||
* | ||
* @author yuuki.takezawa <yuuki.takezawa@comnect.jp.net> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
*/ | ||
class TemplateCompiler extends \Smarty_Internal_SmartyTemplateCompiler | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) | ||
{ | ||
$this->smarty->tpl_vars['userCount'] = new \Smarty_Variable(9999); | ||
if (!isset(self::$_tag_objects[$tag])) { | ||
// lazy load internal compiler plugin | ||
$_tag = explode('_', $tag); | ||
$_tag = array_map('ucfirst', $_tag); | ||
$class_name = $this->detectSmartyInternalCompiler('Smarty_Internal_Compile_' . implode('_', $_tag)); | ||
if (class_exists($class_name) && | ||
(!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) | ||
) { | ||
self::$_tag_objects[$tag] = $this->appendViewFactoryInstance(new $class_name);; | ||
} else { | ||
self::$_tag_objects[$tag] = false; | ||
|
||
return false; | ||
} | ||
} | ||
|
||
// compile this tag | ||
return self::$_tag_objects[$tag] === false ? false : | ||
self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); | ||
} | ||
|
||
/** | ||
* @param string $className | ||
* | ||
* @return string | ||
*/ | ||
protected function detectSmartyInternalCompiler($className) | ||
{ | ||
if ($className === \Smarty_Internal_Compile_Include::class) { | ||
$className = CompileInclude::class; | ||
} | ||
|
||
return $className; | ||
} | ||
|
||
/** | ||
* @param \Smarty_Internal_CompileBase|Compilable $instance | ||
* | ||
* @return \Smarty_Internal_CompileBase|Compilable | ||
*/ | ||
protected function appendViewFactoryInstance($instance) | ||
{ | ||
if ($instance instanceof Compilable) { | ||
if (!is_null($this->smarty->getViewFactory())) { | ||
$instance->setViewFactory($this->smarty->getViewFactory()); | ||
} | ||
} | ||
|
||
return $instance; | ||
} | ||
} |
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
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
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,64 @@ | ||
<?php | ||
|
||
/** | ||
* 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. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
* | ||
* Copyright (c) 2014-2016 Yuuki Takezawa | ||
* | ||
*/ | ||
namespace Ytake\LaravelSmarty\Engines; | ||
|
||
use Smarty; | ||
use Smarty_Internal_Data; | ||
use Smarty_Template_Source; | ||
use Ytake\LaravelSmarty\Compilers\TemplateCompiler; | ||
|
||
/** | ||
* Class SmartyTemplate | ||
* | ||
* @author yuuki.takezawa <yuuki.takezawa@comnect.jp.net> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
*/ | ||
class SmartyTemplate extends \Smarty_Internal_Template | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct( | ||
$template_resource, | ||
Smarty $smarty, | ||
Smarty_Internal_Data $_parent = null, | ||
$_cache_id = null, | ||
$_compile_id = null, | ||
$_caching = null, | ||
$_cache_lifetime = null | ||
) { | ||
$this->smarty = $smarty; | ||
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id; | ||
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id; | ||
$this->caching = $_caching === null ? $this->smarty->caching : $_caching; | ||
if ($this->caching === true) { | ||
$this->caching = Smarty::CACHING_LIFETIME_CURRENT; | ||
} | ||
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime; | ||
$this->parent = $_parent; | ||
// Template resource | ||
$this->template_resource = $template_resource; | ||
$this->source = Smarty_Template_Source::load($this); | ||
$this->source->compiler_class = TemplateCompiler::class; | ||
|
||
Smarty_Internal_Data::__construct(); | ||
if ($smarty->security_policy && method_exists($smarty->security_policy, 'registerCallBacks')) { | ||
$smarty->security_policy->registerCallBacks($this); | ||
} | ||
} | ||
} |
Oops, something went wrong.