Esempio n. 1
0
 public function __construct(SpritePackageInterface $package)
 {
     $this->package = $package;
     $className = $this->package->getConstantsClass();
     $path = $this->package->getConstantsClassPath();
     if (!empty($path)) {
         // Manually create class, as it might not be loaded into opcache
         $parts = explode('\\', $className);
         $this->name = array_pop($parts);
         $this->ns = implode('\\', $parts);
         $this->path = sprintf('%s/%s.php', $path, $this->name);
     } else {
         // Use reflection class to get info
         $info = new ReflectionClass($className);
         $this->ns = $info->getNamespaceName();
         $this->name = $info->getShortName();
         $this->path = $info->getFileName();
     }
 }
Esempio n. 2
0
 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}"));
     }
 }