Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update deprecated preg_replace call, remove PHP closing tags #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Mogreet.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Mogreet
private $token;
private $defaultFormat;

public function __construct($clientId, $token)
public function __construct($clientId, $token)
{
$this->clientId = $clientId;
$this->token = $token;
Expand All @@ -44,18 +44,16 @@ public function __construct($clientId, $token)
$this->list = new Mogreet_List($this);
}

public function processRequest($base, $api, array $params = array(), $multipart = false)
public function processRequest($base, $api, array $params = array(), $multipart = false)
{
// TODO implement flag to do post/get
$params = array_merge($params, $this->_getDefaultApiParams());
$data = Mogreet_Request::postRequest($base, $api, $params, $multipart);
return new Mogreet_Response($params['format'], $data);
}

protected function _getDefaultApiParams()
protected function _getDefaultApiParams()
{
return [ "client_id" => $this->clientId, "token" => $this->token, "format" => $this->defaultFormat ];
}
}

?>
8 changes: 3 additions & 5 deletions lib/Exception.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class Mogreet_Exception
class Mogreet_Exception
extends Exception
{
protected $api;
Expand All @@ -13,15 +13,13 @@ public function __construct($message, $api = '', $params = null, $code = 0)
parent::__construct($message, $code);
}

public function getApi()
public function getApi()
{
return $this->api;
}

public function getParams()
public function getParams()
{
return $this->params;
}
}

?>
12 changes: 5 additions & 7 deletions lib/Keyword.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class Mogreet_Keyword
class Mogreet_Keyword
{
private $client;

Expand All @@ -9,26 +9,24 @@ public function __construct(Mogreet $client)
$this->client = $client;
}

public function listAll(array $params = array())
public function listAll(array $params = array())
{
return $this->client->processRequest('cm', 'keyword.list', $params);
}

public function check(array $params = array())
{
return $this->client->processRequest('cm', 'keyword.check', $params);
}
}

public function add(array $params = array())
{
return $this->client->processRequest('cm', 'keyword.add', $params);
}
}

public function remove(array $params = array())
{
return $this->client->processRequest('cm', 'keyword.remove', $params);
}
}

}

?>
22 changes: 10 additions & 12 deletions lib/List.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class Mogreet_List
class Mogreet_List
{
private $client;

Expand All @@ -9,50 +9,48 @@ public function __construct(Mogreet $client)
$this->client = $client;
}

public function destroy(array $params = array())
public function destroy(array $params = array())
{
return $this->client->processRequest('cm', 'list.destroy', $params);
}

public function pruneAll(array $params = array())
public function pruneAll(array $params = array())
{
return $this->client->processRequest('cm', 'list.empty', $params);
}

public function download(array $params = array())
public function download(array $params = array())
{
return $this->client->processRequest('cm', 'list.download', $params);
}

public function send(array $params = array())
public function send(array $params = array())
{
return $this->client->processRequest('cm', 'list.send', $params);
}

public function prune(array $params = array())
public function prune(array $params = array())
{
return $this->client->processRequest('cm', 'list.prune', $params);
}

public function append(array $params = array())
public function append(array $params = array())
{
return $this->client->processRequest('cm', 'list.append', $params);
}

public function create(array $params = array())
public function create(array $params = array())
{
return $this->client->processRequest('cm', 'list.create', $params);
}

public function listAll(array $params = array())
public function listAll(array $params = array())
{
return $this->client->processRequest('cm', 'list.list', $params);
}

public function info(array $params = array())
public function info(array $params = array())
{
return $this->client->processRequest('cm', 'list.info', $params);
}
}

?>
8 changes: 3 additions & 5 deletions lib/Media.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class Mogreet_Media
class Mogreet_Media
{
private $client;

Expand All @@ -9,7 +9,7 @@ public function __construct(Mogreet $client)
$this->client = $client;
}

public function remove($contentId, array $params = array())
public function remove($contentId, array $params = array())
{
return $this->client->processRequest('cm', 'media.remove', $params);
}
Expand All @@ -19,7 +19,7 @@ public function listAll(array $params = array())
return $this->client->processRequest('cm', 'media.list', $params);
}

