-
Notifications
You must be signed in to change notification settings - Fork 2k
Add full batch support without BC breaks #713
Conversation
4257f97
to
c1cc66a
Compare
* | ||
* @param FacebookRequest|array $request | ||
* @param string|null $name | ||
* @param string|null|array $optionsOrName When it is a string it is the name of the request |
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.
I'd name it just $options
and describe it like "array of batch request options (e.g. ...). If a string is given, it will be the value of the name
option." or something like that :)
return $this; | ||
} | ||
|
||
if (null === $optionsOrName) { |
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.
you must check for this one before !is_array($optionsOrName)
. Currently you will never enter this case
@@ -85,17 +87,35 @@ public function add($request, $name = null) | |||
throw new \InvalidArgumentException('Argument for add() must be of type array or FacebookRequest.'); | |||
} | |||
|
|||
if (!is_array($optionsOrName)) { | |||
$this->add($request, ['name' => $optionsOrName]); |
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.
I'd just change the $options
value here: $options = ['name' => $options];
} | ||
|
||
if (null === $optionsOrName) { | ||
$this->add($request, []); |
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.
I'd just change the $options
value here: $options = [];
* @param string|null $requestName The name of the request. | ||
* @param string|null $attachedFiles Names of files associated with the request. | ||
* @param FacebookRequest $request The request entity to convert. | ||
* @param string|null|array $requestNameOrOptions If it is a string it is the name of the request |
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.
same here, $options
is enough
return $this->requestEntityToBatchArray($request, ['name' => $requestNameOrOptions], $attachedFiles); | ||
} | ||
|
||
if (null === $requestNameOrOptions) { |
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.
same here, check for this one before !is_array(...)
{ | ||
|
||
if (!is_array($requestNameOrOptions)) { | ||
return $this->requestEntityToBatchArray($request, ['name' => $requestNameOrOptions], $attachedFiles); |
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.
same here, just change the $options
value
} | ||
|
||
if (null === $requestNameOrOptions) { | ||
return $this->requestEntityToBatchArray($request, [], $attachedFiles); |
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.
same here, just change the $options
value
c1cc66a
to
1be7009
Compare
I made the changes :) @yguedidi |
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.
I'd add a testBatchRequestsWithNameGetConvertedToAnArray
test :)
I think you can add the doc now! Thanks
* @param FacebookRequest $request The request entity to convert. | ||
* @param string|null|array $options Array of batch request options e.g. 'name', 'omit_response_on_success'. | ||
* If a string is given, it is the value of the 'name' option. | ||
* @param string|null $attachedFiles Names of files associated with the request. |
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.
extra spaces, each "column" should be separated by only one space :)
$options = []; | ||
} | ||
|
||
if (!is_array($options)) { |
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.
I'd use elseif
here to avoid this if in case $options
was null
and it become an empty array
@yguedidi Don't these two tests (and a few others)
|
@teldosas right! :) |
1be7009
to
f9e7d99
Compare
@yguedidi Ok then I made the last changes too. I'll add the docs asap :) |
17c5bb4
to
f319b4c
Compare
@yguedidi I added the docs. It should be ready now :) |
|
||
```php | ||
$fb = new Facebook\Facebook([ | ||
'app_id' => '{app-id}', |
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.
The indentation here and in the other PHP code examples in this file seems to be off, can we consistently use PSR-2 here instead and indent with 4 spaces?
f319b4c
to
217daea
Compare
I fixed the spaces in the examples too @localheinz |
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.
@yguedidi It's been my pleasure 😄 Now that I think of it again couldn't we have just overloaded the |
Sounds good! I'll try to give this a more detailed look tomorrow. I'm curious about the status of #706. I might be able to cherry-pick this one over to master and we could create a new PR with the cleaner API for v6. Thoughts? :) |
```php | ||
<?php | ||
$fb = new Facebook\Facebook([ | ||
'app_id' => '{app-id}', |
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.
Indentation is still off, can we adjust?
```php | ||
<?php | ||
$fb = new Facebook\Facebook([ | ||
'app_id' => '{app-id}', |
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.
Indentation is still off, can we adjust?
## newBatchRequest() | ||
```php | ||
public Facebook\FacebookBatchRequest newBatchRequest( | ||
string|AccessToken|null $accessToken, |
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.
Indentation is still off, can we adjust?
@@ -62,12 +63,12 @@ Since the `Facebook\FacebookBatchRequest` is extended from the [`Facebook\Facebo | |||
```php | |||
public add( | |||
array|Facebook\FacebookBatchRequest $request, |
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.
Indentation is still off, can we adjust?
217daea
to
4980f3a
Compare
@localheinz done! |
Thanks so much for your hard work on this @teldosas! Feel free to send a new PR to the master branch with this feature without worrying about BC if you want to. :) |
I made an initial attempt to add full batch support without the BC breaks that #706 introduced. Awaiting review @yguedidi @SammyK . :) I will adjust the docs too in the following days. :)