Skip to content

Commit d7fefc0

Browse files
author
Luca Bruno
committed
v2.9.2
Summary: new release Test Plan: ./vendor/bin/phpunit -c test/phpunit-travis.xml
1 parent 7910756 commit d7fefc0

File tree

6 files changed

+196
-6
lines changed

6 files changed

+196
-6
lines changed

src/FacebookAds/ApiConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
namespace FacebookAds;
2525
class ApiConfig {
2626
const APIVersion = '2.9';
27-
const SDKVersion = '2.9.1';
27+
const SDKVersion = '2.9.2';
2828
const TYPE_CHECKER_STRICT_MODE = false;
2929
}

src/FacebookAds/Http/Adapter/Curl/Curl.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
namespace FacebookAds\Http\Adapter\Curl;
2626

27+
use FacebookAds\Http\FileParameter;
28+
2729
class Curl extends AbstractCurl {
2830

2931
/**
@@ -53,11 +55,24 @@ public function pause($bitmask) {
5355
}
5456

5557
/**
56-
* @param string $filepath
58+
* FIXME should introduce v2.10 breaking change:
59+
* implement abstract support for FileParameter in AdapterInterface
60+
*
61+
* @param string|FileParameter $filepath
5762
* @return string
5863
*/
5964
public function preparePostFileField($filepath) {
60-
return "@".$filepath;
65+
$mime_type = $name = '';
66+
if ($filepath instanceof FileParameter) {
67+
$mime_type = $filepath->getMimeType() !== null
68+
? sprintf(';type=%s', $filepath->getMimeType())
69+
: '';
70+
$name = $filepath->getName() !== null
71+
? sprintf(';filename=%s', $filepath->getName())
72+
: '';
73+
$filepath = $filepath->getPath();
74+
}
75+
return sprintf('@%s%s%s', $filepath, $mime_type, $name);
6176
}
6277

6378
/**

src/FacebookAds/Http/Adapter/Curl/Curl55.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
namespace FacebookAds\Http\Adapter\Curl;
2626

27+
use FacebookAds\Http\FileParameter;
28+
2729
class Curl55 extends AbstractCurl {
2830

2931
/**
@@ -53,11 +55,20 @@ public function pause($bitmask) {
5355
}
5456

5557
/**
56-
* @param string $filepath
58+
* FIXME should introduce v2.10 breaking change:
59+
* implement abstract support for FileParameter in AdapterInterface
60+
*
61+
* @param string|FileParameter $filepath
5762
* @return \CURLFile
5863
*/
5964
public function preparePostFileField($filepath) {
60-
return new \CURLFile($filepath);
65+
$mime_type = $name = ''; // can't be null in HHVM
66+
if ($filepath instanceof FileParameter) {
67+
$mime_type = $filepath->getMimeType() ?: '';
68+
$name = $filepath->getName() ?: '';
69+
$filepath = $filepath->getPath();
70+
}
71+
return new \CURLFile($filepath, $mime_type, $name);
6172
}
6273

6374
/**
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
4+
*
5+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
6+
* use, copy, modify, and distribute this software in source code or binary
7+
* form for use in connection with the web services and APIs provided by
8+
* Facebook.
9+
*
10+
* As with any software that integrates with the Facebook platform, your use
11+
* of this software is subject to the Facebook Developer Principles and
12+
* Policies [http://developers.facebook.com/policy/]. This copyright notice
13+
* shall be included in all copies or substantial portions of the software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
25+
namespace FacebookAds\Http;
26+
27+
class FileParameter {
28+
29+
/**
30+
* @var string
31+
*/
32+
protected $path;
33+
34+
/**
35+
* @var string|null
36+
*/
37+
protected $mimeType;
38+
39+
/**
40+
* @var string|null
41+
*/
42+
protected $name;
43+
44+
/**
45+
* @param string $path
46+
*/
47+
public function __construct($path) {
48+
$this->path = $path;
49+
}
50+
51+
/**
52+
* @return string
53+
*/
54+
public function getPath() {
55+
return $this->path;
56+
}
57+
58+
/**
59+
* @return null|string
60+
*/
61+
public function getMimeType() {
62+
return $this->mimeType;
63+
}
64+
65+
/**
66+
* @param null|string $mime_type
67+
* @return $this
68+
*/
69+
public function setMimeType($mime_type) {
70+
$this->mimeType = $mime_type;
71+
return $this;
72+
}
73+
74+
/**
75+
* @return null|string
76+
*/
77+
public function getName() {
78+
return $this->name;
79+
}
80+
81+
/**
82+
* @param null|string $name
83+
* @return $this
84+
*/
85+
public function setName($name) {
86+
$this->name = $name;
87+
return $this;
88+
}
89+
}

src/FacebookAds/Object/AbstractCrudObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function getChangedFields() {
163163
public function exportData() {
164164
$data = array();
165165
foreach ($this->changedFields as $key => $val) {
166-
$data[$key] = $val instanceof AbstractObject ? $val->exportData() : $val;
166+
$data[$key] = parent::exportValue($val);
167167
}
168168
return $data;
169169
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
4+
*
5+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
6+
* use, copy, modify, and distribute this software in source code or binary
7+
* form for use in connection with the web services and APIs provided by
8+
* Facebook.
9+
*
10+
* As with any software that integrates with the Facebook platform, your use
11+
* of this software is subject to the Facebook Developer Principles and
12+
* Policies [http://developers.facebook.com/policy/]. This copyright notice
13+
* shall be included in all copies or substantial portions of the software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
25+
namespace FacebookAdsTest\Http;
26+
27+
use FacebookAds\Http\Adapter\Curl\AbstractCurl;
28+
use FacebookAds\Http\FileParameter;
29+
use FacebookAdsTest\AbstractUnitTestCase;
30+
31+
class FileParameterTest extends AbstractUnitTestCase {
32+
33+
public function argumentsProvider() {
34+
return array(
35+
array('PATH', 'NAME', 'MIME_TYPE'),
36+
array('PATH', 'NAME', null),
37+
array('PATH', 'NAME'),
38+
array('PATH', null, null),
39+
array('PATH'),
40+
);
41+
}
42+
43+
/**
44+
* @dataProvider argumentsProvider
45+
* @param string $path
46+
* @param string|null $name
47+
* @param string|null $mime_type
48+
*/
49+
public function testGetters($path, $name = null, $mime_type = null) {
50+
$param = (new FileParameter($path))
51+
->setName($name)
52+
->setMimeType($mime_type);
53+
54+
$this->assertEquals($param->getPath(), $path);
55+
$this->assertEquals($param->getName(), $name);
56+
$this->assertEquals($param->getMimeType(), $mime_type);
57+
}
58+
59+
/**
60+
* @dataProvider argumentsProvider
61+
* @param string $path
62+
* @param string|null $name
63+
* @param string|null $mime_type
64+
*/
65+
public function testCurlImplementation(
66+
$path,
67+
$name = null,
68+
$mime_type = null) {
69+
$param = (new FileParameter($path))
70+
->setName($name)
71+
->setMimeType($mime_type);
72+
73+
AbstractCurl::createOptimalVersion()->preparePostFileField($param);
74+
}
75+
}

0 commit comments

Comments
 (0)