-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add browserkit component documentation #6072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
93d7258
645d50d
9c007e9
1e5ca13
f0f8a50
b3d9eb3
6997c4f
94bb3bf
dda78ba
74cfecd
a3d158e
6b6e23a
ea3fd71
a1df783
03ea5a5
883c062
fd35c93
5aec7c4
e7056a8
c9093a8
3f0858f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,96 @@ You can get the form object by using the crawler to select the button and runnin | |
Cookies | ||
------- | ||
|
||
Retreiving Cookies | ||
~~~~~~~~~~~~~~~~~~ | ||
|
||
The Crawler has a cookieJar which is a container for storing and recieving cookies. | ||
|
||
.. code-block:: php | ||
|
||
use ACME\Client; | ||
|
||
// Make a request | ||
$client = new Client(); | ||
$crawler = $client->request('GET', 'http://symfony.com'); | ||
|
||
// Get the cookie Jar | ||
$cookieJar = $crawler->getCookieJar(); | ||
|
||
// Get a cookie by name | ||
$flavor = $cookieJar->get('flavor'); | ||
|
||
// Get cookie data | ||
$name = $flavor->getName(); | ||
$value = $flavor->getValue(); | ||
$raw = $flavor->getRawValue(); | ||
$secure = $flavor->isSecure(); | ||
$isHttpOnly = $flavor->isHttpOnly(); | ||
$isExpired = $flavor->isExpired(); | ||
$expires = $flavor->getExpiresTime(); | ||
$path = $flavor->getPath(); | ||
$domain = $flavor->getDomain(); | ||
|
||
Looping Through Cookies | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. code-block:: php | ||
|
||
use ACME\Client; | ||
|
||
// Make a request | ||
$client = new Client(); | ||
$crawler = $client->request('GET', 'http://symfony.com'); | ||
|
||
// Get the cookie Jar | ||
$cookieJar = $crawler->getCookieJar(); | ||
|
||
// Get array with all cookies | ||
$cookies = $cookieJar->all(); | ||
foreach($cookies as $cookie) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Symfony CS: put |
||
// ... | ||
} | ||
|
||
// Get all values | ||
$values = $cookieJar->allValues('http://symfony.com'); | ||
foreach($values as $value) | ||
{ | ||
// ... | ||
} | ||
|
||
// Get all raw values | ||
$rawValues = $cookieJar->allRawValues('http://symfony.com'); | ||
foreach($rawValues as $rawValue) | ||
{ | ||
// ... | ||
} | ||
|
||
.. note:: | ||
These cookie jar methods only return cookies that have not expired. | ||
|
||
Setting Cookies | ||
~~~~~~~~~~~~~~~ | ||
|
||
You can define create cookies and add them to a cookie jar that can be injected it into the client constructor. | ||
|
||
.. code-block:: php | ||
|
||
use ACME\Client; | ||
|
||
// create cookies and add to cookie jar | ||
$expires = new \DateTime(); | ||
$expires->add(new \DateInterval('P1D')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not |
||
$cookie = new Cookie( | ||
'flavor', | ||
'chocolate chip', | ||
$now->getTimestamp() | ||
); | ||
|
||
// create a client and set the cookies | ||
$client = new Client(array(), array(), $cookieJar); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undefined variable |
||
// ... | ||
|
||
History | ||
------- | ||
|
||
|
@@ -138,8 +228,6 @@ You can restart the clients history with the restart method. This will also clea | |
// restart history | ||
$client->restart(); | ||
|
||
Insulated Request | ||
----------------- | ||
|
||
.. _Packagist: https://packagist.org/packages/symfony/browser-kit | ||
.. _Goutte: https://github.com/fabpot/Goutte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No text, devs will probably like this 😉 . I'm not sure about it though