| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the WindPress package. |
| 5 |
* |
| 6 |
* (c) Joshua Gugun Siagian <suabahasa@gmail.com> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
declare (strict_types=1); |
| 12 |
namespace WindPress\WindPress\Integration\Timber; |
| 13 |
|
| 14 |
use WindPressPackages\Symfony\Component\Finder\Finder; |
| 15 |
use Timber\LocationManager; |
| 16 |
use Timber\Timber; |
| 17 |
/** |
| 18 |
* @author Joshua Gugun Siagian <suabahasa@gmail.com> |
| 19 |
*/ |
| 20 |
class Compile |
| 21 |
{ |
| 22 |
public function __invoke() : array |
| 23 |
{ |
| 24 |
if (!\class_exists(Timber::class)) { |
| 25 |
return []; |
| 26 |
} |
| 27 |
return $this->get_contents(); |
| 28 |
} |
| 29 |
public function get_contents() : array |
| 30 |
{ |
| 31 |
$contents = []; |
| 32 |
$paths = LocationManager::get_locations(); |
| 33 |
$finder = new Finder(); |
| 34 |
$finder->in($paths); |
| 35 |
$finder->files()->name('*.twig'); |
| 36 |
\do_action('f!windpress/integration/timber/compile:get_contents.finder', $finder); |
| 37 |
foreach ($finder as $file) { |
| 38 |
$template_file = $file->getPathname(); |
| 39 |
if (!\is_readable($template_file)) { |
| 40 |
continue; |
| 41 |
} |
| 42 |
$contents[] = [ |
| 43 |
'name' => $file->getRelativePathname(), |
| 44 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local file |
| 45 |
'content' => \file_get_contents($template_file), |
| 46 |
]; |
| 47 |
} |
| 48 |
return $contents; |
| 49 |
} |
| 50 |
} |
| 51 |
|