Maslosoft Staple API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
<?php
/**
* This software package is licensed under AGPL or Commercial license.
*
* @package maslosoft/staple
* @licence AGPL or Commercial
* @copyright Copyright (c) Piotr Masełkowski <pmaselkowski@gmail.com>
* @copyright Copyright (c) Maslosoft
* @link http://maslosoft.com/staple/
*/
namespace Maslosoft\Staple\Processors\Pre;
use Maslosoft\Staple\Interfaces\PreProcessorInterface;
use Maslosoft\Staple\Interfaces\RendererAwareInterface;
/**
* ##View Json Extractor##
*
* This extracts data from json file named same as view file, but with json extension.
* When resolving name, extension is not added to this json file.
*
* For example, when there is file `index.php` this will try to load data from
* file `index.json`.
* Some example files structure:
* ```
* products/
* index.php
* index.json
* spoon.md.php
* spoon.json
* fork.md
* fork.json
* ```
*
* From example above data from json files will be attached by following associacions:
* ```
* index.json --> index.php
* spoon.json --> sopon.md.php
* fork.json --> fork.md
* ```
*
* Extracted data is available both in view and in layout.
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class ViewJsonExtractor implements PreProcessorInterface
{
public function decorate(RendererAwareInterface $owner, &$content, $data)
{
}
public function getData(RendererAwareInterface $owner, $filename, $view)
{
$data = [];
$path = sprintf('%s/%s/%s.json', $owner->getRootPath(), $owner->getContentPath(), $view);
if (file_exists($path))
{
$data = (array) json_decode(file_get_contents($path));
}
return $data;
}
}
API documentation generated by ApiGen