/** * Create a few creatures and add them to the pet shop * * @return bool * @throws Exception */ function savePetShop() { logStats('create three nameless cats'); logStats('create three nameless dogs'); @($objects = [new Cat(), new Cat(), new Cat(), new Dog(), new Dog(), new Dog()]); logStats('insert all six pets into the database'); logStats('guarantee all the pets are persisted'); $data = getDataObject(); $data->beginTran(); foreach ($objects as $object) { if ($data->insert($object) === false) { return $data->rollback(); } } return $data->commit(); }
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); include_once dirname(__DIR__) . '/vendor/autoload.php'; @($cat = new \Animals\Cat()); printf("Name is currently %s\n", $cat->getName()); $cat->setName("Garfield"); printf("Name has been changed to %s\n", $cat->getName()); $cat->speak(); echo PHP_EOL; $cat->speak('brrrr'); echo PHP_EOL; @($dog = new \Animals\Dog()); printf("Name is currently %s\n", $dog->getName()); $dog->setName("Odie"); printf("Name has been changed to %s\n", $dog->getName()); $dog->speak(); echo PHP_EOL; include 'petShop.php'; saveTest(); savePetShop(); logStats(); logStats('we are done');