コード例 #1
0
ファイル: SchemaEntity.php プロジェクト: timoran/otynirm
 public function __construct($className, array $values = array(), array $map = array(), $tableName = null)
 {
     $this->className = S::upperCamelize($className);
     if (empty($tableName)) {
         $this->tableName = S::underscored($className);
     }
     $this->values = $values;
     $this->map = $map;
 }
コード例 #2
0
ファイル: FileNameBuilder.php プロジェクト: czogori/dami
 /**
  * Build migration file name.
  *
  * @param datatype $timestamp Timestamp of migration.
  *
  * @return string
  */
 public function build($timestamp = null)
 {
     if (null === $timestamp) {
         $timestamp = new \DateTime();
         $timestamp = $timestamp->format('YmdHis');
     }
     $fileName = sprintf('%s_%s.php', $timestamp, S::underscored($this->migrationName));
     return $fileName;
 }
コード例 #3
0
ファイル: MigrationNameParser.php プロジェクト: czogori/dami
 /**
  * Sets a migration name.
  *
  * @param string $migrationName A migration name.
  *
  * @return void
  */
 public function setMigrationName($migrationName)
 {
     $this->migrationName = $migrationName;
     $migrationNameAsUnderscoreSrtring = S::underscored($migrationName);
     $items = explode('_', $migrationNameAsUnderscoreSrtring);
     if (count($items) >= 3) {
         $this->action = in_array($items[0], $this->validActions) ? $items[0] : null;
         $this->actionObject = in_array($items[1], $this->validActionObjects) ? $items[1] : null;
         $this->model = str_replace($items[0] . '_' . $items[1] . '_', '', $migrationNameAsUnderscoreSrtring);
     }
 }
コード例 #4
0
 /**
  * @inheritdoc
  */
 public function dirtyAttributeValues()
 {
     $params = [];
     foreach ($this->dirtyAttributes() as $attribute) {
         $key = (string) StaticStringy::underscored($attribute);
         if ($this->{$attribute} instanceof Model) {
             $params[$key . "_id"] = $this->{$attribute}->id;
         } else {
             $params[$key] = $this->{$attribute};
         }
     }
     return $params;
 }
コード例 #5
0
 /**
  * @dataProvider underscoredProvider()
  */
 public function testUnderscored($expected, $str, $encoding = null)
 {
     $result = S::underscored($str, $encoding);
     $this->assertInternalType('string', $result);
     $this->assertEquals($expected, $result);
 }
コード例 #6
0
ファイル: StringyLoader.php プロジェクト: lablog/stringy
 public function underscored($string)
 {
     return Stringy::underscored($string);
 }
コード例 #7
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());
     }
 }
コード例 #8
0
 /**
  * @param string $className
  * @param string $fieldName
  * @param string|null $layout
  * @param array $imageOptions
  *
  * @return string
  */
 public function getImagineFilterName($className, $fieldName, $layout, array $imageOptions)
 {
     $fileInfo = pathinfo($this->getConfigFileName($className, $fieldName));
     $storageName = $fileInfo['filename'];
     if ($fileInfo['dirname'] !== '.') {
         $storageName = $fileInfo['dirname'] . '/' . $storageName;
     }
     $storageName .= '_' . (empty($layout) ? '' : '--' . $layout . '_') . $imageOptions['width'] . '_' . $imageOptions['height'];
     return (string) S::underscored(str_replace(['/', '\\', '.'], '_', $storageName));
 }
コード例 #9
0
ファイル: Schema.php プロジェクト: sqrt-pro/db
 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" . "  }";
     }
 }