-
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
1 parent
75d3b57
commit f0ab355
Showing
10 changed files
with
398 additions
and
3 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,7 @@ | ||
#!/usr/bin/env php -d phar.readonly=0 | ||
<?php | ||
|
||
require_once __DIR__.'/../vendor/autoload.php'; | ||
|
||
$compiler = new Presque\Compiler(); | ||
$compiler->compile(); |
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,9 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
require_once __DIR__.'/../vendor/autoload.php'; | ||
|
||
use Presque\Console\Application; | ||
|
||
$application = new Application(); | ||
$application->run(); |
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
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
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,50 @@ | ||
<?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\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Command\Command; | ||
use Presque\Job; | ||
|
||
class QueueJobCommand extends Command | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('queue') | ||
->setDescription('Adds a job to the queue') | ||
->setDefinition(array( | ||
|
||
)) | ||
->setHelp(<<<EOT | ||
The <info>%command.name%</info> command adds a new job to the queue. | ||
<info>%command.full_name%</info> queue [job] [args] | ||
EOT | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
|
||
} | ||
} |
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,50 @@ | ||
<?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\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Command\Command; | ||
use Presque\Job; | ||
|
||
class WorkerCommand extends Command | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('worker') | ||
->setDescription('Starts a new Presque worker') | ||
->setDefinition(array( | ||
|
||
)) | ||
->setHelp(<<<EOT | ||
The <info>%command.name%</info> command starts a new Presque worker | ||
<info>%command.full_name%</info> queue [job] [args] | ||
EOT | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
|
||
} | ||
} |
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,172 @@ | ||
<?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\Finder\Finder; | ||
|
||
/** | ||
* The Compiler class compiles Presque into a phar. | ||
* | ||
* Based _heavily_ on the the Composer compiler class, just customized to | ||
* be used with Presque. | ||
* | ||
* @author Fabien Potencier <fabien@symfony.com> | ||
* @author Jordi Boggiano <j.boggiano@seld.be> | ||
* | ||
* @link https://github.com/composer/composer/blob/master/src/Composer/Compiler.php | ||
*/ | ||
class Compiler | ||
{ | ||
/** | ||
* Compiles satis into a single phar file | ||
* | ||
* @param string $pharFile The full path to the file to create | ||
* | ||
* @throws \RuntimeException | ||
*/ | ||
public function compile($pharFile = 'presque.phar') | ||
{ | ||
if (file_exists($pharFile)) { | ||
unlink($pharFile); | ||
} | ||
|
||
$phar = new \Phar($pharFile, 0, basename($pharFile)); | ||
$phar->setSignatureAlgorithm(\Phar::SHA1); | ||
|
||
$phar->startBuffering(); | ||
|
||
$finders = array(); | ||
|
||
$finder = new Finder(); | ||
$finder->files() | ||
->ignoreVCS(true) | ||
->name('*.php') | ||
->notName('Compiler.php') | ||
->in(__DIR__) | ||
; | ||
$finders[] = $finder; | ||
|
||
$vendorDir = __DIR__.'/../../vendor/'; | ||
|
||
$finders[] = Finder::create() | ||
->files() | ||
->ignoreVCS(true) | ||
->name('*.php') | ||
->notName('*Test.php') | ||
->in(array( | ||
$vendorDir.'symfony/event-dispatcher', | ||
$vendorDir.'symfony/console', | ||
$vendorDir.'predis/predis/lib', | ||
$vendorDir.'monolog/monolog/src', | ||
$vendorDir.'composer', | ||
)); | ||
|
||
$this->addFile($phar, $vendorDir.'autoload.php'); | ||
|
||
foreach ($finders as $finder) { | ||
foreach ($finder as $file) { | ||
$this->addFile($phar, $file); | ||
} | ||
} | ||
|
||
$this->addConsole($phar); | ||
|
||
// Stubs | ||
$phar->setStub($this->getStub()); | ||
|
||
$phar->stopBuffering(); | ||
|
||
$phar->compressFiles(\Phar::GZ); | ||
|
||
$this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false); | ||
|
||
unset($phar); | ||
} | ||
|
||
private function addFile($phar, $file, $strip = true) | ||
{ | ||
$path = str_replace(dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR, '', is_string($file) ? realpath($file) : $file->getRealPath()); | ||
|
||
$content = file_get_contents($file); | ||
if ($strip) { | ||
$content = $this->stripWhitespace($content); | ||
} elseif ('LICENSE' === basename($file)) { | ||
$content = "\n".$content."\n"; | ||
} | ||
|
||
$phar->addFromString($path, $content); | ||
} | ||
|
||
private function addConsole($phar) | ||
{ | ||
$content = file_get_contents(__DIR__.'/../../bin/presque'); | ||
$content = preg_replace('{^#!/usr/bin/env php\s*}', '', $content); | ||
|
||
$phar->addFromString('bin/presque', $content); | ||
} | ||
|
||
/** | ||
* Removes whitespace from a PHP source string while preserving line numbers. | ||
* | ||
* @param string $source A PHP string | ||
* @return string The PHP string with the whitespace removed | ||
*/ | ||
private function stripWhitespace($source) | ||
{ | ||
if (!function_exists('token_get_all')) { | ||
return $source; | ||
} | ||
|
||
$output = ''; | ||
foreach (token_get_all($source) as $token) { | ||
if (is_string($token)) { | ||
$output .= $token; | ||
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) { | ||
$output .= str_repeat("\n", substr_count($token[1], "\n")); | ||
} elseif (T_WHITESPACE === $token[0]) { | ||
// reduce wide spaces | ||
$whitespace = preg_replace('{[ \t]+}', ' ', $token[1]); | ||
// normalize newlines to \n | ||
$whitespace = preg_replace('{(?:\r\n|\r|\n)}', "\n", $whitespace); | ||
// trim leading spaces | ||
$whitespace = preg_replace('{\n +}', "\n", $whitespace); | ||
$output .= $whitespace; | ||
} else { | ||
$output .= $token[1]; | ||
} | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
private function getStub() | ||
{ | ||
return <<<'EOF' | ||
#!/usr/bin/env php | ||
<?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. | ||
*/ | ||
Phar::mapPhar('presque.phar'); | ||
require 'phar://presque.phar/bin/presque'; | ||
__HALT_COMPILER(); | ||
EOF; | ||
} | ||
} |
Oops, something went wrong.