Permalink
Browse files

Merge pull request #13 from iron-io/psr2-style

style: apply psr2 with phpfmt
  • Loading branch information...
thousandsofthem committed Feb 23, 2016
2 parents ad1aa6e + 8c9ca55 commit 473f43859d2e9723605bb370276ac3de0496b4de
Showing with 48 additions and 56 deletions.
  1. +44 −49 IronCache.class.php
  2. +2 −5 TestCache.php
  3. +2 −2 build.php
View
@@ -10,7 +10,6 @@
* @copyright Feel free to copy, steal, take credit for, or whatever you feel like doing with this code. ;)
*/
-
class IronCache_Item
{
protected $value;
@@ -89,7 +88,7 @@ public function getAdd()
public function setExpiresIn($expires_in)
{
if ($expires_in > self::MAX_EXPIRES_IN) {
- throw new InvalidArgumentException("Expires In can't be greater than ".self::MAX_EXPIRES_IN.".");
+ throw new InvalidArgumentException("Expires In can't be greater than " . self::MAX_EXPIRES_IN . ".");
} else {
$this->expires_in = $expires_in;
}
@@ -134,20 +133,20 @@ class IronCache extends IronCore
public $session_expire_time = 172800; # 2 days
/**
- * @param string|array $config
- * Array of options or name of config file.
- * Fields in options array or in config:
- *
- * Required:
- * - token
- * - project_id
- * Optional:
- * - protocol
- * - host
- * - port
- * - api_version
- * @param string|null $cache_name set default cache name
- */
+ * @param string|array $config
+ * Array of options or name of config file.
+ * Fields in options array or in config:
+ *
+ * Required:
+ * - token
+ * - project_id
+ * Optional:
+ * - protocol
+ * - host
+ * - port
+ * - api_version
+ * @param string|null $cache_name set default cache name
+ */
public function __construct($config = null, $cache_name = null)
{
$this->getConfigData($config);
@@ -156,11 +155,11 @@ public function __construct($config = null, $cache_name = null)
}
/**
- * Switch active project
- *
- * @param string $project_id Project ID
- * @throws InvalidArgumentException
- */
+ * Switch active project
+ *
+ * @param string $project_id Project ID
+ * @throws InvalidArgumentException
+ */
public function setProjectId($project_id)
{
if (!empty($project_id)) {
@@ -172,11 +171,11 @@ public function setProjectId($project_id)
}
/**
- * Set default cache name
- *
- * @param string $cache_name name of cache
- * @throws InvalidArgumentException
- */
+ * Set default cache name
+ *
+ * @param string $cache_name name of cache
+ * @throws InvalidArgumentException
+ */
public function setCacheName($cache_name)
{
if (!empty($cache_name)) {
@@ -197,12 +196,12 @@ public function getCaches($page = 0)
}
/**
- * Get information about cache.
- * Also returns cache size.
- *
- * @param string $cache
- * @return mixed
- */
+ * Get information about cache.
+ * Also returns cache size.
+ *
+ * @param string $cache
+ * @return mixed
+ */
public function getCache($cache)
{
$cache = self::encodeCache($cache);
@@ -235,10 +234,10 @@ public function getCache($cache)
public function putItem($cache, $key, $item)
{
$cache = self::encodeCache($cache);
- $key = self::encodeKey($key);
- $itm = new IronCache_Item($item);
- $req = $itm->asArray();
- $url = "projects/{$this->project_id}/caches/$cache/items/$key";
+ $key = self::encodeKey($key);
+ $itm = new IronCache_Item($item);
+ $req = $itm->asArray();
+ $url = "projects/{$this->project_id}/caches/$cache/items/$key";
$this->setJsonHeaders();
$res = $this->apiCall(self::PUT, $url, $req);
@@ -256,8 +255,8 @@ public function putItem($cache, $key, $item)
public function getItem($cache, $key)
{
$cache = self::encodeCache($cache);
- $key = self::encodeKey($key);
- $url = "projects/{$this->project_id}/caches/$cache/items/$key";
+ $key = self::encodeKey($key);
+ $url = "projects/{$this->project_id}/caches/$cache/items/$key";
$this->setJsonHeaders();
try {
@@ -275,8 +274,8 @@ public function getItem($cache, $key)
public function deleteItem($cache, $key)
{
$cache = self::encodeCache($cache);
- $key = self::encodeKey($key);
- $url = "projects/{$this->project_id}/caches/$cache/items/$key";
+ $key = self::encodeKey($key);
+ $url = "projects/{$this->project_id}/caches/$cache/items/$key";
$this->setJsonHeaders();
return self::json_decode($this->apiCall(self::DELETE, $url));
@@ -297,16 +296,15 @@ public function deleteItem($cache, $key)
public function incrementItem($cache, $key, $amount = 1)
{
$cache = self::encodeCache($cache);
- $key = self::encodeKey($key);
+ $key = self::encodeKey($key);
$url = "projects/{$this->project_id}/caches/$cache/items/$key/increment";
$params = array(
- 'amount' => $amount
+ 'amount' => $amount,
);
$this->setJsonHeaders();
return self::json_decode($this->apiCall(self::POST, $url, $params));
}
-
/**
* Shortcut for getItem($cache, $key)
* Please set $cache name before use by setCacheName() method
@@ -380,7 +378,6 @@ public function clear($cache = null)
return self::json_decode($this->apiCall(self::POST, $url, $params));
}
-
public function session_open($savePath, $sessionName)
{
$this->setCacheName($sessionName);
@@ -405,8 +402,8 @@ public function session_read($id)
public function session_write($id, $data)
{
$this->put($id, array(
- "value" => $data,
- "expires_in" => $this->session_expire_time
+ "value" => $data,
+ "expires_in" => $this->session_expire_time,
));
return true;
}
@@ -447,7 +444,6 @@ public function set_as_session_store($session_expire_time = null)
);
}
-
/* PRIVATE FUNCTIONS */
protected static function encodeCache($cache)
@@ -466,7 +462,6 @@ protected static function encodeKey($key)
return rawurlencode($key);
}
-
protected function setJsonHeaders()
{
$this->setCommonHeaders();
@@ -475,6 +470,6 @@ protected function setJsonHeaders()
protected function setPostHeaders()
{
$this->setCommonHeaders();
- $this->headers['Content-Type'] ='multipart/form-data';
+ $this->headers['Content-Type'] = 'multipart/form-data';
}
}
View
@@ -1,15 +1,14 @@
<?php
#require "iron_cache.phar";
-require("../iron_core_php/IronCore.class.php");
-require("IronCache.class.php");
+require "../iron_core_php/IronCore.class.php";
+require "IronCache.class.php";
$cache = new IronCache();
$cache->ssl_verifypeer = false;
#$cache->debug_enabled = true;
$cache->setCacheName('cache #4');
-
for ($i = 0; $i < 10; $i++) {
$key = "key ##$i";
@@ -41,9 +40,7 @@
$res = $cache->clear();
var_dump($res);
-
echo "----$i----\n";
}
-
echo "\n done";
View
@@ -6,7 +6,7 @@
* or
* include("phar://".dirname(__FILE__)."/iron_cache.phar");
*/
-
+
@unlink('iron_cache.phar');
$phar = new Phar('iron_cache.phar');
@@ -25,7 +25,7 @@
$phar->addFile('IronCache.class.php');
$phar->addFile('LICENSE', 'LICENSE');
-echo "\ndone - ".(round(filesize('iron_cache.phar')/1024, 2))." KB\n";
+echo "\ndone - " . (round(filesize('iron_cache.phar') / 1024, 2)) . " KB\n";
# Verification
require "phar://iron_cache.phar";

0 comments on commit 473f438

Please sign in to comment.