Skip to content

Commit

Permalink
Merge branch '2.0' into 2.1
Browse files Browse the repository at this point in the history
Conflicts:
	cookbook/testing/doctrine.rst
	cookbook/testing/profiling.rst
  • Loading branch information
weaverryan committed Dec 6, 2012
2 parents 760d20e + b1eb34a commit a03f06f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 33 deletions.
2 changes: 1 addition & 1 deletion book/translation.rst
Expand Up @@ -994,7 +994,7 @@ steps:
.. _`i18n`: http://en.wikipedia.org/wiki/Internationalization_and_localization .. _`i18n`: http://en.wikipedia.org/wiki/Internationalization_and_localization
.. _`L10n`: http://en.wikipedia.org/wiki/Internationalization_and_localization .. _`L10n`: http://en.wikipedia.org/wiki/Internationalization_and_localization
.. _`strtr function`: http://www.php.net/manual/en/function.strtr.php .. _`strtr function`: http://www.php.net/manual/en/function.strtr.php
.. _`ISO 31-11`: http://en.wikipedia.org/wiki/Interval_%28mathematics%29#The_ISO_notation .. _`ISO 31-11`: http://en.wikipedia.org/wiki/Interval_(mathematics)#Notations_for_intervals
.. _`Translatable Extension`: https://github.com/l3pp4rd/DoctrineExtensions .. _`Translatable Extension`: https://github.com/l3pp4rd/DoctrineExtensions
.. _`ISO3166 Alpha-2`: http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes .. _`ISO3166 Alpha-2`: http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
.. _`ISO639-1`: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes .. _`ISO639-1`: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
34 changes: 25 additions & 9 deletions cookbook/doctrine/file_uploads.rst
Expand Up @@ -55,23 +55,29 @@ First, create a simple Doctrine Entity class to work with::


public function getAbsolutePath() public function getAbsolutePath()
{ {
return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path; return null === $this->path
? null
: $this->getUploadRootDir().'/'.$this->path;
} }


public function getWebPath() public function getWebPath()
{ {
return null === $this->path ? null : $this->getUploadDir().'/'.$this->path; return null === $this->path
? null
: $this->getUploadDir().'/'.$this->path;
} }


protected function getUploadRootDir() protected function getUploadRootDir()
{ {
// the absolute directory path where uploaded documents should be saved // the absolute directory path where uploaded
// documents should be saved
return __DIR__.'/../../../../web/'.$this->getUploadDir(); return __DIR__.'/../../../../web/'.$this->getUploadDir();
} }


protected function getUploadDir() protected function getUploadDir()
{ {
// get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view. // get rid of the __DIR__ so it doesn't screw up
// when displaying uploaded doc/image in the view.
return 'uploads/documents'; return 'uploads/documents';
} }
} }
Expand Down Expand Up @@ -213,8 +219,12 @@ object, which is what's returned after a ``file`` field is submitted::
// use the original file name here but you should // use the original file name here but you should
// sanitize it at least to avoid any security issues // sanitize it at least to avoid any security issues


// move takes the target directory and then the target filename to move to // move takes the target directory and then the
$this->file->move($this->getUploadRootDir(), $this->file->getClientOriginalName()); // target filename to move to
$this->file->move(
$this->getUploadRootDir(),
$this->file->getClientOriginalName()
);


// set the path property to the filename where you've saved the file // set the path property to the filename where you've saved the file
$this->path = $this->file->getClientOriginalName(); $this->path = $this->file->getClientOriginalName();
Expand Down Expand Up @@ -266,7 +276,8 @@ Next, refactor the ``Document`` class to take advantage of these callbacks::
{ {
if (null !== $this->file) { if (null !== $this->file) {
// do whatever you want to generate a unique name // do whatever you want to generate a unique name
$this->path = sha1(uniqid(mt_rand(), true)).'.'.$this->file->guessExtension(); $filename = sha1(uniqid(mt_rand(), true));
$this->path = $filename.'.'.$this->file->guessExtension();
} }
} }


Expand Down Expand Up @@ -373,7 +384,10 @@ property, instead of the actual filename::
// you must throw an exception here if the file cannot be moved // you must throw an exception here if the file cannot be moved
// so that the entity is not persisted to the database // so that the entity is not persisted to the database
// which the UploadedFile move() method does // which the UploadedFile move() method does
$this->file->move($this->getUploadRootDir(), $this->id.'.'.$this->file->guessExtension()); $this->file->move(
$this->getUploadRootDir(),
$this->id.'.'.$this->file->guessExtension()
);


