Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Docs

  • Loading branch information...
commit 02dafcd215246113e5247dc5efa707f17c852ff2 1 parent 419b411
@kakserpom authored
View
6 lib/CappedCacheStorageHits.php
@@ -8,6 +8,12 @@
* @author Zorin Vasily <kak.serpom.po.yaitsam@gmail.com>
*/
class CappedCacheStorageHits extends CappedCacheStorage {
+
+ /**
+ * Constructor
+ * @param [integer Maximum number of cached elements]
+ * @return object
+ */
public function __construct($max = null) {
if ($max !== null) {
$this->maxCacheSize = $max;
View
22 lib/ClearStackException.php
@@ -1,8 +1,28 @@
<?php
class ClearStackException extends Exception {
- public $thread;
+ /**
+ * Thread object
+ * @var object Thread
+ */
+ protected $thread;
+
+ /**
+ * Constructor
+ * @param string Message
+ * @param integer Code
+ * @param [object Thread]
+ * @return mixed
+ */
public function __construct($msg, $code, $thread = null) {
parent::__construct($msg, $code);
$this->thread = $thread;
}
+
+ /**
+ * Gets associated Thread object
+ * @return object Thread
+ */
+ public function getThread() {
+ return $this->thread;
+ }
}
View
96 lib/ComplexJob.php
@@ -8,39 +8,102 @@ class ComplexJob {
const STATE_WAITING = 1;
const STATE_RUNNING = 2;
const STATE_DONE = 3;
-
+
+ /**
+ * Listeners
+ * @var array [callable, ...]
+ */
public $listeners = [];
+
+ /**
+ * Hash of results
+ * @var array [jobname -> result, ...]
+ */
public $results = [];
+
+ /**
+ * Current state
+ * @var enum
+ */
public $state;
+
+ /**
+ * Hash of results
+ * @var array [jobname -> result, ...]
+ */
public $jobs = [];
+
+ /**
+ * Number of results
+ * @var integer
+ */
public $resultsNum = 0;
+
+ /**
+ * Number of jobs
+ * @var integer
+ */
public $jobsNum = 0;
+ /**
+ * Constructor
+ * @param callable Listener
+ * @return object
+ */
public function __construct($cb = null) {
$this->state = self::STATE_WAITING;
if($cb !== null) {
$this->addListener($cb);
}
}
+
+ /**
+ * Has completed?
+ * @return boolean
+ */
public function hasCompleted() {
return $this->state === self::STATE_DONE;
}
+ /**
+ * Proxy call
+ * @param string Name
+ * @param array Arguments
+ * @return boolean
+ */
public function __call($name, $args) {
+ if (!isset($this->{$name})) {
+ return false;
+ }
return call_user_func_array($this->{$name}, $args);
}
+ /**
+ * Set result
+ * @param string Job name
+ * @param mixed Result
+ * @return void
+ */
public function setResult($jobname, $result = null) {
$this->results[$jobname] = $result;
++$this->resultsNum;
$this->checkIfAllReady();
}
+ /**
+ * Get result
+ * @param string Job name
+ * @return mixed Result or null
+ */
public function getResult($jobname) {
return isset($this->results[$jobname]) ? $this->results[$jobname] : null;
}
- public function checkIfAllReady() {
+ /**
+ * Checks if all jobs are ready
+ * @return void
+ */
+ protecte function checkIfAllReady() {
if ($this->resultsNum >= $this->jobsNum) {
$this->jobs = [];
$this->state = self::STATE_DONE;
@@ -49,7 +112,13 @@ public function checkIfAllReady() {
}
}
}
-
+
+ /**
+ * Adds job
+ * @param string Job name
+ * @param callable Callback
+ * @return boolean Success
+ */
public function addJob($name, $cb) {
if (isset($this->jobs[$name])) {
return false;
@@ -61,13 +130,22 @@ public function addJob($name, $cb) {
}
return true;
}
-
+
+ /**
+ * Clean up
+ * @return void
+ */
public function cleanup() {
$this->listeners = [];
$this->results = [];
$this->jobs = [];
}
+ /**
+ * Adds listener
+ * @param callable Callback
+ * @return void
+ */
public function addListener($cb) {
if ($this->state === self::STATE_DONE) {
call_user_func($cb, $this);
@@ -76,6 +154,10 @@ public function addListener($cb) {
$this->listeners[] = CallbackWrapper::wrap($cb);
}
+ /**
+ * Runs the job
+ * @return void
+ */
public function execute() {
if ($this->state === self::STATE_WAITING) {
$this->state = self::STATE_RUNNING;
@@ -86,7 +168,11 @@ public function execute() {
$this->checkIfAllReady();
}
}
-
+
+ /**
+ * Adds new job or calls execute() method
+ * @return void
+ */
public function __invoke($name = null, $cb = null) {
if (func_num_args() === 0) {
return $this->execute();
Please sign in to comment.
Something went wrong with that request. Please try again.