Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move code around

  • Loading branch information...
commit d38f14bc5666aee141c67e09823e2bd818bd7c98 1 parent 6f47f10
Benjamin Eberlei authored
8 lib/CarDealer/Basic/BatchInsertScenario.php
View
@@ -2,14 +2,15 @@
namespace CarDealer\Basic;
use Doctrine\ORM\EntityManager;
-use Symfony\Component\Console\Input\InputInterface;
use CarFramework\ConsoleScenario;
+use CarDealer\Entity\Vehicle;
class BatchInsertScenario extends ConsoleScenario
{
- public function play(EntityManager $entityManager, InputInterface $input)
+ public function play(EntityManager $entityManager, array $input)
{
- for ($i = 0; $i < 50000; $i++) {
+ for ($i = 0; $i < 2000; $i++) {
+
$vehicle = new Vehicle();
$vehicle->setOffer("Brand New Audi A8 for just 80.000 €");
$vehicle->setPrice(1000 * ($i % 100));
@@ -17,6 +18,7 @@ public function play(EntityManager $entityManager, InputInterface $input)
$vehicle->setKilometres(400 * rand(1, 10000));
$entityManager->persist($vehicle);
+
if ($i % 1000 == 0) {
$entityManager->flush();
$entityManager->clear();
22 lib/CarDealer/Basic/InsertScenario.php
View
@@ -0,0 +1,22 @@
+<?php
+namespace CarDealer\Basic;
+
+use Doctrine\ORM\EntityManager;
+use CarFramework\ConsoleScenario;
+use CarDealer\Entity\Vehicle;
+
+class InsertScenario extends ConsoleScenario
+{
+ /** php console example:basic:insert */
+ public function play(EntityManager $entityManager, array $args)
+ {
+ $vehicle = new Vehicle;
+ $vehicle->setOffer("Brand New Audi A8 for just 80.000 €");
+ $vehicle->setPrice(80000);
+ $vehicle->setAdmission(new \DateTime( (1980 + rand(0, 32)) . "-01-01"));
+ $vehicle->setKilometres(400 * rand(1, 10000));
+
+ $entityManager->persist($vehicle);
+ $entityManager->flush();
+ }
+}
12 lib/CarDealer/Basic/RemoveScenario.php
View
@@ -2,23 +2,21 @@
namespace CarDealer\Basic;
use Doctrine\ORM\EntityManager;
-use Symfony\Component\Console\Input\InputInterface;
use CarFramework\ConsoleScenario;
class RemoveScenario extends ConsoleScenario
{
/** php console example:basic:remove <id> */
- public function play(EntityManager $entityManager, InputInterface $input)
+ public function play(EntityManager $entityManager, array $args)
{
- $args = $input->getArgument("args");
if (count($args) == 0) {
- throw new \InvalidArgumentException("Eine ID wird als Parameter erwartet!");
+ throw new \InvalidArgumentException("One parameter 'ID' is expected.");
}
$id = $args[0];
- echo "Loesche Entitaet mit ID $id\n";
+ echo "Delete Entity with ID $id\n";
- // 1. entity aus datenbank holen
- // 2. entity löschen
+ // 1. grab entity from database
+ // 2. delete entity
}
}
11 lib/CarDealer/Basic/UpdateScenario.php
View
@@ -2,15 +2,13 @@
namespace CarDealer\Basic;
use Doctrine\ORM\EntityManager;
-use Symfony\Component\Console\Input\InputInterface;
use CarFramework\ConsoleScenario;
class UpdateScenario extends ConsoleScenario
{
/** php console example:basic:update <id> price 20000 */
- public function play(EntityManager $entityManager, InputInterface $input)
+ public function play(EntityManager $entityManager, array $args)
{
- $args = $input->getArgument("args");
if (count($args) != 3) {
throw new \InvalidArgumentException("Ein Parameter ID, 'feldName' und 'value' wird erwartet.");
}
@@ -19,11 +17,12 @@ public function play(EntityManager $entityManager, InputInterface $input)
$method = "set" . $args[1];
$value = $args[2];
- // 1. entity aus datenbank holen
+ // 1. Grab entity from ddatabase
- $object->$method($value);
+ // 2. set the property
+ //$object->$method($value);
- $entityManager->flush();
+ // 3. flush transaction
}
}
31 lib/CarDealer/Basic/VehicleScenario.php
View
@@ -1,31 +0,0 @@
-<?php
-namespace CarDealer\Basic;
-
-use Doctrine\ORM\EntityManager;
-use Symfony\Component\Console\Input\InputInterface;
-use CarFramework\ConsoleScenario;
-
-class VehicleScenario extends ConsoleScenario
-{
- public function play(EntityManager $entityManager, InputInterface $input)
- {
- $vehicle = new Vehicle();
- $vehicle->setOffer("Brand New Audi A8 for just 80.000 €");
- $vehicle->setPrice(80000);
- $vehicle->setAdmission(new \DateTime("2012-01-01"));
- $vehicle->setKilometres(400);
-
- $entityManager->persist($vehicle);
-
- $this->tick("flush");
- $entityManager->flush();
- $this->tick("flush");
-
- $entityManager->clear();
-
- $vehicle = $entityManager->find('CarDealer\Basic\Vehicle', $vehicle->getId());
-
- echo "The price is: " . $vehicle->getPrice() . "\n";
- }
-}
-
17 lib/CarDealer/Basic/ViewScenario.php
View
@@ -2,22 +2,25 @@
namespace CarDealer\Basic;
use Doctrine\ORM\EntityManager;
-use Symfony\Component\Console\Input\InputInterface;
use CarFramework\ConsoleScenario;
class ViewScenario extends ConsoleScenario
{
- public function play(EntityManager $entityManager, InputInterface $input)
+ /** php console example:basic:view <id> */
+ public function play(EntityManager $entityManager, array $args)
{
- $args = $input->getArgument("args");
if (count($args) == 0) {
- throw new \InvalidArgumentException("Eine ID wird als Parameter erwartet!");
+ throw new \InvalidArgumentException("One parameter 'ID' is expected.");
}
$id = $args[0];
- // 1. entity aus datenbank holen
- // 2. entity anzeigen
- $vehicle = $entityManager->find('CarDealer\Basic\Vehicle', $id);
+ // 1. get entity from database
+ // 2. show entity details
+ $vehicle = $entityManager->find('CarDealer\Entity\Vehicle', $id);
+ if (!$vehicle) {
+ echo "Not found";
+ return;
+ }
echo "The price is: " . $vehicle->getPrice() . "\n";
}
20 lib/CarDealer/Classes/Award.php
View
@@ -0,0 +1,20 @@
+<?php
+
+namespace CarDealer\Entity;
+
+/**
+ * @Entity
+ * @Table(name="awards")
+ */
+class Award extends \CarFramework\BaseObject
+{
+ /**
+ * @Id @GeneratedValue @Column(type="integer")
+ * @var int
+ */
+ protected $id;
+ /**
+ * @Column(type="string")
+ */
+ protected $name;
+}
0  lib/CarDealer/Inheritance/Bike.php → lib/CarDealer/Classes/Bike.php
View
File renamed without changes
0  lib/CarDealer/Inheritance/Car.php → lib/CarDealer/Classes/Car.php
View
File renamed without changes
20 lib/CarDealer/Classes/Image.php
View
@@ -0,0 +1,20 @@
+<?php
+
+namespace CarDealer\Entity;
+
+/**
+ * @Entity
+ * @Table(name="images")
+ */
+class Image extends \CarFramework\BaseObject
+{
+ /**
+ * @Id @GeneratedValue @Column(type="integer")
+ * @var int
+ */
+ protected $id;
+ /**
+ * @Column(type="text")
+ */
+ protected $ascii;
+}
4 lib/CarDealer/Inheritance/Make.php → lib/CarDealer/Classes/Make.php
View
@@ -1,10 +1,10 @@
<?php
-namespace CarDealer\Inheritance;
+namespace CarDealer\Entity;
/**
* @Entity
- * @Table(name="joined_make")
+ * @Table(name="make")
*/
class Make extends \CarFramework\BaseObject
{
0  lib/CarDealer/Inheritance/Truck.php → lib/CarDealer/Classes/Truck.php
View
File renamed without changes
0  lib/CarDealer/Inheritance/Vehicle.php → lib/CarDealer/Classes/Vehicle.php
View
File renamed without changes
22 lib/CarDealer/Entity/Vehicle.php
View
@@ -0,0 +1,22 @@
+<?php
+
+namespace CarDealer\Entity;
+
+/**
+ * @Entity
+ * @Table("vehicle")
+ */
+class Vehicle extends \CarFramework\BaseObject
+{
+ /** @Column(type="integer") @Id @GeneratedValue **/
+ protected $id;
+ /** @Column(type="string") **/
+ protected $offer;
+ /** @Column(type="integer") **/
+ protected $price;
+ /** @Column(type="integer") **/
+ protected $kilometres;
+ /** @Column(type="date") **/
+ protected $admission;
+}
+
3  lib/CarDealer/Inheritance/VehicleScenario.php
View
@@ -2,12 +2,11 @@
namespace CarDealer\Inheritance;
use Doctrine\ORM\EntityManager;
-use Symfony\Component\Console\Input\InputInterface;
use CarFramework\ConsoleScenario;
class VehicleScenario extends ConsoleScenario
{
- public function play(EntityManager $entityManager, InputInterface $input)
+ public function play(EntityManager $entityManager, array $args)
{
$vehicle = new Car();
$vehicle->setOffer("Brand New Audi A8 for just 80.000 €");
2  lib/CarFramework/Application.php
View
@@ -13,7 +13,7 @@ public static function bootstrap($configFile, $isDevMode = true, $cache = null)
{
$dbParams = Yaml::parse($configFile);
- $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/../CarDealer"), $isDevMode, null, $cache);
+ $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/../CarDealer/Entity"), $isDevMode, null, $cache);
$entityManager = EntityManager::create($dbParams, $config);
if ($dbParams['driver'] == "pdo_sqlite" && isset($dbParams['memory'])) {
7 lib/CarFramework/ConsoleScenario.php
View
@@ -43,7 +43,8 @@ protected function configure()
$logger = new \CarFramework\ConsoleSQLLogger($output);
$this->em->getConfiguration()->setSQLLogger($logger);
- $this->play($this->em, $input);
+ $args = $input->getArgument("args");
+ $this->play($this->em, $args);
$logger->finalize();
}
@@ -63,8 +64,8 @@ public function tick($timerName)
* Play the scenario
*
* @param EntityManager $entityManager
- * @param InputInterface $input
+ * @param array $args
*/
- abstract public function play(EntityManager $entityManager, InputInterface $input);
+ abstract public function play(EntityManager $entityManager, array $args);
}
Please sign in to comment.
Something went wrong with that request. Please try again.