Example #1
0
 /**
  * Let's do this ...
  * @param $template string The path or url to a tasty cheesecake template
  * @param $params array Optional parameters that are merged with existing
  *                      params from a cheesecake.json file :O
  * @param $options array Options
  */
 public function __construct($template, array $params = [], array $options = [])
 {
     $this->template = $template;
     $this->templateType = $this->detectTemplateType($template);
     $this->params = $params;
     $this->output = $this->getoa($options, self::OPT_OUTPUT, '.');
     $this->noInteraction = $this->getoa($options, self::OPT_NO_INTERACTION, false);
     $options = ['pragmas' => [\Mustache_Engine::PRAGMA_FILTERS]];
     $this->mustache = new \Mustache_Engine($options);
     $this->mustache->addHelper('string', ['toLowerCase' => function ($value) {
         return Stringy::toLowerCase($value);
     }, 'toUpperCase' => function ($value) {
         return Stringy::toUpperCase($value);
     }, 'upperCaseFirst' => function ($value) {
         return Stringy::upperCaseFirst($value);
     }, 'lowerCaseFirst' => function ($value) {
         return Stringy::lowerCaseFirst($value);
     }, 'humanize' => function ($value) {
         return Stringy::humanize($value);
     }, 'camelize' => function ($value) {
         return Stringy::camelize($value);
     }, 'upperCamelize' => function ($value) {
         return Stringy::upperCamelize($value);
     }, 'slugify' => function ($value) {
         return Stringy::slugify($value);
     }]);
     $this->fs = new Filesystem();
 }
Example #2
0
 /**
  * @dataProvider toUpperCaseProvider()
  */
 public function testToUpperCase($expected, $str, $encoding = null)
 {
     $result = S::toUpperCase($str, $encoding);
     $this->assertInternalType('string', $result);
     $this->assertEquals($expected, $result);
 }
Example #3
0
 public function toUpperCase($string)
 {
     return Stringy::toUpperCase($string);
 }
Example #4
0
 protected function makeItemImage($def, &$func, &$before, &$after)
 {
     $col = $def['column'];
     $size_arr = $def['options'];
     $arr = $size_arr ?: array(false);
     $setter = Item::MakeSetterName($col);
     $process = false;
     foreach ($arr as $size) {
         $this->makeItemFileGetters($func, $col, true, $size);
         $s = var_export($size, true);
         $process .= "    \$filename = \$this->makeFileName('{$col}', \$name, {$s});\n";
         $process .= "    \$this->processImage('{$col}', \$tmp, \$filename, \$name, {$s});\n\n";
     }
     $func[] = "  /** Добавить изображение \$file. \$name - оригинальное имя файла */\n" . "  public function {$setter}(\$file, \$name = null)\n" . "  {\n" . "    \$name = \$name ?: pathinfo(\$file, PATHINFO_BASENAME);\n" . "    \$tmp  = \$this->getFilesPath() . \$this->makeFileName('{$col}', \$name, 'temp');\n\n" . "    \$this->copyFile(\$file, \$tmp);\n\n" . $process . "    unlink(\$tmp);\n\n" . "    return \$this;\n" . "  }";
     $after[] = "  /**\n" . "  * Метод для процессинга изображений {$col}.\n" . "  * Должен вернуть объект Image или файл будет сохранен без изменений\n  */\n" . "  protected function prepareImageFor" . StaticStringy::upperCamelize($col) . "(\$file, \$size)\n" . "  {\n" . "    \n" . "  }";
     if (!empty($size_arr)) {
         $const = $names = false;
         foreach ($size_arr as $size) {
             $c = StaticStringy::toUpperCase(StaticStringy::underscored($col . ' size ' . $size));
             $const[] = "  const {$c} = '{$size}';";
             $names[] = "    self::{$c} => '{$size}',";
         }
         $before[] = join("\n", $const);
         $before[] = "  protected static \${$col}_size_arr = array(\n" . join("\n", $names) . "\n  );";
         $name_for = 'GetNameFor' . StaticStringy::upperCamelize($col) . 'Size';
         $getter_arr = 'Get' . StaticStringy::upperCamelize($col) . 'SizeArr';
         $after[] = "  public static function {$getter_arr}()\n" . "  {\n" . "    return static::\${$col}_size_arr;\n" . "  }";
         $after[] = "  public static function {$name_for}(\$size)\n" . "  {\n" . "    \$a = static::{$getter_arr}();\n\n" . "    return isset(\$a[\$size]) ? \$a[\$size] : false;\n" . "  }";
     }
 }