예제 #1
0
use Model\UserBis;
$paths = array("Model");
$isDevMode = false;
// the connection configuration
$dbParams = array('driver' => 'pdo_mysql', 'dbname' => 'vo', 'host' => 'localhost', 'user' => 'root', 'password' => '');
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
$tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
$classes = array($entityManager->getClassMetadata('Model\\CoffeeMaker'), $entityManager->getClassMetadata('Model\\User'), $entityManager->getClassMetadata('Model\\UserBis'), $entityManager->getClassMetadata('Model\\Capsule'), $entityManager->getClassMetadata('Model\\CapsuleType'));
$tool->dropSchema($classes);
$tool->createSchema($classes);
function sep($message = '')
{
    echo "\n\n############ " . $message . "\n";
}
$coffeeMakerKrups = new CoffeeMaker();
$coffeeMakerKrups->setModel('KRUPS U');
$capsule = new Capsule();
$ristretto = CapsuleType::fromValues('Ristretto', 'black', 'puissant et contrasté', 10);
$capsule->setType($ristretto);
$coffeeMakerKrups->setCurrentCapsule($capsule);
$entityManager->persist($coffeeMakerKrups);
$entityManager->persist($capsule);
$entityManager->flush();
sep("Coffee Maker persisted");
var_dump($coffeeMakerKrups);
$entityManager->clear();
$newCapsuleFromORM = $entityManager->find(Capsule::class, $capsule->getId());
sep("Capsule fetched from ORM");
var_dump($newCapsuleFromORM);
$entityManager->clear();
예제 #2
0
use Model\CoffeeMaker;
$ristretto = CapsuleType::fromValues('Ristretto', 'black', 'puissant et contrasté', 10);
$roma = CapsuleType::fromValues('Roma', 'purple', 'intense et crémeux', 9);
var_dump($ristretto == $roma);
var_dump($ristretto === $roma);
/**
 * Equality
 */
class VO
{
    private $test;
    public function __construct($test)
    {
        $this->test = $test;
    }
}
$one = new VO('coucou');
$two = new VO('coucou');
var_dump($one == $two);
var_dump($one === $two);
var_dump($one->__construct('omg'));
var_dump($one == $two);
var_dump($one);
$refObject = new ReflectionObject($one);
$refProperty = $refObject->getProperty('test');
$refProperty->setAccessible(true);
$refProperty->setValue($one, 'yolo');
var_dump($one);
$coffeeMakerKrups = new CoffeeMaker();
$coffeeMakerKrups->setModel('KRUPS U');
$coffeeMakerKrups->setCurrentCapsule(new Capsule());