コード例 #1
0
ファイル: Generator.php プロジェクト: madflow/cheesecake
 /**
  * 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();
 }
コード例 #2
0
ファイル: Manager.php プロジェクト: sqrt-pro/framework
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $arr = array();
     $names = array();
     $collections = false;
     if (is_dir(DIR_REPOSITORY)) {
         $it = new \FilesystemIterator(DIR_REPOSITORY, \FilesystemIterator::SKIP_DOTS);
         while ($it->valid()) {
             if (!$it->isDot() && !$it->isDir()) {
                 $nm = $it->getBasename('.php');
                 $cl = '\\Repository\\' . $nm;
                 if (class_exists($cl)) {
                     $names[] = $nm;
                     $arr[] = "  /** @return {$cl} */\n" . "  public function " . StaticStringy::camelize($nm) . "()\n" . "  {\n" . "    return \$this->getRepository('{$nm}');\n" . "  }";
                     $collections .= "    \$this->setRepositoryClass('{$nm}', '{$cl}');\n";
                 }
             }
             $it->next();
         }
     }
     $code = "<?php\n\nnamespace Base;\n\n" . "/** Этот файл сгенерирован автоматически командой db:manager */\n" . "class Manager extends \\SQRT\\DB\\Manager\n{\n" . "  function __construct()\n" . "  {\n" . "    \$this->addConnection(DB_HOST, DB_USER, DB_PASS, DB_NAME);\n" . "    \$this->setPrefix(PREFIX);\n" . ($collections ? "\n" . $collections : '') . "  }\n\n" . join("\n\n", $arr) . "\n" . "}";
     $file = DIR_APP . '/Base/Manager.php';
     file_put_contents($file, $code);
     if (!empty($names)) {
         $output->writeln(sprintf('<info>Менеджер БД обновлен, список коллекций: %s</info>', join(', ', $names)));
     } else {
         $output->writeln('<info>Первичная инициализация менеджера БД</info>');
     }
 }
コード例 #3
0
ファイル: RouteStrategy.php プロジェクト: sqrt-pro/kernel
 /**
  * {@inheritdoc}
  */
 public function dispatch($controller, array $vars)
 {
     if (is_string($controller) && strpos($controller, '::')) {
         $controller = explode('::', $controller);
     }
     if (is_array($controller)) {
         $controller = [$this->container->get('Controller\\' . $controller[0]), StaticStringy::camelize($controller[1] . ' action')];
     }
     $response = $this->container->call($controller, $vars);
     return $this->determineResponse($response);
 }
コード例 #4
0
 /**
  * @param string $rawName
  * @param \stdClass $boundary
  */
 public function importFilter($rawName, $boundary)
 {
     $name = S::camelize($rawName);
     $boundary = (array) $boundary;
     $isRanged = false;
     $title = S::humanize($rawName);
     if (isset($boundary['max']) || isset($boundary['min'])) {
         $isRanged = true;
     }
     $filterData = ['name' => $name, 'isRanged' => $isRanged, 'title' => $title, 'values' => $boundary];
     $this->filters[] = $filterData;
 }
コード例 #5
0
 /**
  * @param       $name
  * @param array $arguments
  *
  * @throws \ThinFrame\Foundation\Exceptions\InvalidArgumentException
  * @throws \BadMethodCallException
  */
 public function __call($name, array $arguments)
 {
     if (StaticStringy::startsWith($name, 'on')) {
         $eventId = StaticStringy::camelize(substr($name, 2));
         if (!isset($arguments[0]) || !is_callable($arguments[0])) {
             throw new InvalidArgumentException('Invalid or missing callback for event');
         }
         $priority = isset($arguments[1]) ? intval($arguments[1]) : Priority::LOW;
         $this->attachTo($eventId, $arguments[0], $priority);
     } else {
         throw new \BadMethodCallException('Method ' . $name . ' is not defined under ' . get_called_class());
     }
 }
