From bea3c653bc3e0780ca6ec170235953ef2a75842e Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Wed, 7 Sep 2016 17:39:51 -0300 Subject: [PATCH] Updated docs --- docs/en/reference/working-with-objects.rst | 48 +++++++++---------- docs/en/tutorials/getting-started.rst | 56 +++++++++++----------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index bcc9bf185..2b52fac41 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -41,7 +41,7 @@ headline "Hello World" with the ID 1234: find('CMS\Article', 1234); $article->setHeadline('Hello World dude!'); - + $article2 = $entityManager->find('CMS\Article', 1234); echo $article2->getHeadline(); @@ -93,25 +93,25 @@ from newly opened EntityManager. { /** @Id @Column(type="integer") @GeneratedValue */ private $id; - + /** @Column(type="string") */ private $headline; - + /** @ManyToOne(targetEntity="User") */ private $author; - + /** @OneToMany(targetEntity="Comment", mappedBy="article") */ private $comments; - + public function __construct() { $this->comments = new ArrayCollection(); } - + public function getAuthor() { return $this->author; } public function getComments() { return $this->comments; } } - + $article = $em->find('Article', 1); This code only retrieves the ``Article`` instance with id 1 executing @@ -132,22 +132,22 @@ your code. See the following code: find('Article', 1); - + // accessing a method of the user instance triggers the lazy-load echo "Author: " . $article->getAuthor()->getName() . "\n"; - + // Lazy Loading Proxies pass instanceof tests: if ($article->getAuthor() instanceof User) { // a User Proxy is a generated "UserProxy" class } - + // accessing the comments as an iterator triggers the lazy-load // retrieving ALL the comments of this article from the database // using a single SELECT statement foreach ($article->getComments() as $comment) { echo $comment->getText() . "\n\n"; } - + // Article::$comments passes instanceof tests for the Collection interface // But it will NOT pass for the ArrayCollection interface if ($article->getComments() instanceof \Doctrine\Common\Collections\Collection) { @@ -167,7 +167,7 @@ methods along the lines of the ``getName()`` method shown below: { // lazy loading code } - + public function getName() { $this->_load(); @@ -262,7 +262,7 @@ which means that its persistent state will be deleted once for and appear in query and collection results. See the section on :ref:`Database and UnitOfWork Out-Of-Sync ` for more information. - + Example: @@ -681,13 +681,13 @@ methods on a repository as follows: getRepository('MyProject\Domain\User')->findBy(array('age' => 20)); - + // All users that are 20 years old and have a surname of 'Miller' $users = $em->getRepository('MyProject\Domain\User')->findBy(array('age' => 20, 'surname' => 'Miller')); - + // A single user by its nickname $user = $em->getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb')); @@ -723,7 +723,7 @@ examples are equivalent: getRepository('MyProject\Domain\User')->findOneBy(array('nickname' => 'romanb')); - + // A single user by its nickname (__call magic) $user = $em->getRepository('MyProject\Domain\User')->findOneByNickname('romanb'); @@ -733,7 +733,7 @@ Additionally, you can just count the result of the provided conditions when you getRepository('MyProject\Domain\User')->count(array('nickname' => 'nonexistent')); + $availableNickname = 0 === $em->getRepository('MyProject\Domain\User')->count(['nickname' => 'nonexistent']); By Criteria ~~~~~~~~~~~ @@ -782,7 +782,7 @@ A DQL query is represented by an instance of the createQuery("select u from MyDomain\Model\User u where u.age >= 20 and u.age <= 30"); $users = $q->getResult(); @@ -825,18 +825,18 @@ in a central location. getRepository('MyDomain\Model\User')->getAllAdminUsers(); diff --git a/docs/en/tutorials/getting-started.rst b/docs/en/tutorials/getting-started.rst index 5e0444246..05492b133 100644 --- a/docs/en/tutorials/getting-started.rst +++ b/docs/en/tutorials/getting-started.rst @@ -103,7 +103,7 @@ Install Doctrine using the Composer Dependency Management tool, by calling: $ composer install This will install the packages Doctrine Common, Doctrine DBAL, Doctrine ORM, -Symfony YAML and Symfony Console into the `vendor` directory. The Symfony +Symfony YAML and Symfony Console into the `vendor` directory. The Symfony dependencies are not required by Doctrine but will be used in this tutorial. Add the following directories: @@ -131,22 +131,22 @@ step: // bootstrap.php use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; - + require_once "vendor/autoload.php"; - + // Create a simple "default" Doctrine ORM configuration for Annotations $isDevMode = true; $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode); // or if you prefer yaml or XML //$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode); //$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode); - + // database configuration parameters $conn = array( 'driver' => 'pdo_sqlite', 'path' => __DIR__ . '/db.sqlite', ); - + // obtaining the entity manager $entityManager = EntityManager::create($conn, $config); @@ -185,7 +185,7 @@ doctrine command. Its a fairly simple file: getRepository('Product') - ->count(array('name' => $productName)); + $productCount = $entityManager->getRepository(Product::class) + ->count(['name' => $productName]); Conclusion ----------