-
Notifications
You must be signed in to change notification settings - Fork 41
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
7 changed files
with
132 additions
and
2 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,73 @@ | ||
<?php | ||
|
||
namespace ShyimProfiler\Components\Smarty; | ||
|
||
use Smarty; | ||
use Smarty_Internal_Template; | ||
use Smarty_Template_Source; | ||
|
||
/** | ||
* Class SnippetResource | ||
* @package ShyimProfiler\Components\Smarty | ||
* @author Soner Sayakci <[email protected]> | ||
*/ | ||
class SnippetResource extends \Enlight_Components_Snippet_Resource | ||
{ | ||
/** | ||
* @var array | ||
* @author Soner Sayakci <[email protected]> | ||
*/ | ||
private $snippets = []; | ||
|
||
/** | ||
* populate Source Object with meta data from Resource | ||
* | ||
* @param Smarty_Template_Source $source source object | ||
* @param Smarty_Internal_Template $_template template object | ||
*/ | ||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) | ||
{ | ||
if (!isset($source->smarty->registered_plugins[Smarty::PLUGIN_BLOCK]['snippet'])) { | ||
$source->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'snippet', array(__CLASS__, 'compileSnippetBlock')); | ||
} | ||
if (!isset($source->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER]['snippet'])) { | ||
$source->smarty->registerPlugin(Smarty::PLUGIN_MODIFIER, 'snippet', array($this, 'compileSnippetModifier')); | ||
} | ||
$default_resource = $source->smarty->default_resource_type; | ||
$source->smarty->default_resource_type = 'file'; | ||
parent::populate($source, $_template); | ||
$source->smarty->default_resource_type = $default_resource; | ||
} | ||
|
||
/** | ||
* @param $namespace | ||
* @param $name | ||
* @param $default | ||
* @param bool $force | ||
* @return mixed | ||
* @author Soner Sayakci <[email protected]> | ||
*/ | ||
protected function getSnippet($namespace, $name, $default, $force = false) | ||
{ | ||
$result = parent::getSnippet($namespace, $name, $default, $force); | ||
|
||
$this->snippets[$namespace . '|' . $name] = [ | ||
'namespace' => $namespace, | ||
'name' => $name, | ||
'default' => $default, | ||
'force' => $force, | ||
'content' => $result | ||
]; | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @return array | ||
* @author Soner Sayakci <[email protected]> | ||
*/ | ||
public function getUsedSnippets() | ||
{ | ||
return $this->snippets; | ||
} | ||
} |
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
Oops, something went wrong.