Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * 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;
     }
 }
Пример #3
0
 /**
  * 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);
 }
 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);
                 }
             }
         }
     }
 }
Пример #5
0
 /**
  * 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);
 }
Пример #6
0
 /**
  * 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();
 }
Пример #7
0
 /**
  * @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;
 }
Пример #8
0
 /**
  * @inheritdoc
  */
 public static function camelize($word)
 {
     if (!isset(static::$cache['camelize'][$word])) {
         static::$cache['camelize'][$word] = parent::camelize($word);
     }
     return static::$cache['camelize'][$word];
 }
Пример #9
0
 /**
  * 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;
     }
 }
Пример #10
0
 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();
     }
 }
Пример #11
0
 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.");
 }
Пример #12
0
 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();
     }
 }
 /**
  * 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;
 }
 /**
  * Return name
  *
  * @return string
  */
 public function getName()
 {
     $classname = get_class($this);
     if (preg_match('@\\\\([\\w]+)$@', $classname, $matches)) {
         $classname = $matches[1];
     }
     return Inflector::tableize($classname);
 }
 /**
  * {@inheritdoc}
  */
 public function transformName($name)
 {
     if ($this->ucFirst) {
         return Inflector::classify($name);
     } else {
         return Inflector::camelize($name);
     }
 }
 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();
 }
Пример #17
0
 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()));
     }
 }
Пример #18
0
 /**
  * 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.");
 }
Пример #19
0
 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}"}();
     }
 }
 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()));
     }
 }
 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;
 }
 public static function configureMigrationsForBundle(Application $application, $bundle, Configuration $configuration)
 {
     $bundle = $application->getKernel()->getBundle($bundle);
     $dir = $bundle->getPath() . '/DoctrineMigrations';
     $configuration->setMigrationsNamespace($bundle->getNamespace() . '\\DoctrineMigrations');
     $configuration->setMigrationsDirectory($dir);
     $configuration->registerMigrationsFromDirectory($dir);
     $configuration->setName($bundle->getName() . ' Migrations');
     $configuration->setMigrationsTableName(Inflector::tableize($bundle->getName()) . '_migration_versions');
 }
Пример #23
0
 /**
  * convert to array from object.
  *
  * @return array
  */
 public function toArray() : array
 {
     $result = [];
     foreach ($this->getObjectVars() as $property) {
         $method = Inflector::camelize('get_' . $property);
         if (method_exists($this, $method)) {
             $result[$property] = $this->{$method}();
         }
     }
     return $result;
 }
Пример #24
0
 /**
  * @param $data
  */
 public function setData($data)
 {
     foreach ($data as $field => $value) {
         //Ex: user_id => user id => userId => UserId => setUserId
         $setter_method_name = Inflector::camelize(str_replace('_', ' ', $field));
         $setter_method_name = ucfirst($setter_method_name);
         $setter_method_name = 'set' . $setter_method_name;
         $this->{$setter_method_name}($value);
     }
     return $data;
 }
Пример #25
0
 /**
  * Returns the translation key for the given entity property
  *
  * The result format for entity: [vendor].[bundle].[entity].entity_[property]
  * Examples:
  *  label for Acme\Bundle\TestBundle\Entity\Product          -> acme.test.product.entity_label
  *  description for Acme\Bundle\ProductBundle\Entity\Product -> acme.product.entity_label
  *
  * The result format for field: [vendor].[bundle].[entity].[field].[property]
  * Examples:
  *  label for Acme\Bundle\TestBundle\Entity\Product::sellPrice    -> acme.test.product.sell_price.label
  *  label for Acme\Bundle\ProductBundle\Entity\Product::sellPrice -> acme.product.sell_price.label
  *
  * @param string      $propertyName
  * @param string      $className
  * @param string|null $fieldName
  *
  * @return string
  */
 public static function getTranslationKey($propertyName, $className, $fieldName = null)
 {
     $parts = self::explodeClassName($className);
     if ($fieldName) {
         $parts[] = Inflector::tableize($fieldName);
         $parts[] = $propertyName;
     } else {
         $parts[] = 'entity_' . $propertyName;
     }
     return implode('.', $parts);
 }
Пример #26
0
 /**
  * Initialises the controller.
  */
 public function init()
 {
     /** @var \BedRest\Framework\Zend1\Container _bedRest */
     $this->_bedRest = $this->getFrontController()->getParam('bootstrap')->getResource('bedrest');
     $this->_bedRestRequest = new Request();
     $this->_bedRestRequest->setResource(Inflector::classify($this->getRequest()->getControllerName()));
     $routeComponents = array('identifier' => $this->_getParam('id'));
     $this->_bedRestRequest->setRouteComponents($routeComponents);
     $data = file_get_contents('php://input');
     $this->_bedRestRequest->setRawBody($data);
     $this->_helper->ViewRenderer->setNoRender(true);
 }
Пример #27
0
 /**
  * @param $rawCart
  * @return Cart
  * @throws ApiTransformationException
  */
 public function transform($rawCart)
 {
     $cart = new Cart();
     foreach (json_decode($rawCart) as $key => $value) {
         $setter = 'set' . ucfirst(Inflector::camelize($key));
         if (!method_exists($cart, $setter)) {
             throw new ApiTransformationException();
         }
         $cart->{$setter}($value);
     }
     return $cart;
 }
Пример #28
0
 /**
  * Calls methods from the specified object in underscore case.
  *
  * @param  object      $object
  * @param  string      $method
  * @param  mixed       $parameters
  * @param  object|null $anotherObject
  * @return mixed
  */
 public static function call($object, $method, $parameters, $anotherObject = null)
 {
     $method = \Doctrine\Common\Util\Inflector::camelize($method);
     $result = $object;
     if (is_null($anotherObject)) {
         $anotherObject = $object;
     }
     if (method_exists($anotherObject, $method)) {
         $result = call_user_func_array([$anotherObject, $method], $parameters);
     }
     return $result;
 }
Пример #29
0
 /**
  * @param Object $object
  * @param array $valuesToCompare
  */
 public static function compareValues($object, $valuesToCompare)
 {
     foreach ($valuesToCompare as $key => $value) {
         $method = 'get' . Inflector::classify($key);
         if (method_exists($object, $method)) {
             if ($value != $object->{$method}()) {
                 return false;
             }
         }
     }
     return (bool) $valuesToCompare;
 }
Пример #30
0
 public function testTimestamps()
 {
     $entity = new Document();
     foreach (['created', 'updated'] as $field) {
         $setter = sprintf('set%s', ucfirst(Inflector::camelize($field)));
         $getter = sprintf('get%s', ucfirst(Inflector::camelize($field)));
         $this->assertNull($entity->{$getter}());
         $fluent = $entity->{$setter}(new \DateTime());
         $this->assertEquals($entity, $fluent, 'Fluent interface is not working');
         $this->assertNotNull($entity->{$getter}());
     }
 }