parent
7131e2accd
commit
3809682801
@ -1,4 +1,4 @@ |
||||
web: .PHONY |
||||
php -S localhost:8088 -t . index.php
|
||||
php -S localhost:1337
|
||||
|
||||
.PHONY: |
||||
|
@ -1,24 +0,0 @@ |
||||
{ |
||||
"name": "seld/php-console", |
||||
"description": "A console to quickly try and run PHP code in your browser", |
||||
"keywords": ["console", "php"], |
||||
"homepage": "http://github.com/Seldaek/php-console", |
||||
"type": "project", |
||||
"license": "BSD-3-Clause", |
||||
"authors": [ |
||||
{ |
||||
"name": "Jordi Boggiano", |
||||
"email": "j.boggiano@seld.be", |
||||
"homepage": "http://seld.be" |
||||
} |
||||
], |
||||
"require": { |
||||
"php": ">=5.2.0", |
||||
"sensiolabs/melody": "@dev" |
||||
}, |
||||
"extra": { |
||||
"branch-alias": { |
||||
"dev-master": "1.5.x-dev" |
||||
} |
||||
} |
||||
} |
@ -1,65 +0,0 @@ |
||||
<?php |
||||
|
||||
use SensioLabs\Melody\Melody; |
||||
use SensioLabs\Melody\Configuration\RunConfiguration; |
||||
use Symfony\Component\Process\Process; |
||||
use SensioLabs\Melody\Resource\ResourceParser; |
||||
use Symfony\Component\Process\ExecutableFinder; |
||||
|
||||
/** |
||||
* Class which integrates melody scripts into the php-console. |
||||
* |
||||
* @author mstaab |
||||
* @see https://github.com/sensiolabs/melody |
||||
*/ |
||||
class MelodyPlugin { |
||||
public function isMelodyScript($source) { |
||||
return preg_match(ResourceParser::MELODY_PATTERN, $source); |
||||
} |
||||
|
||||
public function isScriptingSupported() { |
||||
$executableFinder = new ExecutableFinder(); |
||||
foreach (['composer', 'composer.phar'] as $candidateName) { |
||||
if ($composerPath = $executableFinder->find($candidateName, null, array(getcwd()))) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public function runScript($__source_code, $__bootstrap_file) |
||||
{ |
||||
$tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'melody-composer'; |
||||
|
||||
// make sure the melody subprocess has a composer home, |
||||
// which is not the case when running from webcontext |
||||
$_ENV['COMPOSER_HOME'] = $tmpDir; |
||||
|
||||
$melody = new Melody(); |
||||
$configuration = new RunConfiguration(/*true, true*/); |
||||
$executor = function (Process $process, $verbose) |
||||
{ |
||||
$callback = function ($type, $text) |
||||
{ |
||||
// we only have one output channel to the browser, just echo "all the things" |
||||
echo $text; |
||||
}; |
||||
$process->run($callback); |
||||
}; |
||||
|
||||
//TODO missing $__bootstrap_file support |
||||
/* |
||||
if ($__bootstrap_file) { |
||||
require $__bootstrap_file; |
||||
} |
||||
*/ |
||||
|
||||
$tmpFile = tempnam($tmpDir, '_script'); |
||||
register_shutdown_function(function() use ($tmpFile) { |
||||
@unlink($tmpFile); |
||||
}); |
||||
file_put_contents($tmpFile, $__source_code); |
||||
$melody->run($tmpFile, array(), $configuration, $executor); |
||||
} |
||||
} |
Loading…
Reference in new issue