Skip to content

Spamercz/PHP-OOP-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Before

  1. Get Data
$data = $this->elastic->get('3315342');
  1. Map Data
$title = new \Before\Model\Entity\Title($data);
  1. Edit entity
$title->setName('Logan');
$title->setPeople([
	123456 => [
		'id' => 123456,
		'name' => 'Hugh Jackman',
		'character' => 'James Howlett',
	 ],
]);
  1. Using entity
$title->getName();
foreach ($title->getPeople()->getData() as $person) {
	$person->getName();
	$person->getCharacter();
}
  1. Save entity
$this->elastic->save($entity->toArray());

After

  1. Get Data
$data = $this->elastic->get('3315342');
  1. Map Data - should be in entity factory
$people = new \After\Model\Collection\People([]);
$people->add(new \After\Model\Entity\Person(
	new \After\Model\Entity\Person\Id(
		new \After\Model\Entity\IntegerType($data['people']['id'])
	)
	, new \After\Model\Entity\Person\Name(
		new \After\Model\Entity\StringType($data['people']['name'])
	)
	, new \After\Model\Entity\Person\Character(
		new \After\Model\Entity\StringType($data['people']['character'])
	)
));

$title = new \After\Model\Entity\Title(
	new \After\Model\Entity\Title\Id(
		new \After\Model\Entity\StringType($data['id'])
	)
	, new \After\Model\Entity\Title\Name(
		new \After\Model\Entity\StringType($data['name'])
	)
	, new \After\Model\Entity\Title\Description(
		new \After\Model\Entity\StringType($data['description'])
	)
	, new \After\Model\Entity\Year(
		new \After\Model\Entity\IntegerType($data['year'])
	)
	, new \After\Model\Entity\Ids(
		new \After\Model\Entity\Ids\Imdb(
			new \After\Model\Entity\IntegerType($data['ids']['imdb'])
		)
	)
	, $people
);
  1. Edit entity
$newName = new \After\Model\Entity\Title\Name(
	new \After\Model\Entity\StringType('Old man Logan')
);
$title->rename($newName);

$entity->people()->add(new \After\Model\Entity\Person(
	new \After\Model\Entity\Person\Id(new \After\Model\Entity\IntegerType(413168))
	, new \After\Model\Entity\Person\Name(new \After\Model\Entity\StringType('Hugh Jackman'))
	, new \After\Model\Entity\Person\Character(new \After\Model\Entity\StringType('Logan'))
));
  1. Using entity
$title->name();
foreach ($entity->people()->items() as $person) {
	$person->name();
	$person->character();
}
  1. Save entity
$this->elastic->save((new \After\Model\ToArray())->decorate($entity));

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages