Example #1
0
 /**
  * Add constant from sprite, but only if in current package.
  * @param SpriteImage $sprite
  */
 public function add(SpriteImage $sprite)
 {
     $dest = $this->package->getConstantsClass();
     foreach ($sprite->packages as $package) {
         $src = $package->getConstantsClass();
         if ($src === $dest) {
             $this->addSprite($sprite);
         }
     }
 }
 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}"));
     }
 }