Skip to content

Commit 928f36b

Browse files
author
Volkan Akbulut
committed
use namesapce
1 parent e2604c4 commit 928f36b

22 files changed

+386
-434
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
test.php
22
build_docs.sh
33
.DS_Store
4-
4+
.idea

Services/Zencoder.php

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
* @link http://github.com/zencoder/zencoder-php
1111
* @access private
1212
*/
13+
namespace Zencoder\Services;
1314

14-
function Services_Zencoder_autoload($className)
15-
{
16-
if (substr($className, 0, 17) != 'Services_Zencoder') {return false;}
17-
$file = str_replace('_', '/', $className);
18-
$file = str_replace('Services/', '', $file);
19-
return include dirname(__FILE__) . "/$file.php";
20-
}
21-
spl_autoload_register('Services_Zencoder_autoload');
15+
use Zencoder\Services\Zencoder\Accounts;
16+
use Zencoder\Services\Zencoder\Base;
17+
use Zencoder\Services\Zencoder\Http;
18+
use Zencoder\Services\Zencoder\Inputs;
19+
use Zencoder\Services\Zencoder\Jobs;
20+
use Zencoder\Services\Zencoder\Notifications;
21+
use Zencoder\Services\Zencoder\Outputs;
2222

2323
/**
2424
* Zencoder API client interface.
@@ -31,14 +31,14 @@ function Services_Zencoder_autoload($className)
3131
* @link http://github.com/zencoder/zencoder-php
3232
*/
3333

