Permalink
Browse files

Fixed an error because it is PHP5.4

  • Loading branch information...
nobuhiko committed Apr 13, 2012
1 parent 01ed966 commit 4f8b479746cfafddc16f106dc22d80bd8ba088b8
Showing with 37 additions and 37 deletions.
  1. +20 −20 cache/file.php
  2. +17 −17 request.php
View
@@ -20,47 +20,47 @@ class File extends Cache
private $_config;
private $_defaultTtl;
private $_path;
-
- private final function __construct()
+
+ private final function __construct($engine)
{
$this->_config = Config::Instance();
$cache = $this->_config->xpath("//Cache[@Engine='File']");
-
+
if (empty($cache) || count($cache) == 0 || !$cache[0]["Enabled"])
return false;
$this->_defaultTtl = strtotime("+2 minutes");
$this->_path = dirname(dirname(__FILE__)) . "/tmp/cache/";
-
+
if (!is_dir($this->_path))
mkdir($this->_path, 0755, true);
-
+
$this->Gc();
}
-
- public static function Instance()
+
+ public static function Instance($engine = 'File')
{
if (null == static::$_instance)
static::$_instance = new self();
return static::$_instance;
}
-
+
public function Set($key, $value, $ttl = NULL)
{
$ttl = (empty($ttl)) ? $this->_defaultTtl : strtotime($ttl);
-
+
if (!is_string($value))
$value = serialize($value);
-
+
$value = $ttl . PHP_EOL . $value;
$this->_save($key, $value);
}
-
+
public function Get($key)
{
if (null !== ($content = $this->_read($key)))
return $content;
return false;
-
+
}
public function Delete($key)
@@ -82,7 +82,7 @@ public function Clear()
$this->Delete($file);
}
}
-
+
public function Gc()
{
$min = (int)date("i");
@@ -99,12 +99,12 @@ public function Gc()
}
}
}
-
+
private function _read($key)
{
$passes = 3;
$now = time();
-
+
if (!$this->Check($key))
return null;
$lines = null;
@@ -117,12 +117,12 @@ private function _read($key)
}
}
catch (Exception $ex) {}
-
+
if (null === $lines)
return null;
-
+
$ttl = (int)array_shift($lines);
-
+
$content = "";
if (count($lines) > 0) {
if ($now >= $ttl) {
@@ -131,10 +131,10 @@ private function _read($key)
}
$content = implode(PHP_EOL, $lines);
}
-
+
return @unserialize($content);
}
-
+
private function _save($key, $content)
{
return file_put_contents($this->_path . $key, $content, LOCK_EX|FILE_TEXT);
View
@@ -2,7 +2,7 @@
/**
* Instaphp
- *
+ *
* Copyright (c) 2011 randy sesser <randy@instaphp.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -11,18 +11,18 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- *
+ *
* @author randy sesser <randy@instaphp.com>
* @copyright 2011, randy sesser
* @license http://www.opensource.org/licenses/mit-license The MIT License
@@ -64,14 +64,14 @@ class Request
* @access private
*/
private $useCurl = false;
-
+
/**
*
* @var iCache Cache object used for caching
- * @access private
+ * @access private
*/
private $_cache = null;
-
+
/**
* The constructor contructs
* @param string $url A URL in which to create a new request (optional)
@@ -94,7 +94,7 @@ public function __construct($url = null, $params = array())
// $this->_cache = $method->invoke(null, null);
// $this->_cache = Cache\File::Instance();
}
-
+
}
*/
}
@@ -110,16 +110,16 @@ public function Get($url = null, $params = array())
{
if (null !== $url)
$this->url = $url;
-
+
if (!empty($params))
$this->parameters = $params;
$query = '';
foreach ($this->parameters as $k => $v)
$query .= ((strlen ($query) == 0) ? '?' : '&') . sprintf('%s=%s', $k, $v);
-
+
if (null !== $this->_cache) {
$key = sha1($url.$query);
-
+
if (false === ($response = $this->_cache->Get($key))) {
$response = $this->GetResponse();
if (empty ($response->error)) {
@@ -160,7 +160,7 @@ public function Post($url = null, $params = array())
*/
public function Put($url = null, $params = array())
{
-
+
}
/**
@@ -191,21 +191,21 @@ public function Delete($url = null, $params = array())
private function GetResponse($method = 'GET')
{
//-- since there's no option to use anything other curl, this check is kinda useless
- //-- I had high hopes with this one using sockets and whatnot, but alas, time is of
+ //-- I had high hopes with this one using sockets and whatnot, but alas, time is of
//-- the essence... in internet time
if ($this->useCurl) {
$response = new Response;
-
+
$http = WebRequest::Instance();
$res = $http->Create($this->url, $method, $this->parameters);
if ($res instanceof Error)
return $res;
-
+
$response->info = $res->Info;
$response->json = $res->Content;
- $response = Response::Create($this, &$response);
+ $response = Response::Create($this, $response);
return $response;
}
}
@@ -219,7 +219,7 @@ private static function HasCurl()
{
return function_exists('curl_init');
}
-
+
/**
* Determines whether or not curl will follow redirects over SSL
* See the constructor for details, but there are cases in which

0 comments on commit 4f8b479

Please sign in to comment.