public function upload(array $params = array())
public function upload(array $params = array())
{
if (isset($params['file'])) {
// uploading a file located on the server
Expand All @@ -31,5 +31,3 @@ public function upload(array $params = array())
return $this->client->processRequest('cm', 'media.upload', $params, true);
}
}

?>
6 changes: 2 additions & 4 deletions lib/Request.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class Mogreet_Request
class Mogreet_Request
{
private static $_requiredParams = array(
'system.ping' => array(),
Expand Down Expand Up @@ -39,7 +39,7 @@ protected static function _checkParams($api, $params)
}
}

public static function postRequest($base, $api, $params, $multipart)
public static function postRequest($base, $api, $params, $multipart)
{
Mogreet_Request::_checkParams($api, $params);

Expand All @@ -66,5 +66,3 @@ public static function postRequest($base, $api, $params, $multipart)
return $data;
}
}

?>
12 changes: 5 additions & 7 deletions lib/Response.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
<?php

class Mogreet_Response
class Mogreet_Response
{
private $format;
private $data;
private $obj;

public function __construct($format, $data)
public function __construct($format, $data)
{
$this->format = $format;
$this->data = $data;
$this->buildObjectFromJson();
}

protected function buildObjectFromJson()
protected function buildObjectFromJson()
{
/* $this->obj = json_decode($this->data); */
$this->obj = Mogreet_Utils::json_to_object(json_decode($this->data, true));
}

public function __get($property)
public function __get($property)
{
return $this->obj->response->$property;
}

public function __toString()
public function __toString()
{
return $this->data;
}
}

?>
6 changes: 2 additions & 4 deletions lib/System.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class Mogreet_System
class Mogreet_System
{
private $client;

Expand All @@ -9,10 +9,8 @@ public function __construct(Mogreet $client)
$this->client = $client;
}

public function ping(array $params = array())
public function ping(array $params = array())
{
return $this->client->processRequest('moms', 'system.ping', $params);
}
}

?>
8 changes: 3 additions & 5 deletions lib/Transaction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class Mogreet_Transaction
class Mogreet_Transaction
{
protected $client;

Expand All @@ -9,15 +9,13 @@ public function __construct(Mogreet $client)
$this->client = $client;
}

public function send(array $params = array())
public function send(array $params = array())
{
return $this->client->processRequest('moms', 'transaction.send', $params);
}

public function lookup(array $params = array())
{
return $this->client->processRequest('moms', 'transaction.lookup', $params);
}
}
}

?>
14 changes: 6 additions & 8 deletions lib/User.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class Mogreet_User
class Mogreet_User
{
private $client;

Expand All @@ -9,30 +9,28 @@ public function __construct(Mogreet $client)
$this->client = $client;
}

public function transactions(array $params = array())
public function transactions(array $params = array())
{
return $this->client->processRequest('moms', 'user.transactions', $params);
}

public function getopt(array $params = array())
public function getopt(array $params = array())
{
return $this->client->processRequest('moms', 'user.getopt', $params);
}

public function info(array $params = array())
public function info(array $params = array())
{
return $this->client->processRequest('moms', 'user.info', $params);
}

public function lookup(array $params = array())
public function lookup(array $params = array())
{
return $this->client->processRequest('moms', 'user.lookup', $params);
}

public function uncache(array $params = array())
public function uncache(array $params = array())
{
return $this->client->processRequest('moms', 'user.uncache', $params);
}
}

?>
12 changes: 8 additions & 4 deletions lib/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
class Mogreet_Utils
{

public static function toCamelCase($str)
public static function toCamelCase($str)
{
return preg_replace('/_([a-z])/e', "strtoupper('\\1')", $str);
return preg_replace_callback(
'/_([a-z])/',
function ($matches) {
return strtoupper($matches[0]);
},
$str
);
}

public static function fromCamelCase($str)
Expand Down Expand Up @@ -42,5 +48,3 @@ public static function json_to_object($in)
return $obj;
}
}

?>