Maslosoft Sprite 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
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace Maslosoft\Sprite\Helpers;
use Maslosoft\MiniView\MiniView;
use Maslosoft\Sprite\Interfaces\SpritePackageInterface;
use RuntimeException;
/**
* ConstantsFileCreator
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class ConstantsFileCreator
{
public static function generate(SpritePackageInterface $package)
{
$path = $package->getConstantsClassPath();
if (empty($path))
{
return;
}
$className = $package->getConstantsClass();
$parts = explode('\\', $className);
$name = array_pop($parts);
$ns = implode('\\', $parts);
$fileName = sprintf('%s/%s.php', $path, $name);
if (!file_exists($fileName))
{
$view = new MiniView(new self);
$params = [
'tag' => '<?php',
'ns' => $ns,
'name' => $name
];
$def = $view->render('constantsClass.latte', $params, true);
$result = file_put_contents($fileName, $def);
assert($result, new RuntimeException("Could not write into $fileName"));
}
}
}
API documentation generated by ApiGen