コード例 #6
0
ファイル: Item.php プロジェクト: pharmonic/menu
 public function __call($name, $arguments)
 {
     if (substr($name, 0, 3) === 'get' && sizeof($arguments) === 0) {
         $name = Str::camelize(substr($name, 3));
         if (isset($this->props[$name])) {
             return $this->props[$name];
         }
         return;
     }
     if (substr($name, 0, 3) === 'set' && sizeof($arguments) === 1) {
         $name = Str::camelize(substr($name, 3));
         $this->props[$name] = $arguments[0];
         return true;
     }
 }
コード例 #7
0
ファイル: Menu.php プロジェクト: pharmonic/menu
 public function addMenu($name, $item)
 {
     $label = $item['label'];
     $link = null;
     if (isset($item['link'])) {
         $link = $this->prefix . $item['link'];
     }
     $childs = null;
     if (isset($item['childs'])) {
         $childs = new self($item['childs']);
         unset($item['childs']);
     }
     $this->items[$name] = new Item($label, $link);
     $this->items[$name]->setChilds($childs);
     foreach ($item as $key => $val) {
         $func = Str::camelize('set_' . $key);
         $this->items[$name]->{$func}($val);
     }
 }
コード例 #8
0
 /**
  * @dataProvider camelizeProvider()
  */
 public function testCamelize($expected, $str, $encoding = null)
 {
     $result = S::camelize($str, $encoding);
     $this->assertInternalType('string', $result);
     $this->assertEquals($expected, $result);
 }
コード例 #9
0
ファイル: StringyLoader.php プロジェクト: lablog/stringy
 public function camelize($string)
 {
     return Stringy::camelize($string);
 }