unset($this->file); unset($this->file);
} }
Expand All @@ -398,7 +412,9 @@ property, instead of the actual filename::


public function getAbsolutePath() public function getAbsolutePath()
{ {
return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->id.'.'.$this->path; return null === $this->path
? null
: $this->getUploadRootDir().'/'.$this->id.'.'.$this->path;
} }
} }


Expand Down
19 changes: 11 additions & 8 deletions cookbook/doctrine/multiple_entity_managers.rst
Expand Up @@ -64,7 +64,7 @@ two connections, one for each entity manager.


.. note:: .. note::


When working with multiple connections and entity managers, you should be When working with multiple connections and entity managers, you should be
explicit about which configuration you want. If you *do* omit the name of explicit about which configuration you want. If you *do* omit the name of
the connection or entity manager, the default (i.e. ``default``) is used. the connection or entity manager, the default (i.e. ``default``) is used.


Expand Down Expand Up @@ -98,7 +98,7 @@ the default entity manager (i.e. ``default``) is returned::
// both return the "default" em // both return the "default" em
$em = $this->get('doctrine')->getManager(); $em = $this->get('doctrine')->getManager();
$em = $this->get('doctrine')->getManager('default'); $em = $this->get('doctrine')->getManager('default');

$customerEm = $this->get('doctrine')->getManager('customer'); $customerEm = $this->get('doctrine')->getManager('customer');
} }
} }
Expand All @@ -115,17 +115,20 @@ The same applies to repository call::
{ {
// Retrieves a repository managed by the "default" em // Retrieves a repository managed by the "default" em
$products = $this->get('doctrine') $products = $this->get('doctrine')
->getRepository('AcmeStoreBundle:Product') ->getRepository('AcmeStoreBundle:Product')
->findAll(); ->findAll()
;


// Explicit way to deal with the "default" em // Explicit way to deal with the "default" em
$products = $this->get('doctrine') $products = $this->get('doctrine')
->getRepository('AcmeStoreBundle:Product', 'default') ->getRepository('AcmeStoreBundle:Product', 'default')
->findAll(); ->findAll()
;


// Retrieves a repository managed by the "customer" em // Retrieves a repository managed by the "customer" em
$customers = $this->get('doctrine') $customers = $this->get('doctrine')
->getRepository('AcmeCustomerBundle:Customer', 'customer') ->getRepository('AcmeCustomerBundle:Customer', 'customer')
->findAll(); ->findAll()
;
} }
} }
23 changes: 18 additions & 5 deletions cookbook/doctrine/registration_form.rst
Expand Up @@ -194,7 +194,11 @@ Next, create the form for this ``Registration`` model::
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder->add('user', new UserType()); $builder->add('user', new UserType());
$builder->add('terms', 'checkbox', array('property_path' => 'termsAccepted')); $builder->add(
'terms',
'checkbox',
array('property_path' => 'termsAccepted')
);
} }


public function getName() public function getName()
Expand Down Expand Up @@ -227,9 +231,15 @@ controller for displaying the registration form::
{ {
public function registerAction() public function registerAction()
{ {
$form = $this->createForm(new RegistrationType(), new Registration()); $form = $this->createForm(

new RegistrationType(),
return $this->render('AcmeAccountBundle:Account:register.html.twig', array('form' => $form->createView())); new Registration()
);

return $this->render(
'AcmeAccountBundle:Account:register.html.twig',
array('form' => $form->createView())
);
} }
} }


Expand Down Expand Up @@ -264,7 +274,10 @@ the validation and saves the data into the database::
return $this->redirect(...); return $this->redirect(...);
} }


return $this->render('AcmeAccountBundle:Account:register.html.twig', array('form' => $form->createView())); return $this->render(
'AcmeAccountBundle:Account:register.html.twig',
array('form' => $form->createView())
);
} }


