-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 37aba9f
Showing
28 changed files
with
782 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
|
||
before_script: | ||
- wget --quiet http://getcomposer.org/composer.phar | ||
- php composer.phar install | ||
- cp phpunit.xml.dist phpunit.xml | ||
|
||
script: phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright © 2012 Justin Rainbow <justin.rainbow@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to deal | ||
in the Software without restriction, including without limitation the rights | ||
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. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "presque/presque", | ||
"type": "library", | ||
"require": { | ||
"predis/predis" : "0.7.*", | ||
"symfony/event-dispatcher": "2.1.*@dev" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"": "src/" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
bootstrap="tests/bootstrap.php" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Presque Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src/Presque/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque; | ||
|
||
use Presque\StatusInterface; | ||
|
||
abstract class AbstractJob implements JobInterface | ||
{ | ||
public function isSuccessful() | ||
{ | ||
return StatusInterface::SUCCESS === $this->getStatus(); | ||
} | ||
|
||
public function isError() | ||
{ | ||
return StatusInterface::FAILED === $this->getStatus(); | ||
} | ||
|
||
public function isActive() | ||
{ | ||
return StatusInterface::RUNNING === $this->getStatus(); | ||
} | ||
|
||
public function isTrackable() | ||
{ | ||
|
||
} | ||
|
||
public function getMaxAttempts() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Event; | ||
|
||
use Symfony\Component\EventDispatcher\Event as SymfonyEvent; | ||
|
||
class Event extends SymfonyEvent | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Event; | ||
|
||
class StatusEvent extends Event | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque; | ||
|
||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* Provides methods to use with the Symfony EventDispatcher component. | ||
* | ||
* @author Justin Rainbow <justin.rainbow@gmail.com> | ||
*/ | ||
interface EventDispatcherAwareInterface | ||
{ | ||
/** | ||
* Sets an instance of the EventDispatcherInterface for this object. | ||
* If the `$eventDispatcher` is null, the object must remove any | ||
* current EventDispatcherInterface assigned to it. | ||
* | ||
* @param EventDispatcherInterface $eventDispatcher | ||
*/ | ||
function setEventDispatcher(EventDispatcherInterface $eventDispatcher = null); | ||
|
||
/** | ||
* Returns an instance of the EventDispatcher | ||
* | ||
* @return EventDispatcherInterface | ||
*/ | ||
function getEventDispatcher(); | ||
|
||
/** | ||
* Checks if there is an EventDispatcher available to the current object. | ||
* | ||
* @return Boolean | ||
*/ | ||
function hasEventDispatcher(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque; | ||
|
||
final class Events | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque\Exception; | ||
|
||
class InvalidArgumentException extends \InvalidArgumentException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Presque package. | ||
* | ||
* (c) Justin Rainbow <justin.rainbow@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Presque; | ||
|
||
use Presque\Exception\InvalidArgumentException; | ||
|
||
class Job extends AbstractJob | ||
{ | ||
protected $class; | ||
protected $args; | ||
|
||
private $reflClass; | ||
private $reflMethod; | ||
private $instance; | ||
|
||
public static function create($class, array $args = array()) | ||
{ | ||
return new static($class, $args); | ||
} | ||
|
||
public function __construct($class, array $args = array()) | ||
{ | ||
try { | ||
$refl = new \ReflectionClass($class); | ||
} catch (\ReflectionException $e) { | ||
throw new InvalidArgumentException( | ||
$class . ' is not a valid class. Please make sure it has already been '. | ||
'defined or can be autoloaded.' | ||
); | ||
} | ||
|
||
if (!$refl->hasMethod('perform')) { | ||
throw new InvalidArgumentException( | ||
$class . ' must implement the "perform" method to be added to the queue.' | ||
); | ||
} | ||
|
||
$method = $refl->getMethod('perform'); | ||
|
||
if (!$method->isPublic()) { | ||
throw new InvalidArgumentException( | ||
'The "perform" method for class "' . $class . '" must be public, not ' . $method->getVisiblity() | ||
); | ||
} | ||
|
||
if (count($args) < $method->getNumberOfRequiredParameters()) { | ||
throw new InvalidArgumentException( | ||
'The ' . $class . ' has ' . $method->getNumberOfRequiredParameters() . ' required '. | ||
'arguments, but only ' . count($args) . ' were provided.' | ||
); | ||
} | ||
|
||
$this->class = $class; | ||
$this->args = $args; | ||
|
||
$this->reflClass = $refl; | ||
$this->reflMethod = $method; | ||
} | ||
|
||
public function perform() | ||
{ | ||
return $this->reflMethod->invokeArgs( | ||
$this->getInstance(), | ||
$this->getArguments() | ||
); | ||
} | ||
|
||
public function getMaxAttempts() | ||
{ | ||
|
||
} | ||
|
||
public function getClass() | ||
{ | ||
return $this->class; | ||
} | ||
|
||
public function getArguments() | ||
{ | ||
return $this->args; | ||
} | ||
|
||
public function getInstance() | ||
{ | ||
if (!$this->instance) { | ||
$this->instance = $this->reflClass->newInstance(); | ||
} | ||
|
||
return $this->instance; | ||
} | ||
} |
Oops, something went wrong.