本文整理汇总了PHP中Doctrine\Common\Util\Inflector类的典型用法代码示例。如果您正苦于以下问题:PHP Inflector类的具体用法?PHP Inflector怎么用?PHP Inflector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Inflector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getName
/**
* Creates a name for a command that can be used throughout configuration files
*
* @return string
*/
public function getName()
{
$class = get_class($this);
$class = explode('\\', $class);
$class = $class[count($class) - 1];
$class = str_replace(array('Supra', 'Package'), '', $class);
$inflector = new Inflector();
$name = $inflector->tableize($class);
return $name;
}
开发者ID:sitesupra,项目名称:sitesupra,代码行数:15,代码来源:AbstractSupraPackage.php
示例2: setAttribute
/**
* Sets the attribute
*
* @param AttributeInterface $attribute
*
* @throws ColumnLabelException
*/
public function setAttribute(AttributeInterface $attribute = null)
{
$this->attribute = $attribute;
if (null === $attribute) {
$this->locale = null;
$this->scope = null;
$this->suffixes = $this->rawSuffixes;
$this->propertyPath = lcfirst(Inflector::classify($this->name));
} else {
$this->propertyPath = $attribute->getBackendType();
$suffixes = $this->rawSuffixes;
if ($attribute->isLocalizable()) {
if (count($suffixes)) {
$this->locale = array_shift($suffixes);
} else {
throw new ColumnLabelException('The column "%column%" must contain a locale code', array('%column%' => $this->label));
}
}
if ($attribute->isScopable()) {
if (count($suffixes)) {
$this->scope = array_shift($suffixes);
} else {
throw new ColumnLabelException('The column "%column%" must contain a scope code', array('%column%' => $this->label));
}
}
$this->suffixes = $suffixes;
}
}
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:35,代码来源:ColumnInfo.php
示例3: __call
/**
* Doctrine\ORM\EntityRepository.__call()と同じ動きで自前のfindBy関数を動かす
*
* @see Doctrine\ORM\EntityRepository::__call()
*/
public function __call($method, $arguments)
{
$by = null;
switch (true) {
case 0 === strpos($method, 'findCountBy'):
$by = substr($method, 11);
$method = 'findCountBy';
break;
}
// $by があれば、上記に定義した独自関数だったとする
if (!is_null($by)) {
$fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
switch (count($arguments)) {
case 1:
return $this->{$method}(array($fieldName => $arguments[0]));
case 2:
return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1]);
case 3:
return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]);
case 4:
return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]);
default:
// Do nothing
}
}
}
return parent::__call($method, $arguments);
}
开发者ID:iwatea,项目名称:Swim,代码行数:34,代码来源:AbstractRepository.php
示例4: _autofixeuroformat
private function _autofixeuroformat($object)
{
$formRequestData = $this->getRequest()->request->all();
if (!isset($formRequestData[$this->getForm()->getName()])) {
return;
}
$formRequestData = $formRequestData[$this->getForm()->getName()];
$fields = $object->fieldsAsArray($object);
foreach ($fields as $field => $value) {
$fieldDescription = $this->getFormFieldDescription($field);
if ($fieldDescription && ($type = $fieldDescription->getType())) {
if ($type == 'money' || $type == 'number' || $type == 'float') {
if (isset($formRequestData[$field])) {
$method = ucfirst(\Doctrine\Common\Util\Inflector::classify($field));
$setMethod = 'set' . $method;
$getMethod = 'get' . $method;
$value = str_replace(array("\n", "\t", "\r"), " ", $formRequestData[$field]);
$value = str_replace(array(' ', ','), array('', '.'), $value);
$value = preg_replace('/[^(\\x20-\\x7F)]*/', '', $value);
$object->{$setMethod}($value);
}
}
}
}
}
开发者ID:defan-marunchak,项目名称:eurotax,代码行数:25,代码来源:AbstractCompteAdmin.php
示例5: getTranslationKey
/**
* Returns translation key (placeholder) by entity class name, field name and property code
* examples (for default scope which is 'entity'):
* [vendor].[bundle].[entity].[field].[config property]
* oro.user.group.name.label
*
* if [entity] == [bundle] -> skip it
* oro.user.first_name.label
*
* if NO fieldName -> add prefix 'entity_'
* oro.user.entity_label
* oro.user.group.entity_label
* examples (for other scopes, for instance 'test'):
* [vendor].[bundle].[entity].[field].[scope]_[config property]
* oro.user.group.name.test_label
*
* if [entity] == [bundle] -> skip it
* oro.user.first_name.test_label
*
* if NO fieldName -> add prefix 'entity_'
* oro.user.entity_test_label
* oro.user.group.entity_test_label
*
* @param string $scope
* @param string $propertyName property key: label, description, plural_label, etc.
* @param string $className
* @param string $fieldName
*
* @return string
*
* @throws \InvalidArgumentException
*/
public static function getTranslationKey($scope, $propertyName, $className, $fieldName = null)
{
if (empty($scope)) {
throw new \InvalidArgumentException('$scope must not be empty');
}
if (empty($propertyName)) {
throw new \InvalidArgumentException('$propertyName must not be empty');
}
if (empty($className)) {
throw new \InvalidArgumentException('$className must not be empty');
}
// handle 'entity' scope separately
if ($scope === 'entity') {
return EntityLabelBuilder::getTranslationKey($propertyName, $className, $fieldName);
}
$parts = EntityLabelBuilder::explodeClassName($className);
$propertyName = Inflector::tableize($scope) . '_' . $propertyName;
if ($fieldName) {
$parts[] = Inflector::tableize($fieldName);
$parts[] = $propertyName;
} else {
$parts[] = 'entity_' . $propertyName;
}
return implode('.', $parts);
}
开发者ID:Maksold,项目名称:platform,代码行数:57,代码来源:ConfigHelper.php
示例6: executeHookHandler
/**
* Execute certain hook handler
*
* @return void
*/
public function executeHookHandler()
{
// It's the metadata collected by Doctrine
foreach ($this->getMetadata() as $main) {
$node = static::getClassesTree()->find($main->name);
// Process only certain classes
if (!$node->isTopLevelNode() && !$node->isDecorator()) {
foreach ($main->fieldMappings as $field => $info) {
if ('money' == $info['type']) {
$fieldName = \Includes\Utils\Converter::convertToCamelCase($field);
$purposes = array('net' => '');
$behaviors = array();
if (isset($info['options']) && is_array($info['options'])) {
foreach ($info['options'] as $option) {
if ($option instanceof \XLite\Core\Doctrine\Annotation\Behavior) {
$behaviors = array_merge($behaviors, $option->list);
} elseif ($option instanceof \XLite\Core\Doctrine\Annotation\Purpose) {
$purposes[$option->name] = $option->source;
}
}
}
foreach ($purposes as $purpose => $source) {
$camelField = ucfirst(\Doctrine\Common\Util\Inflector::camelize($field));
$source = $source ? ucfirst($source) . $camelField : $camelField;
$this->addReplacement($main, 'get', array('<getter>' => 'get' . $source, '<fieldName>' => $fieldName, '<methodName>' => ucfirst($purpose) . $camelField, '<behaviors>' => $behaviors ? '\'' . implode('\',\'', $behaviors) . '\'' : '', '<purpose>' => $purpose));
}
}
}
}
}
// Populate changes
$this->writeData();
}
开发者ID:kirkbauer2,项目名称:kirkxc,代码行数:38,代码来源:Main.php
示例7: setRelationships
/**
* @param \ReflectionClass $class
* @param ResourceEntityInterface $entity
* @param array $relationships
* @return self
*/
protected function setRelationships(\ReflectionClass $class, ResourceEntityInterface $entity, array $relationships)
{
foreach ($relationships as $relationship => $value) {
$camelCased = Inflector::camelize($relationship);
if (is_array($value)) {
$getter = DefaultMutator::GET . $camelCased;
$singular = Inflector::singularize($camelCased);
$remover = DefaultMutator::REMOVE . $singular;
$adder = DefaultMutator::ADD . $singular;
// @todo Improve algorithm.
foreach ($entity->{$getter}() as $item) {
$entity->{$remover}($item);
}
foreach ($value as $item) {
$entity->{$adder}($item);
}
} else {
$method = DefaultMutator::SET . $camelCased;
if ($class->hasMethod($method)) {
$entity->{$method}($value);
}
}
}
return $this;
}
开发者ID:gointegro,项目名称:hateoas,代码行数:31,代码来源:AltersEntities.php
示例8: setAttribute
/**
* Sets the attribute
*
* @param AttributeInterface $attribute
*
* @throws ColumnLabelException
*/
public function setAttribute(AttributeInterface $attribute = null)
{
$this->attribute = $attribute;
if (null === $attribute) {
$this->locale = null;
$this->scope = null;
$this->suffixes = $this->rawSuffixes;
$this->propertyPath = lcfirst(Inflector::classify($this->name));
} else {
if (!in_array($attribute->getBackendType(), [AbstractAttributeType::BACKEND_TYPE_REF_DATA_OPTION, AbstractAttributeType::BACKEND_TYPE_REF_DATA_OPTIONS])) {
$this->propertyPath = $attribute->getBackendType();
} else {
$this->propertyPath = $attribute->getReferenceDataName();
}
$suffixes = $this->rawSuffixes;
if ($attribute->isLocalizable()) {
if (count($suffixes)) {
$this->locale = array_shift($suffixes);
} else {
throw new ColumnLabelException('The column "%column%" must contain a locale code', ['%column%' => $this->label]);
}
}
if ($attribute->isScopable()) {
if (count($suffixes)) {
$this->scope = array_shift($suffixes);
} else {
throw new ColumnLabelException('The column "%column%" must contain a scope code', ['%column%' => $this->label]);
}
}
$this->suffixes = $suffixes;
}
}
开发者ID:qrz-io,项目名称:pim-community-dev,代码行数:39,代码来源:ColumnInfo.php
示例9: load
public function load(ObjectManager $manager)
{
$yaml = new Parser();
// TODO: find a way of obtainin Bundle's path with the help of $this->container
$bpath = $this->container->get('kernel')->getBundle('SiwappEstimateBundle')->getPath();
$value = $yaml->parse(file_get_contents($bpath . '/DataFixtures/estimates.yml'));
foreach ($value['Item'] as $ref => $values) {
$item = new Item();
$estimate = new Estimate();
foreach ($values as $fname => $fvalue) {
if ($fname == 'Estimate') {
$fvalue = $manager->merge($this->getReference($fvalue));
$fvalue->addItem($item);
$manager->persist($fvalue);
}
$method = 'set' . Inflector::camelize($fname);
if (is_callable(array($item, $method))) {
call_user_func(array($item, $method), $fvalue);
}
}
$manager->persist($item);
$manager->flush();
$this->addReference($ref, $item);
}
foreach ($value['ItemTax'] as $ref => $values) {
$item = $this->getReference($values['Item']);
$tax = $this->getReference($values['Tax']);
$item->addTax($tax);
$manager->persist($item);
$manager->flush();
}
}
开发者ID:siwapp,项目名称:siwapp-sf3,代码行数:32,代码来源:LoadItemData.php
示例10: __get
public function __get($property)
{
if (count($this->getPropertiesMap()) > 0) {
$map = $this->getPropertiesMap();
if (array_key_exists($property, $map)) {
$methodName = $map[$property];
if (method_exists($this, $methodName)) {
return $this->{$methodName}();
} elseif (method_exists($this->dataObject, $methodName)) {
return $this->dataObject->{$methodName}();
}
}
throw new \LogicException("Undefined " . $property . " property.");
}
$methodName = 'get' . \Doctrine\Common\Util\Inflector::classify($property);
if (method_exists($this, $methodName)) {
return $this->{$methodName}();
} elseif (property_exists($this, $property)) {
return $this->{$property};
} elseif (method_exists($this->dataObject, $methodName)) {
return $this->dataObject->{$methodName}();
} elseif (property_exists($this->dataObject, $property)) {
return $this->dataObject->{$property};
}
throw new \LogicException("Undefined " . $methodName . " method or missing " . $property . " property.");
}
开发者ID:sourcefabric,项目名称:newscoop,代码行数:26,代码来源:MetaBase.php
示例11: load
public function load(ObjectManager $manager)
{
$yaml = new Parser();
$bpath = $this->container->get('kernel')->getBundle('SiwappRecurringInvoiceBundle')->getPath();
$value = $yaml->parse(file_get_contents($bpath . '/DataFixtures/recurring_invoices.yml'));
foreach ($value['Item'] as $ref => $values) {
$item = new Item();
$recurring_invoice = new RecurringInvoice();
foreach ($values as $fname => $fvalue) {
if ($fname == 'RecurringInvoice') {
$fvalue = $manager->merge($this->getReference($fvalue));
}
$method = 'set' . Inflector::camelize($fname);
if (is_callable(array($item, $method))) {
call_user_func(array($item, $method), $fvalue);
}
}
$manager->persist($item);
$manager->flush();
$this->addReference($ref, $item);
}
foreach ($value['ItemTax'] as $ref => $values) {
$item = $this->getReference($values['Item']);
$tax = $this->getReference($values['Tax']);
$item->addTax($tax);
$manager->persist($item);
$manager->flush();
}
}
开发者ID:rvdavid,项目名称:siwapp-sf2,代码行数:29,代码来源:LoadItemData.php
示例12: createObject
/**
* Creates and returns one object based on the given data and metadata
*
* @param $class object's class name
* @param $data array of the object's fixture data
* @param $metadata the class metadata for doctrine
* @param $embedded true for embedded documents
* @return Object
*/
public function createObject($class, $data, $metadata, $options = array())
{
// options to state if a document is to be embedded or persisted on its own
$embedded = isset($options['embedded']);
$mapping = array_keys($metadata->fieldMappings);
// Instantiate new object
$object = new $class();
foreach ($data as $field => $value) {
// Add the fields defined in the fixtures file
$method = Inflector::camelize('set_' . $field);
// This is a standard field
if (in_array($field, $mapping)) {
// Dates need to be converted to DateTime objects
$type = $metadata->fieldMappings[$field]['type'];
if ($type == 'many') {
$method = Inflector::camelize('add_' . $field);
// EmbedMany
if (isset($metadata->fieldMappings[$field]['embedded']) && $metadata->fieldMappings[$field]['embedded']) {
foreach ($value as $embedded_value) {
$embed_class = $metadata->fieldMappings[$field]['targetDocument'];
$embed_data = $embedded_value;
$embed_meta = $this->getMetaDataForClass($embed_class);
$value = $this->createObject($embed_class, $embed_data, $embed_meta, array('embedded' => true));
$object->{$method}($value);
}
//ReferenceMany
} else {
foreach ($value as $reference_object) {
$object->{$method}($this->loader->getReference($reference_object));
}
}
} else {
if ($type == 'datetime' || $type == 'date' || $type == 'time') {
$value = new \DateTime($value);
}
if ($type == 'one') {
// EmbedOne
if (isset($metadata->fieldMappings[$field]['embedded']) && $metadata->fieldMappings[$field]['embedded']) {
$embed_class = $metadata->fieldMappings[$field]['targetDocument'];
$embed_data = $value;
$embed_meta = $this->getMetaDataForClass($embed_class);
$value = $this->createObject($embed_class, $embed_data, $embed_meta, array('embedded' => true));
// ReferenceOne
} else {
$value = $this->loader->getReference($value);
}
}
$object->{$method}($value);
}
} else {
// The key is not a field's name but the name of a method to be called
$object->{$method}($value);
}
}
// Save a reference to the current object
if (!$embedded) {
$this->runServiceCalls($object);
}
return $object;
}
开发者ID:Eskro,项目名称:KhepinYamlFixturesBundle,代码行数:69,代码来源:MongoYamlFixture.php
示例13: getName
/**
* Return name
*
* @return string
*/
public function getName()
{
$classname = get_class($this);
if (preg_match('@\\\\([\\w]+)$@', $classname, $matches)) {
$classname = $matches[1];
}
return Inflector::tableize($classname);
}
开发者ID:xleliberty,项目名称:BatchBundle,代码行数:13,代码来源:AbstractConfigurableStepElement.php
示例14: transformName
/**
* {@inheritdoc}
*/
public function transformName($name)
{
if ($this->ucFirst) {
return Inflector::classify($name);
} else {
return Inflector::camelize($name);
}
}
开发者ID:rafrsr,项目名称:lib-array2object,代码行数:11,代码来源:CamelCaseNamingStrategy.php
示例15: load
public function load(ObjectManager $manager, $tags = null)
{
if (!$this->hasTag($tags)) {
return;
}
$cmf = $manager->getMetadataFactory();
// The model class for all fixtures defined in this file
$class = $this->file['model'];
// Get the fields that are not "associations"
$metadata = $cmf->getMetaDataFor($class);
$mapping = array_keys($metadata->fieldMappings);
$associations = array_keys($metadata->associationMappings);
foreach ($this->file['fixtures'] as $reference => $fixture) {
// Instantiate new object
$object = new $class();
foreach ($fixture as $field => $value) {
// Add the fields defined in the fistures file
$method = Inflector::camelize('set_' . $field);
//
if (strpos($value, '$') === 0) {
// custom reference loader format: $<referencedEntityKey>|<referencedColumn>
// ex: $first_campaign|idcampaign
list($referencedEntity, $referenceColumn) = explode('|', ltrim($value, '$'));
$getterMethod = Inflector::camelize('get_' . $referenceColumn);
$object->{$method}($this->loader->getReference($referencedEntity)->{$getterMethod}());
} elseif (in_array($field, $mapping)) {
// Dates need to be converted to DateTime objects
$type = $metadata->fieldMappings[$field]['type'];
if ($type == 'datetime' or $type == 'date') {
$value = new \DateTime($value);
}
$object->{$method}($value);
} else {
if (in_array($field, $associations)) {
// This field is an association, we load it from the references
$object->{$method}($this->loader->getReference($value));
} else {
// It's a method call that will set a field named differently
// eg: FOSUserBundle ->setPlainPassword sets the password after
// Encrypting it
$object->{$method}($value);
}
}
}
// Save a reference to the current object
$this->loader->setReference($reference, $object);
if (!$this->isReverseSaveOrder()) {
$manager->persist($object);
}
}
if ($this->isReverseSaveOrder()) {
$refs = array_keys($this->file['fixtures']);
for ($i = count($refs) - 1; $i >= 0; $i--) {
$manager->persist($this->loader->getReference($refs[$i]));
}
}
$manager->flush();
}
开发者ID:rombob,项目名称:KhepinYamlFixturesBundle,代码行数:58,代码来源:YamlFixture.php
示例16: testSetProperty
public function testSetProperty()
{
$options = array('label' => 'my label', 'getter' => 'getFoo', 'sort_on' => 'foo', 'sortOn' => 'foo', 'dbType' => 'text', 'formType' => 'choices', 'formOptions' => array('foo' => 'bar'), 'filterType' => 'choice', 'filterOptions' => array('bar' => 'foo'));
$column = new Column("test", false);
foreach ($options as $option => $value) {
$column->setProperty($option, $value);
$this->assertEquals($value, call_user_func_array(array($column, 'get' . Inflector::classify($option)), array()));
}
}
开发者ID:Restless-ET,项目名称:GeneratorBundle,代码行数:9,代码来源:ColumnTest.php
示例17: __call
/**
* Magic method to execute curl_xxx calls
*
* @param string $name Method name (should be camelized)
* @param array $arguments Method arguments
*
* @return mixed
* @throws \Exception
*/
public function __call($name, $arguments)
{
$name = Inflector::tableize($name);
if (function_exists("curl_{$name}")) {
array_unshift($arguments, $this->handle);
return call_user_func_array("curl_{$name}", $arguments);
}
throw new \Exception("Function 'curl_{$name}' do not exist, see PHP manual.");
}
开发者ID:bebetojefry,项目名称:LswApiCallerBundle,代码行数:18,代码来源:Curl.php
示例18: offsetGet
public function offsetGet($offset)
{
$method = Inflector::classify($offset);
if (method_exists($this, "get{$method}")) {
return $this->{"get{$method}"}();
} elseif (method_exists($this, "is{$method}")) {
return $this->{"is{$method}"}();
}
}
开发者ID:noadless,项目名称:ec-cube,代码行数:9,代码来源:AbstractEntity.php
示例19: testSetOption
public function testSetOption()
{
$from_to_array = array('name' => 'Name', 'underscored_name' => 'Underscored name');
$options = array('label' => 'my label', 'getter' => 'getFoo', 'sort_on' => 'foo', 'sortOn' => 'foo', 'dbType' => 'text', 'formType' => 'choices', 'formOptions' => array('foo' => 'bar'));
$column = new Column($from_to_array);
foreach ($options as $option => $value) {
$column->setOption($option, $value);
$this->assertEquals($value, call_user_func_array(array($column, 'get' . Inflector::classify($option)), array()));
}
}
开发者ID:norfil,项目名称:AdmingeneratorGeneratorBundle,代码行数:10,代码来源:ColumnTest.php
示例20: getRelation
protected function getRelation($fieldName, $class = null)
{
$table = $this->getMetadatas($class);
foreach ($table->getRelations() as $relation) {
if (Inflector::classify($fieldName) == $relation->getName()) {
return $relation;
}
}
return false;
}
开发者ID:norfil,项目名称:AdmingeneratorGeneratorBundle,代码行数:10,代码来源:PropelORMFieldGuesser.php
注:本文中的Doctrine\Common\Util\Inflector类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论