34-
class Services_Zencoder extends Services_Zencoder_Base
34+
class Zencoder extends Base
3535
{
3636
const USER_AGENT = 'ZencoderPHP v2.2.3';
3737

3838
/**
3939
* Contains the HTTP communication class
4040
*
41-
* @var Services_Zencoder_Http
41+
* @var Http
4242
*/
4343
protected $http;
4444
/**
@@ -53,39 +53,39 @@ class Services_Zencoder extends Services_Zencoder_Base
5353
*
5454
* Valid functions: create, details, integration, live
5555
*
56-
* @var Services_Zencoder_Accounts
56+
* @var Accounts
5757
*/
5858
public $accounts;
5959
/**
6060
* Provides access the Zencoder Inputs API
6161
*
6262
* Valid functions: details, progress
6363
*
64-
* @var Services_Zencoder_Inputs
64+
* @var Inputs
6565
*/
6666
public $inputs;
6767
/**
6868
* Provides access the Zencoder Jobs API
6969
*
7070
* Valid functions: create, index, details, progress, resubmit, cancel
7171
*
72-
* @var Services_Zencoder_Jobs
72+
* @var Jobs
7373
*/
7474
public $jobs;
7575
/**
7676
* Provides access the Zencoder Notifications API
7777
*
7878
* Valid functions: parseIncoming
7979
*
80-
* @var Services_Zencoder_Notifications
80+
* @var Notifications
8181
*/
8282
public $notifications;
8383
/**
8484
* Provides access the Zencoder Outputs API
8585
*
8686
* Valid functions: details, progress
8787
*
88-
* @var Services_Zencoder_Outputs
88+
* @var Outputs
8989
*/
9090
public $outputs;
9191

@@ -110,13 +110,13 @@ public function __construct(
110110
{
111111
// Check that library dependencies are met
112112
if (strnatcmp(phpversion(),'5.2.0') < 0) {
113-
throw new Services_Zencoder_Exception('PHP version 5.2 or higher is required.');
113+
throw new \Exception('PHP version 5.2 or higher is required.');
114114
}
115115
if (!function_exists('json_encode')) {
116-
throw new Services_Zencoder_Exception('JSON support must be enabled.');
116+
throw new \Exception('JSON support must be enabled.');
117117
}
118118
if (!function_exists('curl_init')) {
119-
throw new Services_Zencoder_Exception('cURL extension must be enabled.');
119+
throw new \Exception('cURL extension must be enabled.');
120120
}
121121

122122
$this->version = $api_version;
@@ -129,12 +129,14 @@ public function __construct(
129129
$http_options["curlopts"][CURLOPT_CAINFO] = realpath($ca_file);
130130
}
131131

132-
$this->http = new Services_Zencoder_Http($api_host, $http_options);
133-
$this->accounts = new Services_Zencoder_Accounts($this);
134-
$this->inputs = new Services_Zencoder_Inputs($this);
135-
$this->jobs = new Services_Zencoder_Jobs($this);
136-
$this->notifications = new Services_Zencoder_Notifications($this);
137-
$this->outputs = new Services_Zencoder_Outputs($this);
132+
$this->http = new Http($api_host, $http_options);
133+
$this->accounts = new Accounts($this);
134+
$this->inputs = new Inputs($this);
135+
$this->jobs = new Jobs($this);
136+
$this->notifications = new Notifications($this);
137+
$this->outputs = new Outputs($this);
138+
139+
parent::__construct($this);
138140
}
139141

140142
/**
@@ -232,16 +234,16 @@ private function _processResponse($response)
232234
return TRUE;
233235
}
234236
if (empty($headers['Content-Type'])) {
235-
throw new Services_Zencoder_Exception('Response header is missing Content-Type', $body);
237+
throw new \Exception('Response header is missing Content-Type', $body);
236238
}
237239
switch ($headers['Content-Type']) {
238240
case 'application/json':
239241
case 'application/json; charset=utf-8':
240242
return $this->_processJsonResponse($status, $headers, $body);
241243
break;
242244
}
243-
throw new Services_Zencoder_Exception(
244-
'Unexpected content type: ' . $headers['Content-Type'], $body);
245+
throw new \Exception(
246+
'Unexpected content type: ' . $headers['Content-Type']);
245247
}
246248

247249
private function _processJsonResponse($status, $headers, $body)
@@ -250,8 +252,8 @@ private function _processJsonResponse($status, $headers, $body)
250252
if ($status >= 200 && $status < 300) {
251253
return $decoded;
252254
}
253-
throw new Services_Zencoder_Exception(
254-
"Invalid HTTP status code: " . $status, $body
255+
throw new \Exception(
256+
"Invalid HTTP status code: " . $status
255257
);
256258
}
257259
}

Services/Zencoder/Account.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* @link http://github.com/zencoder/zencoder-php
1111
*/
1212

13-
class Services_Zencoder_Account extends Services_Zencoder_Object
13+
namespace Zencoder\Services\Zencoder;
14+
15+
class Account extends Object
1416
{
1517
}

Services/Zencoder/Accounts.php

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,63 @@
11
<?php
2-
/**
3-
* Zencoder API client interface.
4-
*
5-
* @category Services
6-
* @package Services_Zencoder
7-
* @author Michael Christopher <m@zencoder.com>
8-
* @version Release: 2.1.2
9-
* @license http://creativecommons.org/licenses/MIT/MIT
10-
* @link http://github.com/zencoder/zencoder-php
11-
*/
122

13-
class Services_Zencoder_Accounts extends Services_Zencoder_Base
3+
namespace Zencoder\Services\Zencoder;
4+
5+
class Accounts extends Base
146
{
15-
/**
16-
* Create a Zencoder account
17-
*
18-
* @param array $account Array of attributes to use when creating the account
19-
* @param array $params Optional overrides
20-
*
21-
* @return Services_Zencoder_Account The object representation of the resource
22-
*/
23-
public function create($account = NULL, $params = array()) {
24-
if(is_string($account)) {
25-
$json = trim($account);
26-
} else if(is_array($account)) {
27-
$json = json_encode($account);
28-
} else {
29-
throw new Services_Zencoder_Exception(
30-
'Account parameters required to create account.');
7+
/**
8+
* Create a Zencoder account.
9+
*
10+
* @param array $account Array of attributes to use when creating the account
11+
* @param array $params Optional overrides
12+
*
13+
* @return Account The object representation of the resource
14+
*/
15+
public function create($account = null, $params = [])
16+
{
17+
if (is_string($account)) {
18+
$json = trim($account);
19+
} elseif (is_array($account)) {
20+
$json = json_encode($account);
21+
} else {
22+
throw new \Exception('Account parameters required to create account.');
23+
}
24+
25+
return new Account($this->proxy->createData('account', $json, $params));
3126
}
32-
return new Services_Zencoder_Account($this->proxy->createData("account", $json, $params));
33-
}
3427

35-
/**
36-
* Return details of your Zencoder account
37-
*
38-
* @param array $params Optional overrides
39-
*
40-
* @return Services_Zencoder_Account The object representation of the resource
41-
*/
42-
public function details($params = array()) {
43-
return new Services_Zencoder_Account($this->proxy->retrieveData("account.json", array(), $params));
44-
}
28+
/**
29+
* Return details of your Zencoder account.
30+
*
31+
* @param array $params Optional overrides
32+
*
33+
* @return Account The object representation of the resource
34+
*/
35+
public function details($params = [])
36+
{
37+
return new Account($this->proxy->retrieveData('account.json', [], $params));
38+
}
4539

46-
/**
47-
* Put your account into integration mode
48-
*
49-
* @param array $params Optional overrides
50-
*
51-
* @return bool If the operation was successful
52-
*/
53-
public function integration($params = array()) {
54-
return $this->proxy->updateData("account/integration", "", $params);
55-
}
40+
/**
41+
* Put your account into integration mode.
42+
*
43+
* @param array $params Optional overrides
44+
*
45+
* @return bool If the operation was successful
46+
*/
47+
public function integration($params = [])
48+
{
49+
return $this->proxy->updateData('account/integration', '', $params);
50+
}
5651

57-
/**
58-
* Put your account into live mode
59-
*
60-
* @param array $params Optional overrides
61-
*
62-
* @return bool If the operation was successful
63-
*/
64-
public function live($params = array()) {
65-
return $this->proxy->updateData("account/live", "", $params);
66-
}
52+
/**
53+
* Put your account into live mode.
54+
*
55+
* @param array $params Optional overrides
56+
*
57+
* @return bool If the operation was successful
58+
*/
59+
public function live($params = [])
60+
{
61+
return $this->proxy->updateData('account/live', '', $params);
62+
}
6763
}

Services/Zencoder/Base.php

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,33 @@
11
<?php
2-
/**
3-
* Zencoder API client interface.
4-
*
5-
* @category Services
6-
* @package Services_Zencoder
7-
* @author Michael Christopher <m@zencoder.com>
8-
* @version Release: 2.1.2
9-
* @license http://creativecommons.org/licenses/MIT/MIT
10-
* @link http://github.com/zencoder/zencoder-php
11-
*/
122

13-
abstract class Services_Zencoder_Base
14-
implements Services_Zencoder_HttpProxy
15-
{
3+
namespace Zencoder\Services\Zencoder;
164

17-
protected $proxy;
5+
abstract class Base implements HttpProxy
6+
{
7+
protected $proxy;
188

19-
public function __construct(Services_Zencoder_HttpProxy $proxy)
20-
{
21-
$this->proxy = $proxy;
22-
}
9+
public function __construct(HttpProxy $proxy)
10+
{
11+
$this->proxy = $proxy;
12+
}
2313

24-
public function createData($path, $body = "", array $opts = array())
25-
{
26-
return $this->proxy->createData($path, $body, $opts);
27-
}
14+
public function createData($path, $body = '', array $opts = [])
15+
{
16+
return $this->proxy->createData($path, $body, $opts);
17+
}
2818

29-
public function retrieveData($path, array $params = array(), array $opts = array())
30-
{
31-
return $this->proxy->retrieveData($path, $params, $opts);
32-
}
19+
public function retrieveData($path, array $params = [], array $opts = [])
20+
{
21+
return $this->proxy->retrieveData($path, $params, $opts);
22+
}
3323

34-
public function updateData($path, $body = "", array $opts = array())
35-
{
36-
return $this->proxy->updateData($path, $body, $opts);
37-
}
24+
public function updateData($path, $body = '', array $opts = [])
25+
{
26+
return $this->proxy->updateData($path, $body, $opts);
27+
}
3828

39-
public function deleteData($path, array $opts = array())
40-
{
41-
return $this->proxy->deleteData($path, $opts);
42-
}
29+
public function deleteData($path, array $opts = [])
30+
{
31+
return $this->proxy->deleteData($path, $opts);
32+
}
4333
}

Services/Zencoder/Error.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)