|
1 | 1 | <?php |
2 | 2 |
|
3 | | -/* |
4 | | -
|
5 | | - JSON2Video PHP SDK |
6 | | -
|
7 | | - This simple SDK is a wrapper for calling JSON2Video API |
8 | | - JSON2Video API allows you to create and edit videos programmatically |
9 | | -
|
10 | | - Documentation: https://json2video.com/docs/sdk |
11 | | -
|
12 | | -*/ |
13 | | - |
14 | 3 | namespace JSON2Video; |
15 | 4 |
|
16 | | -class Base { |
17 | | - |
18 | | - protected $object, $properties; |
19 | | - |
20 | | - public function __get($property) { |
21 | | - $property = strtolower($property); |
22 | | - if (in_array($property, $this->properties) && isset($this->object[$property])) { |
23 | | - return $this->object[$property]; |
24 | | - } |
25 | | - |
26 | | - return null; |
27 | | - } |
28 | | - |
29 | | - public function __set($property, $value) { |
30 | | - $property = strtolower($property); |
31 | | - if (in_array($property, $this->properties)) { |
32 | | - $property = strtolower(str_replace('_', '-', $property)); |
33 | | - $this->object[$property] = $value; |
34 | | - return $value; |
35 | | - } |
36 | | - |
37 | | - return null; |
38 | | - } |
39 | | - |
40 | | - public function addElement($element=null) { |
41 | | - if ($element && is_array($element)) { |
42 | | - if (!isset($this->object['elements'])) $this->object['elements'] = []; |
43 | | - $this->object['elements'][] = $element; |
44 | | - return true; |
45 | | - } |
46 | | - return false; |
47 | | - } |
48 | | - |
49 | | - public function getJSON() { |
50 | | - return json_encode($this->object, JSON_PRETTY_PRINT); |
51 | | - } |
52 | | - |
53 | | - public function getObject() { |
54 | | - return $this->object; |
55 | | - } |
56 | | -} |
57 | | - |
58 | | - |
59 | | -class Scene extends Base { |
60 | | - protected $properties = ['comment', 'background_color', 'duration', 'cache']; |
61 | | - |
62 | | - protected $object = []; |
63 | | - |
64 | | - public function setTransition($style=null, $duration=null, $type=null) { |
65 | | - if ($style || $duration || $type) { |
66 | | - if (!isset($this->object['transition'])) $this->object['transition'] = []; |
67 | | - if (!is_null($style)) $this->object['transition']['style'] = $style; |
68 | | - if (!is_null($duration)) $this->object['transition']['duration'] = $duration; |
69 | | - if (!is_null($type)) $this->object['transition']['type'] = $type; |
70 | | - } |
71 | | - } |
72 | | - |
73 | | -} |
74 | | - |
75 | 5 | class Movie extends Base { |
76 | 6 | private $api_url = 'https://api.json2video.com/v1/movies'; |
77 | 7 | protected $properties = ['comment', 'project', 'width', 'height', 'resolution', 'quality', 'fps', 'cache']; |
|
0 commit comments