flyntwp /
flynt
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Flynt\Utils; |
||||||
| 4 | |||||||
| 5 | use Flynt\ComponentManager; |
||||||
| 6 | use Twig_Environment; |
||||||
| 7 | use Twig_Extension; |
||||||
| 8 | use Twig\TwigFunction; |
||||||
| 9 | |||||||
| 10 | class TwigExtensionFlynt extends Twig_Extension |
||||||
|
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||||||
| 11 | { |
||||||
| 12 | public function getName() |
||||||
| 13 | { |
||||||
| 14 | return 'twig_extension_flynt'; |
||||||
| 15 | } |
||||||
| 16 | |||||||
| 17 | public function getFunctions() |
||||||
| 18 | { |
||||||
| 19 | return [ |
||||||
| 20 | new TwigFunction('renderComponent', [$this, 'renderComponent'], array('needs_environment' => true, 'needs_context' => true, 'is_safe' => array('all'))), |
||||||
| 21 | ]; |
||||||
| 22 | } |
||||||
| 23 | |||||||
| 24 | public function renderComponent(Twig_Environment $env, $context, $componentName, $data = [], $withContext = true, $ignoreMissing = false, $sandboxed = false) |
||||||
| 25 | { |
||||||
| 26 | $data = $data === false ? [] : $data; |
||||||
| 27 | |||||||
| 28 | if (is_array($componentName)) { |
||||||
| 29 | $data = array_merge($componentName, $data); |
||||||
| 30 | $componentName = ucfirst($data['acf_fc_layout']); |
||||||
| 31 | } |
||||||
| 32 | $data = $this->getComponentData($data, $componentName); |
||||||
| 33 | |||||||
| 34 | $componentManager = ComponentManager::getInstance(); |
||||||
| 35 | $templateFilename = apply_filters('Flynt/TimberLoader/templateFilename', 'index.twig'); |
||||||
| 36 | $templateFilename = apply_filters("Flynt/TimberLoader/templateFilename?name=${componentName}", $templateFilename); |
||||||
| 37 | $filePath = $componentManager->getComponentFilePath($componentName, $templateFilename); |
||||||
| 38 | $relativeFilePath = ltrim(str_replace(get_template_directory(), '', $filePath), '/'); |
||||||
| 39 | |||||||
| 40 | if (!is_file($filePath)) { |
||||||
| 41 | trigger_error("Template not found: {$filePath}", E_USER_WARNING); |
||||||
| 42 | return ''; |
||||||
| 43 | } |
||||||
| 44 | |||||||
| 45 | $loader = $env->getLoader(); |
||||||
| 46 | |||||||
| 47 | $loaderPaths = $loader->getPaths(); |
||||||
|
0 ignored issues
–
show
The method
getPaths() does not exist on Twig\Loader\LoaderInterface. It seems like you code against a sub-type of Twig\Loader\LoaderInterface such as Twig\Loader\FilesystemLoader or Twig\Loader\FilesystemLoader or Twig\Loader\FilesystemLoader.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 48 | |||||||
| 49 | $loader->addPath(dirname($filePath)); |
||||||
|
0 ignored issues
–
show
The method
addPath() does not exist on Twig\Loader\LoaderInterface. It seems like you code against a sub-type of Twig\Loader\LoaderInterface such as Twig\Loader\FilesystemLoader or Twig\Loader\FilesystemLoader or Twig\Loader\FilesystemLoader.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 50 | |||||||
| 51 | $output = twig_include($env, $context, $relativeFilePath, $data, $withContext, $ignoreMissing, $sandboxed); |
||||||
| 52 | |||||||
| 53 | $loader->setPaths($loaderPaths); |
||||||
|
0 ignored issues
–
show
The method
setPaths() does not exist on Twig\Loader\LoaderInterface. It seems like you code against a sub-type of Twig\Loader\LoaderInterface such as Twig\Loader\FilesystemLoader or Twig\Loader\FilesystemLoader or Twig\Loader\FilesystemLoader.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 54 | |||||||
| 55 | $output = apply_filters( |
||||||
| 56 | 'Flynt/renderComponent', |
||||||
| 57 | $output, |
||||||
| 58 | $componentName, |
||||||
| 59 | $data |
||||||
| 60 | ); |
||||||
| 61 | |||||||
| 62 | return $output; |
||||||
| 63 | } |
||||||
| 64 | |||||||
| 65 | protected function getComponentData($data, $componentName) |
||||||
| 66 | { |
||||||
| 67 | $data = apply_filters( |
||||||
| 68 | 'Flynt/addComponentData', |
||||||
| 69 | $data, |
||||||
| 70 | $componentName |
||||||
| 71 | ); |
||||||
| 72 | |||||||
| 73 | return $data; |
||||||
| 74 | } |
||||||
| 75 | } |
||||||
| 76 |