That's it! Your form now validates, and allows you to save the ``User`` That's it! Your form now validates, and allows you to save the ``User``
Expand Down
13 changes: 9 additions & 4 deletions cookbook/email/dev_environment.rst
Expand Up @@ -96,7 +96,12 @@ Now, suppose you're sending an email to ``recipient@example.com``.
->setSubject('Hello Email') ->setSubject('Hello Email')
->setFrom('send@example.com') ->setFrom('send@example.com')
->setTo('recipient@example.com') ->setTo('recipient@example.com')
->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name))) ->setBody(
$this->renderView(
'HelloBundle:Hello:email.txt.twig',
array('name' => $name)
)
)
; ;
$this->get('mailer')->send($message); $this->get('mailer')->send($message);
Expand Down Expand Up @@ -150,10 +155,10 @@ you to open the report with details of the sent emails.
<!-- app/config/config_dev.xml --> <!-- app/config/config_dev.xml -->
<!-- <!--
xmlns:webprofiler="http://symfony.com/schema/dic/webprofiler" xmlns:webprofiler="http://symfony.com/schema/dic/webprofiler"
xsi:schemaLocation="http://symfony.com/schema/dic/webprofiler xsi:schemaLocation="http://symfony.com/schema/dic/webprofiler
http://symfony.com/schema/dic/webprofiler/webprofiler-1.0.xsd"> http://symfony.com/schema/dic/webprofiler/webprofiler-1.0.xsd">
--> -->
<webprofiler:config <webprofiler:config
Expand Down
7 changes: 6 additions & 1 deletion cookbook/email/email.rst
Expand Up @@ -106,7 +106,12 @@ an email is pretty straightforward::
->setSubject('Hello Email') ->setSubject('Hello Email')
->setFrom('send@example.com') ->setFrom('send@example.com')
->setTo('recipient@example.com') ->setTo('recipient@example.com')
->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name))) ->setBody(
$this->renderView(
'HelloBundle:Hello:email.txt.twig',
array('name' => $name)
)
)
; ;
$this->get('mailer')->send($message); $this->get('mailer')->send($message);


Expand Down
4 changes: 3 additions & 1 deletion cookbook/form/form_collections.rst
Expand Up @@ -607,7 +607,9 @@ the relationship between the removed ``Tag`` and ``Task`` object.
$originalTags = array(); $originalTags = array();


// Create an array of the current Tag objects in the database // Create an array of the current Tag objects in the database
foreach ($task->getTags() as $tag) $originalTags[] = $tag; foreach ($task->getTags() as $tag) {
$originalTags[] = $tag;
}


$editForm = $this->createForm(new TaskType(), $task); $editForm = $this->createForm(new TaskType(), $task);


Expand Down
5 changes: 4 additions & 1 deletion cookbook/testing/doctrine.rst
Expand Up @@ -39,7 +39,10 @@ which makes all of this quite easy::
{ {
static::$kernel = static::createKernel(); static::$kernel = static::createKernel();
static::$kernel->boot(); static::$kernel->boot();
$this->em = static::$kernel->getContainer()->get('doctrine')->getManager(); $this->em = static::$kernel->getContainer()
->get('doctrine')
->getManager()
;
} }


public function testSearchByCategoryName() public function testSearchByCategoryName()
Expand Down
15 changes: 12 additions & 3 deletions cookbook/testing/profiling.rst
Expand Up @@ -27,10 +27,16 @@ environment)::
// Check that the profiler is enabled // Check that the profiler is enabled
if ($profile = $client->getProfile()) { if ($profile = $client->getProfile()) {
// check the number of requests // check the number of requests
$this->assertLessThan(10, $profile->getCollector('db')->getQueryCount()); $this->assertLessThan(
10,
$profile->getCollector('db')->getQueryCount()
);


// check the time spent in the framework // check the time spent in the framework
$this->assertLessThan(500, $profile->getCollector('time')->getTotalTime()); $this->assertLessThan(
500,
$profile->getCollector('time')->getTotalTime()
);
} }
} }
} }
Expand All @@ -42,7 +48,10 @@ finish. It's easy to achieve if you embed the token in the error message::
$this->assertLessThan( $this->assertLessThan(
30, 30,
$profile->get('db')->getQueryCount(), $profile->get('db')->getQueryCount(),
sprintf('Checks that query count is less than 30 (token %s)', $profile->getToken()) sprintf(
'Checks that query count is less than 30 (token %s)',
$profile->getToken()
)
); );


.. caution:: .. caution::
Expand Down

0 comments on commit a03f06f

Please sign in to comment.