Skip to content

Commit

Permalink
Initial commit for the Presque lib
Browse files Browse the repository at this point in the history
  • Loading branch information
justinrainbow committed Jul 22, 2012
0 parents commit 37aba9f
Show file tree
Hide file tree
Showing 28 changed files with 782 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
12 changes: 12 additions & 0 deletions .travis.yml
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
21 changes: 21 additions & 0 deletions LICENSE
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 added README.md
Empty file.
13 changes: 13 additions & 0 deletions composer.json
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/"
}
}
}
29 changes: 29 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions phpunit.xml.dist
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>
42 changes: 42 additions & 0 deletions src/Presque/AbstractJob.php
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()
{

}
}
18 changes: 18 additions & 0 deletions src/Presque/Event/Event.php
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
{
}
16 changes: 16 additions & 0 deletions src/Presque/Event/StatusEvent.php
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
{
}
45 changes: 45 additions & 0 deletions src/Presque/EventDispatcherAwareInterface.php
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();
}
16 changes: 16 additions & 0 deletions src/Presque/Events.php
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
{
}
16 changes: 16 additions & 0 deletions src/Presque/Exception/InvalidArgumentException.php
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
{
}
100 changes: 100 additions & 0 deletions src/Presque/Job.php
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;
}
}
Loading

0 comments on commit 37aba9f

Please sign in to comment.