/** * @return string */ public function getData() { $camelizedName = PropelInflector::camelize('get_' . $this->getName()); if (method_exists($this, $camelizedName)) { $result = $this->{$camelizedName}(); } else { $result = parent::getData(); } return $result; }
/** * Try to find the object with all params from the $request * * @param string $classQuery the query class * @param Request $request * * @return mixed */ protected function findOneBy($classQuery, Request $request) { $query = $this->getQuery($classQuery); $hasCriteria = false; foreach ($this->filters as $column => $value) { if (!in_array($column, $this->exclude)) { try { $query->{'filterBy' . PropelInflector::camelize($column)}($value); $hasCriteria = true; } catch (\PropelException $e) { } } } if (!$hasCriteria) { return false; } if (!$this->hasWith) { return $query->findOne(); } else { return $query->find()->getFirst(); } }
/** * Loads the data using the generated data model. * * @param array $data The data to be loaded */ protected function loadDataFromArray($data = null) { if ($data === null) { return; } foreach ($data as $class => $datas) { $class = trim($class); if ('\\' == $class[0]) { $class = substr($class, 1); } $tableMap = $this->dbMap->getTable(constant(constant($class . '::PEER') . '::TABLE_NAME')); $column_names = call_user_func_array(array(constant($class . '::PEER'), 'getFieldNames'), array(BasePeer::TYPE_FIELDNAME)); // iterate through datas for this class // might have been empty just for force a table to be emptied on import if (!is_array($datas)) { continue; } foreach ($datas as $key => $data) { // create a new entry in the database if (!class_exists($class)) { throw new \InvalidArgumentException(sprintf('Unknown class "%s".', $class)); } $obj = new $class(); if (!$obj instanceof BaseObject) { throw new \RuntimeException(sprintf('The class "%s" is not a Propel class. There is probably another class named "%s" somewhere.', $class, $class)); } if (!is_array($data)) { throw new \InvalidArgumentException(sprintf('You must give a name for each fixture data entry (class %s).', $class)); } foreach ($data as $name => $value) { if (is_array($value) && 's' === substr($name, -1)) { try { // many to many relationship $this->loadManyToMany($obj, substr($name, 0, -1), $value); continue; } catch (PropelException $e) { // Check whether this is actually an array stored in the object. if ('Cannot fetch TableMap for undefined table: ' . substr($name, 0, -1) === $e->getMessage()) { if (PropelColumnTypes::PHP_ARRAY !== $tableMap->getColumn($name)->getType() && PropelColumnTypes::OBJECT !== $tableMap->getColumn($name)->getType()) { throw $e; } } } } $isARealColumn = true; if ($tableMap->hasColumn($name)) { $column = $tableMap->getColumn($name); } elseif ($tableMap->hasColumnByPhpName($name)) { $column = $tableMap->getColumnByPhpName($name); } else { $isARealColumn = false; } // foreign key? if ($isARealColumn) { /* * A column, which is a PrimaryKey (self referencing, e.g. versionable behavior), * but which is not a ForeignKey (e.g. delegatable behavior on 1:1 relation). */ if ($column->isPrimaryKey() && null !== $value && !$column->isForeignKey()) { if (isset($this->object_references[$class . '_' . $value])) { $obj = $this->object_references[$class . '_' . $value]; continue; } } if ($column->isForeignKey() && null !== $value) { $relatedTable = $this->dbMap->getTable($column->getRelatedTableName()); if (!isset($this->object_references[$relatedTable->getClassname() . '_' . $value])) { throw new \InvalidArgumentException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedTable->getClassname())); } $value = $this->object_references[$relatedTable->getClassname() . '_' . $value]->getByName($column->getRelatedName(), BasePeer::TYPE_COLNAME); } } if (false !== ($pos = array_search($name, $column_names))) { $obj->setByPosition($pos, $value); } elseif (is_callable(array($obj, $method = 'set' . ucfirst(PropelInflector::camelize($name))))) { $obj->{$method}($value); } else { throw new \InvalidArgumentException(sprintf('Column "%s" does not exist for class "%s".', $name, $class)); } } $obj->save($this->con); $this->saveParentReference($class, $key, $obj); } } }
/** * Перевод из венгерского стиля в CamelCase * * @param $name * @return mixed */ protected function CamelCase($name) { return ucfirst(\Propel\PropelBundle\Util\PropelInflector::camelize($name)); }
/** * @dataProvider dataProviderForTestCamelize */ public function testCamelize($word, $expected) { $this->assertEquals($expected, PropelInflector::camelize($word)); }
/** * Loads the data using the generated data model. * * @param array $data The data to be loaded */ protected function loadDataFromArray($data = null) { if ($data === null) { return; } foreach ($data as $class => $datas) { $class = trim($class); $tableMap = $this->dbMap->getTable(constant(constant($class . '::PEER') . '::TABLE_NAME')); $column_names = call_user_func_array(array(constant($class . '::PEER'), 'getFieldNames'), array(BasePeer::TYPE_FIELDNAME)); // iterate through datas for this class // might have been empty just for force a table to be emptied on import if (!is_array($datas)) { continue; } foreach ($datas as $key => $data) { // create a new entry in the database if (!class_exists($class)) { throw new \InvalidArgumentException(sprintf('Unknown class "%s".', $class)); } $obj = new $class(); if (!$obj instanceof BaseObject) { throw new \RuntimeException(sprintf('The class "%s" is not a Propel class. There is probably another class named "%s" somewhere.', $class, $class)); } if (!is_array($data)) { throw new \InvalidArgumentException(sprintf('You must give a name for each fixture data entry (class %s).', $class)); } foreach ($data as $name => $value) { if (is_array($value) && 's' == substr($name, -1)) { // many to many relationship $this->loadManyToMany($obj, substr($name, 0, -1), $value); continue; } $isARealColumn = true; if ($tableMap->hasColumn($name)) { $column = $tableMap->getColumn($name); } else { if ($tableMap->hasColumnByPhpName($name)) { $column = $tableMap->getColumnByPhpName($name); } else { $isARealColumn = false; } } // foreign key? if ($isARealColumn) { if ($column->isForeignKey() && null !== $value) { $relatedTable = $this->dbMap->getTable($column->getRelatedTableName()); if (!isset($this->object_references[$relatedTable->getPhpName() . '_' . $value])) { throw new \InvalidArgumentException(sprintf('The object "%s" from class "%s" is not defined in your data file.', $value, $relatedTable->getPhpName())); } $value = $this->object_references[$relatedTable->getPhpName() . '_' . $value]->getByName($column->getRelatedName(), BasePeer::TYPE_COLNAME); } } if (false !== ($pos = array_search($name, $column_names))) { $obj->setByPosition($pos, $value); } elseif (is_callable(array($obj, $method = 'set' . ucfirst(PropelInflector::camelize($name))))) { $obj->{$method}($value); } else { throw new \InvalidArgumentException(sprintf('Column "%s" does not exist for class "%s".', $name, $class)); } } $obj->save($this->con); // save the object for future reference if (method_exists($obj, 'getPrimaryKey')) { $class_default = constant(constant($class . '::PEER') . '::CLASS_DEFAULT'); if ('/' !== substr($class_default, 0, 1)) { $class_default = '/' . $class_default; } $this->object_references[Propel::importClass($class_default) . '_' . $key] = $obj; } } } }