Exemple #1
0
 /**
  * Get the field for the primary key.
  *
  * @return  string  The name of the field
  */
 public function key()
 {
     if (empty($this->key) && !empty($this->definition->primary)) {
         $keys = array_values(array_filter(preg_split('~[\\s,]+~', $this->definition->primary)));
         $keys = array_map(function ($key) {
             return Normalise::toVariable($key);
         }, $keys);
         $this->key = count($keys) > 1 ? $keys : array_shift($keys);
     }
     if (empty($this->key) && $this->has('id')) {
         $this->key = 'id';
     }
     return $this->key;
 }
 /**
  * Adds an entity to the repo
  *
  * @param   object $entity The entity to add
  *
  * @return  void
  *
  * @throws  OrmException  if the entity could not be added
  */
 public function add($entity)
 {
     foreach ($this->restrictions as $preset) {
         if ($preset['op'] == Operator::EQUAL) {
             $property = Normalise::toVariable($preset['field']);
             $entity->{$property} = $preset['value'];
         }
     }
     $this->unitOfWork->scheduleForInsertion($entity);
 }
Exemple #3
0
 /**
  * Gets the property name for an identifier
  *
  * @param   string $identifier The identifier
  *
  * @return  string
  */
 public function propertyName($identifier)
 {
     return Normalise::toVariable($identifier);
 }
 /**
  * Method to test Normalise::toVariable().
  *
  * @param   string  $expected  The expected value from the method.
  * @param   string  $input     The input value for the method.
  *
  * @return  void
  *
  * @covers        Joomla\String\Normalise::toVariable
  * @dataProvider  seedTestToVariable
  * @since         1.0
  */
 public function testToVariable($expected, $input)
 {
     $this->assertEquals($expected, Normalise::toVariable($input));
 }