o2system /
parser
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * This file is part of the O2System Framework package. |
||||
| 4 | * |
||||
| 5 | * For the full copyright and license information, please view the LICENSE |
||||
| 6 | * file that was distributed with this source code. |
||||
| 7 | * |
||||
| 8 | * @author Steeve Andrian Salim |
||||
| 9 | * @copyright Copyright (c) Steeve Andrian Salim |
||||
| 10 | */ |
||||
| 11 | |||||
| 12 | // ------------------------------------------------------------------------ |
||||
| 13 | |||||
| 14 | namespace O2System\Parser\Template\Abstracts; |
||||
| 15 | |||||
| 16 | // ------------------------------------------------------------------------ |
||||
| 17 | |||||
| 18 | use O2System\Spl\Traits\Collectors\FileExtensionCollectorTrait; |
||||
| 19 | use O2System\Spl\Traits\Collectors\FilePathCollectorTrait; |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * Class AbstractEngine |
||||
| 23 | * |
||||
| 24 | * @package O2System\Parser\Template\Abstracts |
||||
| 25 | */ |
||||
| 26 | abstract class AbstractEngine |
||||
| 27 | {
|
||||
| 28 | use FileExtensionCollectorTrait; |
||||
| 29 | use FilePathCollectorTrait; |
||||
| 30 | |||||
| 31 | // ------------------------------------------------------------------------ |
||||
| 32 | |||||
| 33 | /** |
||||
| 34 | * AbstractEngine::parsePartials |
||||
| 35 | * |
||||
| 36 | * @param string $filename |
||||
| 37 | * @param array $vars |
||||
| 38 | * @param string $optionalFilename |
||||
| 39 | * |
||||
| 40 | * @return string|null |
||||
| 41 | */ |
||||
| 42 | public function parsePartials($filename, $vars = null, $optionalFilename = null) |
||||
| 43 | {
|
||||
| 44 | if (empty($vars)) {
|
||||
| 45 | if (isset($optionalFilename)) {
|
||||
| 46 | return $this->parseFile($optionalFilename); |
||||
| 47 | } |
||||
| 48 | } else {
|
||||
| 49 | return $this->parseFile($filename, $vars); |
||||
| 50 | } |
||||
| 51 | |||||
| 52 | return null; |
||||
| 53 | } |
||||
| 54 | |||||
| 55 | // ------------------------------------------------------------------------ |
||||
| 56 | |||||
| 57 | /** |
||||
| 58 | * AbstractEngine::parseFile |
||||
| 59 | * |
||||
| 60 | * @param string $filePath |
||||
| 61 | * @param array $vars |
||||
| 62 | * |
||||
| 63 | * @return string |
||||
| 64 | */ |
||||
| 65 | public function parseFile($filePath, array $vars = []) |
||||
| 66 | {
|
||||
| 67 | if (class_exists('O2System\Framework', false)) {
|
||||
| 68 | return view()->load($filePath, $vars, true); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 69 | } else {
|
||||
| 70 | $fileExtension = '.' . pathinfo($filePath, PATHINFO_EXTENSION); |
||||
| 71 | |||||
| 72 | if (in_array($fileExtension, $this->fileExtensions) AND is_file($filePath)) {
|
||||
| 73 | return $this->parseString(file_get_contents($filePath), $vars); |
||||
|
0 ignored issues
–
show
The method
parseString() does not exist on O2System\Parser\Template\Abstracts\AbstractEngine. Since it exists in all sub-types, consider adding an abstract or default implementation to O2System\Parser\Template\Abstracts\AbstractEngine.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 74 | } |
||||
| 75 | |||||
| 76 | // Try to find from filePaths |
||||
| 77 | if (count($this->filePaths)) {
|
||||
| 78 | foreach ($this->filePaths as $fileDirectory) {
|
||||
| 79 | $checkFilePath = $fileDirectory . $filePath; |
||||
| 80 | |||||
| 81 | if (in_array($fileExtension, $this->fileExtensions) AND is_file($checkFilePath)) {
|
||||
| 82 | return $this->parseString(file_get_contents($checkFilePath), $vars); |
||||
| 83 | break; |
||||
|
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other Loading history...
|
|||||
| 84 | } |
||||
| 85 | } |
||||
| 86 | } |
||||
| 87 | } |
||||
| 88 | |||||
| 89 | return null; |
||||
| 90 | } |
||||
| 91 | } |