Exemple #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);
         }
     }
 }
Exemple #2
0
 public static function nameConstant(SpritePackageInterface $package, SpriteImage $sprite)
 {
     $converter = $package->getConstantsConverter();
     if (!empty($converter)) {
         if (!is_callable($converter, true)) {
             throw new RuntimeException('Variable of type `%s` is not callable', get_type($converter));
         }
         $params = [$package, $sprite];
         $name = call_user_func_array($converter, $params);
     } else {
         $name = $sprite->name;
     }
     // Last resort replacements
     $name = preg_replace('~^[0-9]+~', '', $name);
     return str_replace('-', '_', $name);
 }
 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}"));
     }
 }