From 4ab9a87e83756acb93aa13a07d363419bcec947a Mon Sep 17 00:00:00 2001 From: Henry Snoek Date: Sat, 23 May 2015 11:09:11 +0200 Subject: [PATCH 1/3] 5177 use dump() instead of echo in examples --- book/doctrine.rst | 2 +- book/translation.rst | 4 +-- components/event_dispatcher/generic_event.rst | 5 +-- components/event_dispatcher/introduction.rst | 2 +- components/expression_language/caching.rst | 4 +-- components/expression_language/extending.rst | 3 +- .../expression_language/introduction.rst | 8 ++--- components/expression_language/syntax.rst | 24 ++++++------- components/form/introduction.rst | 4 +-- components/http_foundation/introduction.rst | 4 +-- components/intl.rst | 12 +++---- components/property_access/introduction.rst | 36 +++++++++---------- components/security/authorization.rst | 5 +-- components/serializer.rst | 2 +- components/translation/custom_formats.rst | 3 +- components/translation/usage.rst | 7 ++-- cookbook/bundles/remove.rst | 2 +- 17 files changed, 66 insertions(+), 61 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index e1f66134ed4..92ad5f8105e 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1190,7 +1190,7 @@ to the given ``Category`` object via their ``category_id`` value. $category = $product->getCategory(); // prints "Proxies\AcmeStoreBundleEntityCategoryProxy" - echo get_class($category); + dump(get_class($category)); This proxy object extends the true ``Category`` object, and looks and acts exactly like it. The difference is that, by using a proxy object, diff --git a/book/translation.rst b/book/translation.rst index 63a98e8309b..461319785e9 100644 --- a/book/translation.rst +++ b/book/translation.rst @@ -12,11 +12,11 @@ wrapping each with a function capable of translating the text (or "message") into the language of the user:: // text will *always* print out in English - echo 'Hello World'; + dump('Hello World'); // text can be translated into the end-user's language or // default to English - echo $translator->trans('Hello World'); + dump($translator->trans('Hello World')); .. note:: diff --git a/components/event_dispatcher/generic_event.rst b/components/event_dispatcher/generic_event.rst index 3be0b9bb876..73ade2a1c8e 100644 --- a/components/event_dispatcher/generic_event.rst +++ b/components/event_dispatcher/generic_event.rst @@ -75,7 +75,7 @@ the event arguments:: ); $dispatcher->dispatch('foo', $event); - echo $event['counter']; + dump($event['counter']); class FooListener { @@ -96,7 +96,7 @@ Filtering data:: $event = new GenericEvent($subject, array('data' => 'Foo')); $dispatcher->dispatch('foo', $event); - echo $event['data']; + dump($event['data']); class FooListener { @@ -105,3 +105,4 @@ Filtering data:: $event['data'] = strtolower($event['data']); } } + diff --git a/components/event_dispatcher/introduction.rst b/components/event_dispatcher/introduction.rst index 44db477789b..ebe833a04f5 100644 --- a/components/event_dispatcher/introduction.rst +++ b/components/event_dispatcher/introduction.rst @@ -641,7 +641,7 @@ part of the listener's processing logic:: { public function myEventListener(Event $event) { - echo $event->getName(); + // ... do something with the event name } } diff --git a/components/expression_language/caching.rst b/components/expression_language/caching.rst index 3ea35752e2f..24b2573e239 100644 --- a/components/expression_language/caching.rst +++ b/components/expression_language/caching.rst @@ -56,7 +56,7 @@ Both ``evaluate()`` and ``compile()`` can handle ``ParsedExpression`` and $expression = new ParsedExpression($language->parse('1 + 4')); - echo $language->evaluate($expression); // prints 5 + dump($language->evaluate($expression)); // prints 5 .. code-block:: php @@ -67,7 +67,7 @@ Both ``evaluate()`` and ``compile()`` can handle ``ParsedExpression`` and serialize($language->parse('1 + 4')) ); - echo $language->evaluate($expression); // prints 5 + dump($language->evaluate($expression)); // prints 5 .. _DoctrineBridge: https://github.com/symfony/DoctrineBridge .. _`doctrine cache library`: http://docs.doctrine-project.org/projects/doctrine-common/en/latest/reference/caching.html diff --git a/components/expression_language/extending.rst b/components/expression_language/extending.rst index 9676452219e..d2c37f5978a 100644 --- a/components/expression_language/extending.rst +++ b/components/expression_language/extending.rst @@ -44,7 +44,7 @@ This method has 3 arguments: return strtolower($str); }); - echo $language->evaluate('lowercase("HELLO")'); + dump($language->evaluate('lowercase("HELLO")')); This will print ``hello``. Both the **compiler** and **evaluator** are passed an ``arguments`` variable as their first argument, which is equal to the @@ -123,3 +123,4 @@ or by using the second argument of the constructor:: parent::__construct($parser, $providers); } } + diff --git a/components/expression_language/introduction.rst b/components/expression_language/introduction.rst index a53c8aa960d..07ff024900d 100644 --- a/components/expression_language/introduction.rst +++ b/components/expression_language/introduction.rst @@ -71,9 +71,9 @@ The main class of the component is $language = new ExpressionLanguage(); - echo $language->evaluate('1 + 2'); // displays 3 + dump($language->evaluate('1 + 2')); // displays 3 - echo $language->compile('1 + 2'); // displays (1 + 2) + dump($language->compile('1 + 2')); // displays (1 + 2) Expression Syntax ----------------- @@ -99,12 +99,12 @@ PHP type (including objects):: $apple = new Apple(); $apple->variety = 'Honeycrisp'; - echo $language->evaluate( + dump($language->evaluate( 'fruit.variety', array( 'fruit' => $apple, ) - ); + )); This will print "Honeycrisp". For more information, see the :doc:`/components/expression_language/syntax` entry, especially :ref:`component-expression-objects` and :ref:`component-expression-arrays`. diff --git a/components/expression_language/syntax.rst b/components/expression_language/syntax.rst index 49dd43b42cd..387716c2b94 100644 --- a/components/expression_language/syntax.rst +++ b/components/expression_language/syntax.rst @@ -42,12 +42,12 @@ to JavaScript:: $apple = new Apple(); $apple->variety = 'Honeycrisp'; - echo $language->evaluate( + dump($language->evaluate( 'fruit.variety', array( 'fruit' => $apple, ) - ); + )); This will print out ``Honeycrisp``. @@ -72,12 +72,12 @@ JavaScript:: $robot = new Robot(); - echo $language->evaluate( + dump($language->evaluate( 'robot.sayHi(3)', array( 'robot' => $robot, ) - ); + )); This will print out ``Hi Hi Hi!``. @@ -93,9 +93,9 @@ constant:: define('DB_USER', 'root'); - echo $language->evaluate( + dump($language->evaluate( 'constant("DB_USER")' - ); + )); This will print out ``root``. @@ -114,12 +114,12 @@ array keys, similar to JavaScript:: $data = array('life' => 10, 'universe' => 10, 'everything' => 22); - echo $language->evaluate( + dump($language->evaluate( 'data["life"] + data["universe"] + data["everything"]', array( 'data' => $data, ) - ); + )); This will print out ``42``. @@ -140,14 +140,14 @@ Arithmetic Operators For example:: - echo $language->evaluate( + dump($language->evaluate( 'life + universe + everything', array( 'life' => 10, 'universe' => 10, 'everything' => 22, ) - ); + )); This will print out ``42``. @@ -230,13 +230,13 @@ String Operators For example:: - echo $language->evaluate( + dump($language->evaluate( 'firstName~" "~lastName', array( 'firstName' => 'Arthur', 'lastName' => 'Dent', ) - ); + )); This would print out ``Arthur Dent``. diff --git a/components/form/introduction.rst b/components/form/introduction.rst index 09c947429b5..7376145670c 100644 --- a/components/form/introduction.rst +++ b/components/form/introduction.rst @@ -394,9 +394,9 @@ is created from the form factory. ->add('dueDate', 'date') ->getForm(); - echo $twig->render('new.html.twig', array( + dump($twig->render('new.html.twig', array( 'form' => $form->createView(), - )); + ))); .. code-block:: php-symfony diff --git a/components/http_foundation/introduction.rst b/components/http_foundation/introduction.rst index 100fae30f5d..96403551349 100644 --- a/components/http_foundation/introduction.rst +++ b/components/http_foundation/introduction.rst @@ -454,10 +454,10 @@ represented by a PHP callable instead of a string:: $response = new StreamedResponse(); $response->setCallback(function () { - echo 'Hello World'; + dump('Hello World'); flush(); sleep(2); - echo 'Hello World'; + dump('Hello World'); flush(); }); $response->send(); diff --git a/components/intl.rst b/components/intl.rst index bed02fc2b55..835c0167335 100644 --- a/components/intl.rst +++ b/components/intl.rst @@ -212,7 +212,7 @@ This class currently only works with the `intl extension`_ installed:: $reader = new BinaryBundleReader(); $data = $reader->read('/path/to/bundle', 'en'); - echo $data['Data']['entry1']; + dump($data['Data']['entry1']); PhpBundleReader ~~~~~~~~~~~~~~~ @@ -226,7 +226,7 @@ object:: $reader = new PhpBundleReader(); $data = $reader->read('/path/to/bundle', 'en'); - echo $data['Data']['entry1']; + dump($data['Data']['entry1']); BufferedBundleReader ~~~~~~~~~~~~~~~~~~~~ @@ -267,10 +267,10 @@ returned:: $data = $reader->read('/path/to/bundle', 'en'); // Produces an error if the key "Data" does not exist - echo $data['Data']['entry1']; + dump($data['Data']['entry1']); // Returns null if the key "Data" does not exist - echo $reader->readEntry('/path/to/bundle', 'en', array('Data', 'entry1')); + dump($reader->readEntry('/path/to/bundle', 'en', array('Data', 'entry1'))); Additionally, the :method:`Symfony\\Component\\Intl\\ResourceBundle\\Reader\\StructuredBundleReaderInterface::readEntry` @@ -281,12 +281,12 @@ multi-valued entries (arrays), the values of the more specific and the fallback locale will be merged. In order to suppress this behavior, the last parameter ``$fallback`` can be set to ``false``:: - echo $reader->readEntry( + dump($reader->readEntry( '/path/to/bundle', 'en', array('Data', 'entry1'), false - ); + )); Accessing ICU Data ------------------ diff --git a/components/property_access/introduction.rst b/components/property_access/introduction.rst index 55bbda909c3..81b5df2a595 100644 --- a/components/property_access/introduction.rst +++ b/components/property_access/introduction.rst @@ -45,8 +45,8 @@ method. This is done using the index notation that is used in PHP:: 'first_name' => 'Wouter', ); - echo $accessor->getValue($person, '[first_name]'); // 'Wouter' - echo $accessor->getValue($person, '[age]'); // null + dump($accessor->getValue($person, '[first_name]')); // 'Wouter' + dump($accessor->getValue($person, '[age]')); // null As you can see, the method will return ``null`` if the index does not exists. @@ -62,8 +62,8 @@ You can also use multi dimensional arrays:: ) ); - echo $accessor->getValue($persons, '[0][first_name]'); // 'Wouter' - echo $accessor->getValue($persons, '[1][first_name]'); // 'Ryan' + dump($accessor->getValue($persons, '[0][first_name]')); // 'Wouter' + dump($accessor->getValue($persons, '[1][first_name]')); // 'Ryan' Reading from Objects -------------------- @@ -80,13 +80,13 @@ To read from properties, use the "dot" notation:: $person = new Person(); $person->firstName = 'Wouter'; - echo $accessor->getValue($person, 'firstName'); // 'Wouter' + dump($accessor->getValue($person, 'firstName')); // 'Wouter' $child = new Person(); $child->firstName = 'Bar'; $person->children = array($child); - echo $accessor->getValue($person, 'children[0].firstName'); // 'Bar' + dump($accessor->getValue($person, 'children[0].firstName')); // 'Bar' .. caution:: @@ -116,7 +116,7 @@ property name (``first_name`` becomes ``FirstName``) and prefixes it with $person = new Person(); - echo $accessor->getValue($person, 'first_name'); // 'Wouter' + dump($accessor->getValue($person, 'first_name')); // 'Wouter' Using Hassers/Issers ~~~~~~~~~~~~~~~~~~~~ @@ -145,10 +145,10 @@ getters, this means that you can do something like this:: $person = new Person(); if ($accessor->getValue($person, 'author')) { - echo 'He is an author'; + dump('He is an author'); } if ($accessor->getValue($person, 'children')) { - echo 'He has children'; + dump('He has children'); } This will produce: ``He is an author`` @@ -173,7 +173,7 @@ The ``getValue`` method can also use the magic ``__get`` method:: $person = new Person(); - echo $accessor->getValue($person, 'Wouter'); // array(...) + dump($accessor->getValue($person, 'Wouter')); // array(...) Magic ``__call()`` Method ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -209,7 +209,7 @@ enable this feature by using :class:`Symfony\\Component\\PropertyAccess\\Propert ->enableMagicCall() ->getPropertyAccessor(); - echo $accessor->getValue($person, 'wouter'); // array(...) + dump($accessor->getValue($person, 'wouter')); // array(...) .. versionadded:: 2.3 The use of magic ``__call()`` method was introduced in Symfony 2.3. @@ -233,9 +233,9 @@ method:: $accessor->setValue($person, '[first_name]', 'Wouter'); - echo $accessor->getValue($person, '[first_name]'); // 'Wouter' + dump($accessor->getValue($person, '[first_name]')); // 'Wouter' // or - // echo $person['first_name']; // 'Wouter' + // dump($person['first_name']); // 'Wouter' Writing to Objects ------------------ @@ -269,9 +269,9 @@ can use setters, the magic ``__set`` method or properties to set values:: $accessor->setValue($person, 'lastName', 'de Jong'); $accessor->setValue($person, 'children', array(new Person())); - echo $person->firstName; // 'Wouter' - echo $person->getLastName(); // 'de Jong' - echo $person->children; // array(Person()); + dump($person->firstName); // 'Wouter' + dump($person->getLastName()); // 'de Jong' + dump($person->children); // array(Person()); You can also use ``__call`` to set values but you need to enable the feature, see `Enable other Features`_. @@ -307,7 +307,7 @@ see `Enable other Features`_. $accessor->setValue($person, 'wouter', array(...)); - echo $person->getWouter(); // array(...) + dump($person->getWouter()); // array(...) Checking Property Paths ----------------------- @@ -372,7 +372,7 @@ You can also mix objects and arrays:: $accessor->setValue($person, 'children[0].firstName', 'Wouter'); // equal to $person->getChildren()[0]->firstName = 'Wouter' - echo 'Hello '.$accessor->getValue($person, 'children[0].firstName'); // 'Wouter' + dump('Hello '.$accessor->getValue($person, 'children[0].firstName')); // 'Wouter' // equal to $person->getChildren()[0]->firstName Enable other Features diff --git a/components/security/authorization.rst b/components/security/authorization.rst index c5b357e5118..e73bedf8c1c 100644 --- a/components/security/authorization.rst +++ b/components/security/authorization.rst @@ -186,8 +186,8 @@ first constructor argument:: $role = new Role('ROLE_ADMIN'); - // will echo 'ROLE_ADMIN' - echo $role->getRole(); + // will show 'ROLE_ADMIN' + dump($role->getRole()); .. note:: @@ -247,3 +247,4 @@ decision manager:: if (!$securityContext->isGranted('ROLE_ADMIN')) { throw new AccessDeniedException(); } + diff --git a/components/serializer.rst b/components/serializer.rst index 0d26457d0aa..329ffd038b5 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -330,7 +330,7 @@ having unique identifiers:: }); $serializer = new Serializer(array($normalizer), array($encoder)); - echo $serializer->serialize($org, 'json'); + dump($serializer->serialize($org, 'json')); // {"name":"Les-Tilleuls.coop","members":[{"name":"K\u00e9vin", organization: "Les-Tilleuls.coop"]} JMSSerializer diff --git a/components/translation/custom_formats.rst b/components/translation/custom_formats.rst index 4378d249f86..793d118c549 100644 --- a/components/translation/custom_formats.rst +++ b/components/translation/custom_formats.rst @@ -63,7 +63,7 @@ Once created, it can be used as any other loader:: $translator->addResource('my_format', __DIR__.'/translations/messages.txt', 'fr_FR'); - echo $translator->trans('welcome'); + dump($translator->trans('welcome')); It will print *"accueil"*. @@ -116,3 +116,4 @@ YAML file are dumped into a text file with the custom format:: $dumper = new MyFormatDumper(); $dumper->dump($catalogue, array('path' => __DIR__.'/dumps')); + diff --git a/components/translation/usage.rst b/components/translation/usage.rst index e6343c95f00..00d8968bf34 100644 --- a/components/translation/usage.rst +++ b/components/translation/usage.rst @@ -15,7 +15,7 @@ Imagine you want to translate the string *"Symfony is great"* into French:: 'Symfony is great!' => 'J\'aime Symfony!', ), 'fr_FR'); - echo $translator->trans('Symfony is great!'); + dump($translator->trans('Symfony is great!')); In this example, the message *"Symfony is great!"* will be translated into the locale set in the constructor (``fr_FR``) if the message exists in one of @@ -31,7 +31,7 @@ Sometimes, a message containing a variable needs to be translated:: // ... $translated = $translator->trans('Hello '.$name); - echo $translated; + dump($translated); However, creating a translation for this string is impossible since the translator will try to look up the exact message, including the variable portions @@ -45,7 +45,7 @@ variable with a "placeholder":: array('%name%' => $name) ); - echo $translated; + dump($translated); Symfony will now look for a translation of the raw message (``Hello %name%``) and *then* replace the placeholders with their values. Creating a translation @@ -392,3 +392,4 @@ The ``$messages`` variable will have the following structure:: 'Value is too long' => 'Valeur est trop long', ), ); + diff --git a/cookbook/bundles/remove.rst b/cookbook/bundles/remove.rst index f289ecd144c..9b005606d5e 100644 --- a/cookbook/bundles/remove.rst +++ b/cookbook/bundles/remove.rst @@ -79,7 +79,7 @@ can remove the ``Acme`` directory as well. :method:`Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface::getPath` method to get the path of the bundle:: - echo $this->container->get('kernel')->getBundle('AcmeDemoBundle')->getPath(); + dump($this->container->get('kernel')->getBundle('AcmeDemoBundle')->getPath()); 3.1 Remove Bundle Assets ~~~~~~~~~~~~~~~~~~~~~~~~ From fa00a5081d1e91a5115e984026af63578b8d1bd2 Mon Sep 17 00:00:00 2001 From: Henry Snoek Date: Sat, 23 May 2015 11:16:05 +0200 Subject: [PATCH 2/3] 5177 use dump() instead of print in examples --- components/class_loader/class_map_generator.rst | 2 +- components/css_selector.rst | 2 +- components/dom_crawler.rst | 2 +- components/finder.rst | 16 +++++++--------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/components/class_loader/class_map_generator.rst b/components/class_loader/class_map_generator.rst index d905c2b22e1..ab0537adb05 100644 --- a/components/class_loader/class_map_generator.rst +++ b/components/class_loader/class_map_generator.rst @@ -50,7 +50,7 @@ method:: use Symfony\Component\ClassLoader\ClassMapGenerator; - print_r(ClassMapGenerator::createMap(__DIR__.'/library')); + dump(ClassMapGenerator::createMap(__DIR__.'/library')); Given the files and class from the table above, you should see an output like this: diff --git a/components/css_selector.rst b/components/css_selector.rst index b62c58d94a3..67cf3965b15 100644 --- a/components/css_selector.rst +++ b/components/css_selector.rst @@ -49,7 +49,7 @@ equivalents:: use Symfony\Component\CssSelector\CssSelector; - print CssSelector::toXPath('div.item > h4 > a'); + dump(CssSelector::toXPath('div.item > h4 > a')); This gives the following output: diff --git a/components/dom_crawler.rst b/components/dom_crawler.rst index 37ef6e24827..6c2a8871595 100644 --- a/components/dom_crawler.rst +++ b/components/dom_crawler.rst @@ -45,7 +45,7 @@ traverse easily:: $crawler = new Crawler($html); foreach ($crawler as $domElement) { - print $domElement->nodeName; + dump($domElement->nodeName); } Specialized :class:`Symfony\\Component\\DomCrawler\\Link` and diff --git a/components/finder.rst b/components/finder.rst index 48a6c55a9b9..5e301b84562 100644 --- a/components/finder.rst +++ b/components/finder.rst @@ -28,14 +28,14 @@ directories:: $finder->files()->in(__DIR__); foreach ($finder as $file) { - // Print the absolute path - print $file->getRealpath()."\n"; + // Dump the absolute path + dump($file->getRealpath()); - // Print the relative path to the file, omitting the filename - print $file->getRelativePath()."\n"; + // Dump the relative path to the file, omitting the filename + dump($file->getRelativePath()); - // Print the relative path to the file - print $file->getRelativePathname()."\n"; + // Dump the relative path to the file + dump($file->getRelativePathname()); } The ``$file`` is an instance of :class:`Symfony\\Component\\Finder\\SplFileInfo` @@ -116,9 +116,7 @@ And it also works with user-defined streams:: $finder = new Finder(); $finder->name('photos*')->size('< 100K')->date('since 1 hour ago'); foreach ($finder->in('s3://bucket-name') as $file) { - // ... do something - - print $file->getFilename()."\n"; + // ... do something with the file } .. note:: From 3c3a0059512e4f1e83f528fee62093f426bd21e6 Mon Sep 17 00:00:00 2001 From: Henry Snoek Date: Sat, 23 May 2015 11:29:51 +0200 Subject: [PATCH 3/3] Merge branch '2.6' into 5177-change-echo-and-print-in-examples Conflicts: book/doctrine.rst components/event_dispatcher/introduction.rst components/serializer.rst --- book/doctrine.rst | 2 +- components/event_dispatcher/introduction.rst | 2 +- components/serializer.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/book/doctrine.rst b/book/doctrine.rst index 7ecd592ef63..5f842454f7c 100644 --- a/book/doctrine.rst +++ b/book/doctrine.rst @@ -1199,7 +1199,7 @@ to the given ``Category`` object via their ``category_id`` value. $category = $product->getCategory(); // prints "Proxies\AppBundleEntityCategoryProxy" - echo get_class($category); + dump(get_class($category)); This proxy object extends the true ``Category`` object, and looks and acts exactly like it. The difference is that, by using a proxy object, diff --git a/components/event_dispatcher/introduction.rst b/components/event_dispatcher/introduction.rst index a106834b965..c951c6f5016 100644 --- a/components/event_dispatcher/introduction.rst +++ b/components/event_dispatcher/introduction.rst @@ -636,7 +636,7 @@ dispatched, are passed as arguments to the listener:: { public function myEventListener(Event $event, $eventName, EventDispatcherInterface $dispatcher) { - echo $eventName; + // ... do something with the event name } } diff --git a/components/serializer.rst b/components/serializer.rst index 7a4bd7006a3..55f563f5314 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -358,7 +358,7 @@ having unique identifiers:: }); $serializer = new Serializer(array($normalizer), array($encoder)); - echo $serializer->serialize($org, 'json'); + dump($serializer->serialize($org, 'json')); // {"name":"Les-Tilleuls.coop","members":[{"name":"K\u00e9vin", organization: "Les-Tilleuls.coop"}]} JMSSerializer