Skip to content

Commit d0e4515

Browse files
Merge pull request #108 from renderforest/voiceover-project-data
voiceover-project-data
2 parents f4fc169 + bb601dc commit d0e4515

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ $projectDataInstance->setStyles($styles);
587587

588588
##### Set voice-over
589589

590+
In case if you want to unset `voiceover`, send empty array.
591+
590592
```php
591593
$voiceOver = [
592594
'path' => 'https://example.com/voice-ower.mp3' // optional

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "renderforest/sdk-php",
33
"description": "Renderforest SDK for PHP",
4-
"version": "0.3.5",
4+
"version": "0.3.6",
55
"homepage": "https://github.com/renderforest/renderforest-sdk-php",
66
"authors": [
77
{

src/ProjectData/ProjectData.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,39 @@ class ProjectData
2424
*/
2525
public function __construct($projectDataJson)
2626
{
27-
/**
28-
* Get SDK version from composer.json file and set it in generator`.
29-
*/
30-
$ComposerJson = json_decode(file_get_contents(dirname(__FILE__) . '/../../composer.json'), true);
31-
$sdkVersion = $ComposerJson['version'];
32-
$this->generator = "renderforest/sdk-node/$sdkVersion";
33-
34-
function objectToArray($objectToConvert)
35-
{
36-
if (is_object($objectToConvert)) {
37-
$objectToConvert = get_object_vars($objectToConvert);
38-
}
27+
$composer = file_get_contents(dirname(__FILE__) . '/../../composer.json');
28+
$composerJson = json_decode($composer, true);
29+
$sdkVersion = $composerJson['version'];
3930

40-
if (is_array($objectToConvert)) {
41-
return array_map(__FUNCTION__, $objectToConvert);
42-
} else {
43-
return $objectToConvert;
44-
}
45-
}
46-
$this->projectDataJson = objectToArray($projectDataJson);
47-
$this->projectDataUtil = new ProjectDataUtil();
31+
$this->generator = "renderforest/sdk-php/$sdkVersion";
4832
$this->patchProperties = [];
33+
$this->projectDataJson = $this->objectToArray($projectDataJson);
34+
$this->projectDataUtil = new ProjectDataUtil();
4935
$this->setGenerator();
5036
}
5137

5238
/**
53-
* @param $array
39+
* Converts `stdClass` object to array recursively.
40+
* @param \stdClass $objectToConvert
5441
* @return array
42+
*/
43+
private function objectToArray($objectToConvert)
44+
{
45+
if (is_object($objectToConvert)) {
46+
$objectToConvert = get_object_vars($objectToConvert);
47+
}
48+
49+
if (is_array($objectToConvert)) {
50+
return array_map([__CLASS__, __METHOD__], $objectToConvert);
51+
} else {
52+
return $objectToConvert;
53+
}
54+
}
55+
56+
/**
5557
* Checks if given array have `NULL` property then unset it, otherwise does noting.
58+
* @param $array - The data to unset `NULL` props.
59+
* @return array
5660
*/
5761
private function unsetNullProperties($array)
5862
{
@@ -75,8 +79,8 @@ private function setGenerator()
7579
}
7680

7781
/**
78-
* @return array
7982
* Get patch object.
83+
* @return array
8084
*/
8185
public function getPatchObject()
8286
{
@@ -258,6 +262,7 @@ public function getVoiceOver()
258262
*/
259263
public function setVoiceOver($voiceOver)
260264
{
265+
$voiceOver = (empty($voiceOver)) ? new \stdClass() : $voiceOver;
261266
$this->projectDataJson['data']['voiceOver'] = $voiceOver;
262267
array_push($this->patchProperties, 'voiceOver');
263268
}

src/ProjectData/ProjectDataUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function insertAndNormalizeOrder($screens, $newScreen)
8181
usort($screensWithNewScreen, $this->sortFactory('order'));
8282

8383
return array_map(
84-
array(new ProjectDataUtil(), 'normalizeOrders'),
84+
array(__CLASS__, 'normalizeOrders'),
8585
$screensWithNewScreen,
8686
array_keys($screensWithNewScreen)
8787
);

0 commit comments

Comments
 (0)