1. Go to this page and download the library: Download carrooi/addressable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
carrooi / addressable example snippets
namespace App\Model\Entities;
use Carrooi\Addressable\Model\Entities\IAddressableEntity;
use Carrooi\Addressable\Model\Entities\TAddressable;
use Doctrine\ORM\Mapping as ORM;
use Kdyby\Doctrine\Entities\Attributes\Identifier;
use Kdyby\Doctrine\Entities\BaseEntity;
/**
* @ORM\Entity
* @author David Kudera
*/
class User extends BaseEntity implements IAddressableEntity
{
use Identifier;
use TAddressable;
}
namespace App\Model\Facades;
use Carrooi\Addressable\Model\Facades\AddressesFacade;
/**
* @author David Kudera
*/
class UsersFacade
{
/** @var \Kdyby\Doctrine\EntityManager */
private $em;
/** @var \Carrooi\Addressable\Model\Facades\AddressesFacade */
private $addressesFacade;
/**
* @param \Kdyby\Doctrine\EntityManager $em
* @param \Carrooi\Addressable\Model\Facades\AddressesFacade $addressesFacade
*/
public function __construct(EntityManager $em, AddressesFacade $addressesFacade)
{
$this->em = $em;
$this->addressesFacade = $addressesFacade;
}
/**
* @param \App\Model\Entities\User $user
* @param string $city
* @param int $postalCode
* @param int $houseNumber
* @param array $values
*/
public function addAddress(User $user, $city, $postalCode, $houseNumber, arra $values = [])
{
$address = $this->addressesFacade->create($city, $postalCode, $houseNumber, $values);
$user->setAddress($address);
$this->em->persist($user)->flush();
return $this;
}
/**
* @param \App\Model\Entities\User $user
*/
public function removeAddress(User $user)
{
$this->addressesFacade->remove($user->getAddress());
$user->setAddress(null);
$this->em->persist($user)->flush();
return $this;
}
}
/** @var \App\Model\Facades\UsersFacade @inject */
public $usersFacade;
/** @var \Carrooi\Addressable\Model\Facades\AddressesFacade @inject */
public $addressesFacade;
public function actionAdd()
{
$user = getUserSomehow();
$this->usersFacade->addAddress($user, 'Prague', 13000, 555, [
'orientationNumber' => '8b',
'street' => 'Lorem ipsum',
]);
}
public function actionEdit()
{
$user = getUserSomehow();
$address = $user->getAddress();
$this->addressesFacade->update($address, [
'city' => 'New York',
'postalCode' => 88877,
'houseNumber' => 1212,
'orientationNumber' => 45,
'street' => 'Ipsum',
]);
}
public function actionRemove()
{
$user = getUserSomehow();
$this->usersFacade->removeAddress($user);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.