/** * Gets the identifier for an entity * * @param object $entity The entity * * @return array The identifier as key-value pair(s) */ protected function getIdentifier($entity) { $entityId = json_decode($this->entityRegistry->getEntityId($entity), true); if (is_array($entityId)) { $identifier = []; foreach ($entityId as $key => $value) { $key = strtolower(Normalise::toUnderscoreSeparated(Normalise::fromCamelCase($key))); $identifier[$key] = $value; } return $identifier; } $primary = $this->builder->getMeta(get_class($entity))->primary; return [$primary => $entityId]; }
/** * Method to test Normalise::toUnderscoreSeparated(). * * @param string $expected The expected value from the method. * @param string $input The input value for the method. * * @return void * * @covers Joomla\String\Normalise::toUnderscoreSeparated * @dataProvider seedTestToUnderscoreSeparated * @since 1.0 */ public function testToUnderscoreSeparated($expected, $input) { $this->assertEquals($expected, Normalise::toUnderscoreSeparated($input)); }
/** * Gets the column name for an identifier * * @param string $identifier The identifier * * @return string */ public function columnName($identifier) { return Normalise::toUnderscoreSeparated($identifier); }
/** * @param string $word A word * * @return string */ private function normalise($word) { return Normalise::toUnderscoreSeparated(strtolower(Normalise::fromCamelCase($word))); }