コード例 #10
0
ファイル: Otynirm.php プロジェクト: timoran/otynirm
 public function update(ProxyEntity $entitie)
 {
     $entitieInfo = $this->getEntitie($entitie);
     $entitieName = $this->getEntityName($entitie);
     $table = $entitieInfo->getTableName();
     $values = $entitieInfo->getValues();
     $map = $entitieInfo->getMap();
     $reversedValues = array_reverse($values);
     unset($reversedValues['id']);
     $values = array_reverse($reversedValues);
     $prepareSql = "UPDATE " . $table . " SET ";
     $i = 0;
     foreach ($values as $value) {
         if ($i > 0) {
             $prepareSql .= ", ";
         }
         $prepareSql .= "{$value}=?";
         $i++;
     }
     foreach ($map as $entitieMappedName => $relationType) {
         $entitieMappedTableName = S::underscored($entitieMappedName);
         if (empty($this->cachedEntity[$entitieMappedTableName])) {
             $this->cachedEntity[$entitieMappedTableName] = array();
         }
         foreach ($this->cachedEntity[$entitieMappedTableName] as $entitieItem) {
             $this->removeFromEntitie($entitieItem, $entitie);
         }
         $get = S::camelize($entitieMappedName);
         $linkedEntity = $entitie->{$get};
         if ($relationType == SchemaEntity::ONE) {
             if ($linkedEntity === null) {
                 continue;
             }
             if (!$linkedEntity instanceof ProxyEntity) {
                 try {
                     $this->create($linkedEntity);
                 } catch (Exception $e) {
                     throw new Exception("Error when update entitie '{$entitieName}' : " . $e->getMessage());
                 }
             }
             $prepareSql .= ", id_" . strtolower($entitieMappedName) . "=" . $linkedEntity->getId();
         } elseif ($relationType == SchemaEntity::MANY) {
             $linkedEntities = $entitie->{$entitieMappedName};
             foreach ($entitie->{$entitieMappedName} as $linkedEntity) {
                 if (!$linkedEntity instanceof ProxyEntity) {
                     try {
                         $this->create($linkedEntity);
                     } catch (Exception $e) {
                         throw new Exception("Error when update entitie '{$entitieName}' : " . $e->getMessage());
                     }
                 } else {
                     if ($linkedEntity instanceof ProxyEntity && $linkedEntity->isDirty()) {
                         try {
                             $this->update($linkedEntity);
                         } catch (Exception $e) {
                             throw new Exception("Error when update entitie '{$entitieName}' : " . $e->getMessage());
                         }
                     }
                 }
             }
         } else {
         }
     }
     $prepareSql .= " WHERE id=" . $entitie->getId();
     $stmt = $this->driver->prepare($prepareSql);
     $i = 1;
     foreach ($values as $value) {
         $get = S::camelize($value);
         $toSend = "toSend{$i}";
         ${$toSend} = $entitie->{$get};
         $stmt->bindParam($i, ${$toSend});
         $i++;
     }
     if (!$stmt->execute()) {
         $error = $stmt->errorInfo();
         throw new Exception("Error when update entitie '{$entitieName}' : " . $error[2]);
     }
     try {
         $stmt->closeCursor();
         $this->findById($entitieName, $entitie->getId());
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
 }
コード例 #11
0
ファイル: StaticFactory.php プロジェクト: ra3oul/Pelastic
 /**
  * Make string studly
  *
  * @param $string
  * @return string
  */
 public static function makeStudly($string)
 {
     return ucfirst(StaticStringy::camelize($string));
 }
コード例 #12
0
ファイル: Schema.php プロジェクト: sqrt-pro/db
 protected function makeItemBitmask($def, &$func, &$before, &$after)
 {
     $col = $def['column'];
     $setter = Item::MakeSetterName($col);
     $getter = Item::MakeGetterName($col);
     $name_for = StaticStringy::upperCamelize('get name for ' . $col);
     $getter_arr = StaticStringy::upperCamelize('get ' . $col . ' arr');
     $adder = StaticStringy::camelize('add ' . $col);
     $hasser = StaticStringy::camelize('has ' . $col);
     $remove = StaticStringy::camelize('remove ' . $col);
     $const = $names = '';
     $func[] = "  public function {$hasser}(\${$col})\n" . "  {\n" . "    return \$this->bitCheck('{$col}', \${$col});\n" . "  }";
     $func[] = "  public function {$getter}()\n" . "  {\n" . "    return \$this->bitGet('{$col}', array_keys(static::{$getter_arr}()));\n" . "  }";
     $func[] = "  public function {$setter}(array \$bits, \$clean = true)\n" . "  {\n" . "    return \$this->bitSet('{$col}', \$bits, \$clean);\n" . "  }";
     $func[] = "  /** @return static */\n" . "  public function {$adder}(\${$col})\n" . "  {\n" . "    if (!empty(\${$col}) && !static::{$name_for}(\${$col})) {\n" . "      Exception::ThrowError(Exception::ENUM_BAD_VALUE, '{$col}', \${$col});\n" . "    }\n\n" . "    return \$this->bitAdd('{$col}', \${$col});\n" . "  }";
     $func[] = "  /** @return static */\n" . "  public function {$remove}(\${$col})\n" . "  {\n" . "    if (!empty(\${$col}) && !static::{$name_for}(\${$col})) {\n" . "      Exception::ThrowError(Exception::ENUM_BAD_VALUE, '{$col}', \${$col});\n" . "    }\n\n" . "    return \$this->bitRemove('{$col}', \${$col});\n" . "  }";
     if (!empty($def['options'])) {
         $i = 0;
         foreach ($def['options'] as $v) {
             $c = strtoupper($col . '_' . $v);
             $b = pow(2, $i++);
             $f = $hasser . StaticStringy::upperCamelize($v);
             $const[] = "  const {$c} = {$b};";
             $names[] = "    self::{$c} => '{$v}',";
             $func[] = "  public function {$f}()\n" . "  {\n" . "    return \$this->{$hasser}(static::{$c});\n" . "  }";
         }
         $before[] = join("\n", $const);
     }
     $before[] = "  protected static \${$col}_arr = array(\n" . join("\n", $names) . "\n  );";
     $after[] = "  public static function {$getter_arr}()\n" . "  {\n" . "    return static::\${$col}_arr;\n" . "  }";
     $after[] = "  public static function {$name_for}(\${$col})\n" . "  {\n" . "    \$a = static::{$getter_arr}();\n\n" . "    return isset(\$a[\${$col}]) ? \$a[\${$col}] : false;\n" . "  }";
 }