Merge pull request #511 from romainneutron/developers

[3.8] Developers API
This commit is contained in:
Romain Neutron
2013-07-17 09:16:55 -07:00
20 changed files with 149 additions and 132 deletions

View File

@@ -54,8 +54,8 @@ php:
- 5.5
script:
- bin/setup system:upgrade -y -v -f
- bin/developer dependencies:all --prefer-source
- bin/setup system:upgrade -y -v -f
- php hudson/cleanupSubdefs.php
- bin/developer assets:compile-less
- bin/developer assets:build-javascript

View File

@@ -57,14 +57,16 @@ try {
under certain conditions; type `about:license' for details.\n\n"
. ' Phraseanet Developer Tools ', Version::getName() . ' ' . Version::getNumber());
$helpers = array(
'db' => new ConnectionHelper($cli['EM']->getConnection()),
'em' => new EntityManagerHelper($cli['EM'])
);
if ($cli['phraseanet.configuration']->isSetup()) {
$helpers = array(
'db' => new ConnectionHelper($cli['EM']->getConnection()),
'em' => new EntityManagerHelper($cli['EM'])
);
$helperSet = $cli['console']->getHelperSet();
foreach ($helpers as $name => $helper) {
$helperSet->set($helper, $name);
$helperSet = $cli['console']->getHelperSet();
foreach ($helpers as $name => $helper) {
$helperSet->set($helper, $name);
}
}
$cli->command(new InstallAll());

View File

@@ -88,8 +88,6 @@ use Alchemy\Phrasea\Core\Provider\FtpServiceProvider;
use Alchemy\Geonames\GeonamesServiceProvider;
use Alchemy\Phrasea\Core\Provider\InstallerServiceProvider;
use Alchemy\Phrasea\Core\Provider\JMSSerializerServiceProvider;
use Alchemy\Phrasea\Core\Provider\LessBuilderServiceProvider;
use Alchemy\Phrasea\Core\Provider\LessCompilerServiceProvider;
use Alchemy\Phrasea\Core\Provider\LocaleServiceProvider;
use Alchemy\Phrasea\Core\Provider\NotificationDelivererServiceProvider;
use Alchemy\Phrasea\Core\Provider\ORMServiceProvider;
@@ -255,8 +253,6 @@ class Application extends SilexApplication
$this->register(new PhraseaVersionServiceProvider());
$this->register(new PHPExiftoolServiceProvider());
$this->register(new ReCaptchaServiceProvider());
$this->register(new LessCompilerServiceProvider());
$this->register(new LessBuilderServiceProvider());
$this['recaptcha.public-key'] = $this->share(function (Application $app) {
if ($app['phraseanet.registry']->get('GV_captchas')) {

View File

@@ -13,9 +13,10 @@ namespace Alchemy\Phrasea;
use Alchemy\Phrasea\Command\CommandInterface;
use Symfony\Component\Console;
use Alchemy\Phrasea\Core\CLIProvider\PluginServiceProvider;
use Alchemy\Phrasea\Core\CLIProvider\ComposerSetupServiceProvider;
use Alchemy\Phrasea\Core\CLIProvider\CLIDriversServiceProvider;
use Alchemy\Phrasea\Core\CLIProvider\ComposerSetupServiceProvider;
use Alchemy\Phrasea\Core\CLIProvider\LessBuilderServiceProvider;
use Alchemy\Phrasea\Core\CLIProvider\PluginServiceProvider;
/**
* Phraseanet Command Line Application
@@ -52,6 +53,7 @@ class CLI extends Application
$this->register(new PluginServiceProvider());
$this->register(new ComposerSetupServiceProvider());
$this->register(new CLIDriversServiceProvider());
$this->register(new LessBuilderServiceProvider());
$this->bindRoutes();
}

View File

@@ -54,7 +54,7 @@ class ComposerInstall extends Command
$output->writeln("<info>OK</info>");
}
} catch (ExecutionFailureException $e) {
throw new RuntimeException('Unable to install bower dependencies', $e->getCode(), $e);
throw new RuntimeException('Unable to install composer dependencies', $e->getCode(), $e);
}
return 0;

View File

@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Utilities\Less;
namespace Alchemy\Phrasea\Command\Developer\Utils;
use Alchemy\BinaryDriver\AbstractBinary;
use Psr\Log\LoggerInterface;
@@ -18,11 +18,20 @@ use Alchemy\BinaryDriver\ConfigurationInterface;
class RecessDriver extends AbstractBinary
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'recess';
}
/**
* @param array|ConfigurationInterface $conf
* @param LoggerInterface $logger
*
* @return RecessDriver
*/
public static function create($conf = array(), LoggerInterface $logger = null)
{
if (!$conf instanceof ConfigurationInterface) {

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Core\CLIProvider;
use Alchemy\Phrasea\Command\Developer\Utils\BowerDriver;
use Alchemy\Phrasea\Command\Developer\Utils\UglifyJsDriver;
use Alchemy\Phrasea\Command\Developer\Utils\ComposerDriver;
use Alchemy\Phrasea\Command\Developer\Utils\RecessDriver;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\Process\ExecutableFinder;
@@ -26,13 +27,21 @@ class CLIDriversServiceProvider implements ServiceProviderInterface
return new ExecutableFinder();
});
$app['driver.bower'] = $app->share(function (Application $app) {
if (isset($app['phraseanet.configuration']['binaries']['bower_binary'])) {
$bowerBinary = $app['phraseanet.configuration']['binaries']['bower_binary'];
} else {
$bowerBinary = $app['executable-finder']->find('bower');
$app['driver.binary-finder'] = $app->protect(function ($name, $configName) use ($app) {
if (!$app['phraseanet.configuration']->isSetup()) {
return $app['executable-finder']->find($name);
}
if (isset($app['phraseanet.configuration']['binaries'][$configName])) {
return $app['phraseanet.configuration']['binaries'][$configName];
}
return $app['executable-finder']->find($name);
});
$app['driver.bower'] = $app->share(function (Application $app) {
$bowerBinary = $app['driver.binary-finder']('bower', 'bower_binary');
if (null === $bowerBinary) {
throw new RuntimeException('Unable to find bower executable.');
}
@@ -40,13 +49,19 @@ class CLIDriversServiceProvider implements ServiceProviderInterface
return BowerDriver::create(array('bower.binaries' => $bowerBinary), $app['monolog']);
});
$app['driver.composer'] = $app->share(function (Application $app) {
if (isset($app['phraseanet.configuration']['binaries']['composer_binary'])) {
$composerBinary = $app['phraseanet.configuration']['binaries']['composer_binary'];
} else {
$composerBinary = $app['executable-finder']->find('composer');
$app['driver.recess'] = $app->share(function (Application $app) {
$recessBinary = $app['driver.binary-finder']('recess', 'recess_binary');
if (null === $recessBinary) {
throw new RuntimeException('Unable to find recess executable.');
}
return RecessDriver::create(array('recess.binaries' => $recessBinary), $app['monolog']);
});
$app['driver.composer'] = $app->share(function (Application $app) {
$composerBinary = $app['driver.binary-finder']('composer', 'composer_binary');
if (null === $composerBinary) {
throw new RuntimeException('Unable to find composer executable.');
}
@@ -55,7 +70,13 @@ class CLIDriversServiceProvider implements ServiceProviderInterface
});
$app['driver.uglifyjs'] = $app->share(function (Application $app) {
return UglifyJsDriver::create(array(), $app['monolog']);
$uglifyJsBinary = $app['driver.binary-finder']('uglifyjs', 'uglifyjs_binary');
if (null === $uglifyJsBinary) {
throw new RuntimeException('Unable to find uglifyJs executable.');
}
return UglifyJsDriver::create(array('uglifyjs.binaries' => $uglifyJsBinary), $app['monolog']);
});
}

View File

@@ -9,11 +9,12 @@
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Provider;
namespace Alchemy\Phrasea\Core\CLIProvider;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Alchemy\Phrasea\Utilities\Less\Builder as LessBuilder;
use Alchemy\Phrasea\Utilities\Less\Compiler as LessCompiler;
class LessBuilderServiceProvider implements ServiceProviderInterface
{
@@ -47,6 +48,10 @@ class LessBuilderServiceProvider implements ServiceProviderInterface
);
});
$app['phraseanet.less-compiler'] = $app->share(function($app) {
return new LessCompiler($app['filesystem'], $app['driver.recess']);
});
$app['phraseanet.less-builder'] = $app->share(function($app) {
return new LessBuilder($app['phraseanet.less-compiler'], $app['filesystem']);
});

View File

@@ -1,30 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Provider;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Alchemy\Phrasea\Utilities\Less\Compiler as LessCompiler;
class LessCompilerServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$app['phraseanet.less-compiler'] = $app->share(function($app) {
return LessCompiler::create($app);
});
}
public function boot(Application $app)
{
}
}

View File

@@ -11,8 +11,7 @@
namespace Alchemy\Phrasea\Utilities\Less;
use Alchemy\Phrasea\Application;
use Alchemy\BinaryDriver\BinaryInterface;
use Alchemy\Phrasea\Command\Developer\Utils\RecessDriver;
use Alchemy\BinaryDriver\Exception\ExecutionFailureException;
use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\Filesystem\Filesystem;
@@ -22,19 +21,12 @@ class Compiler
private $filesystem;
private $recess;
public function __construct(Filesystem $filesystem, BinaryInterface $recess)
public function __construct(Filesystem $filesystem, RecessDriver $recess)
{
$this->filesystem = $filesystem;
$this->recess = $recess;
}
public static function create(Application $app)
{
$binaries = $app['phraseanet.configuration']['binaries'];
return new self($app['filesystem'], RecessDriver::create($binaries));
}
/**
* Compile LESS files
*

View File

@@ -10,8 +10,6 @@
*/
use Alchemy\Phrasea\Application;
use Entities\Session;
use Entities\SessionModule;
class patch_3814 implements patchInterface
{

View File

@@ -1,17 +1,8 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Tests\Phrasea\Command\Developper\Utils;
namespace Alchemy\Tests\Phrasea\Utilities\Less;
use Alchemy\Phrasea\Utilities\Less\RecessDriver;
use Alchemy\Phrasea\Command\Developer\Utils\RecessDriver;
class RecessDriverTest extends \PHPUnit_Framework_TestCase
{

View File

@@ -30,6 +30,11 @@ class CLISDriversServiceProviderTest extends ServiceProviderTestCase
'driver.uglifyjs',
'Alchemy\Phrasea\Command\Developer\Utils\UglifyJsDriver'
),
array(
'Alchemy\Phrasea\Core\CLIProvider\CLIDriversServiceProvider',
'driver.recess',
'Alchemy\Phrasea\Command\Developer\Utils\RecessDriver'
),
);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Alchemy\Tests\Phrasea\Core\CLIProvider;
/**
* @covers Alchemy\Phrasea\Core\CLIProvider\LessBuilderServiceProvider
*/
class LessBuilderServiceProvidertest extends ServiceProviderTestCase
{
public function provideServiceDescription()
{
return array(
array(
'Alchemy\Phrasea\Core\CLIProvider\LessBuilderServiceProvider',
'phraseanet.less-compiler',
'\Alchemy\Phrasea\Utilities\Less\Compiler'
),
array(
'Alchemy\Phrasea\Core\CLIProvider\LessBuilderServiceProvider',
'phraseanet.less-builder',
'\Alchemy\Phrasea\Utilities\Less\Builder'
),
);
}
}

View File

@@ -3,7 +3,7 @@ main:
maintenance: false
database:
host: 'sql-host'
port: '3306'
port: 3306
user: 'sql-user'
password: 'sql-password'
dbname: ab_phraseanet
@@ -25,12 +25,28 @@ main:
search-engine:
type: Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine
options: []
task-manager:
options: null
trusted-proxies: []
debugger:
allowed-ips: []
binaries: []
binaries:
ghostscript_binary: null
php_binary: null
swf_extract_binary: null
pdf2swf_binary: null
swf_render_binary: null
unoconv_binary: null
ffmpeg_binary: null
ffprobe_binary: null
mp4box_binary: null
pdftotext_binary: null
recess_binary: null
phraseanet_indexer: null
ffmpeg_timeout: 3600
ffprobe_timeout: 60
gs_timeout: 60
mp4box_timeout: 60
swftools_timeout: 60
unoconv_timeout: 60
border-manager:
enabled: true
checkers:

View File

@@ -3,7 +3,7 @@ main:
maintenance: false
database:
host: 'sql-host'
port: '3306'
port: 3306
user: 'sql-user'
password: 'sql-password'
dbname: ab_phraseanet
@@ -25,12 +25,28 @@ main:
search-engine:
type: Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine
options: []
task-manager:
options: null
trusted-proxies: []
debugger:
allowed-ips: []
binaries: []
binaries:
ghostscript_binary: null
php_binary: null
swf_extract_binary: null
pdf2swf_binary: null
swf_render_binary: null
unoconv_binary: null
ffmpeg_binary: null
ffprobe_binary: null
mp4box_binary: null
pdftotext_binary: null
recess_binary: null
phraseanet_indexer: null
ffmpeg_timeout: 3600
ffprobe_timeout: 60
gs_timeout: 60
mp4box_timeout: 60
swftools_timeout: 60
unoconv_timeout: 60
border-manager:
enabled: true
checkers:

View File

@@ -1,16 +0,0 @@
<?php
namespace Alchemy\Tests\Phrasea\Core\Provider;
/**
* @covers Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider
*/
class LessCompilerServiceProvidertest extends ServiceProviderTestCase
{
public function provideServiceDescription()
{
return array(
array('Alchemy\Phrasea\Core\Provider\LessCompilerServiceProvider', 'phraseanet.less-compiler', '\Alchemy\Phrasea\Utilities\Less\Compiler'),
);
}
}

View File

@@ -1,16 +0,0 @@
<?php
namespace Alchemy\Tests\Phrasea\Core\Provider;
/**
* @covers Alchemy\Phrasea\Core\Provider\UnicodeServiceProvider
*/
class LessBuilderServiceProvidertest extends ServiceProviderTestCase
{
public function provideServiceDescription()
{
return array(
array('Alchemy\Phrasea\Core\Provider\LessBuilderServiceProvider', 'phraseanet.less-builder', '\Alchemy\Phrasea\Utilities\Less\Builder'),
);
}
}

View File

@@ -18,7 +18,9 @@ class CompilerTest extends \PhraseanetPHPUnitAbstract
{
public function testCompileSuccess()
{
$recessDriver = $this->getMock('Alchemy\BinaryDriver\BinaryInterface');
$recessDriver = $this->getMockBuilder('Alchemy\Phrasea\Command\Developer\Utils\RecessDriver')
->disableOriginalConstructor()
->getMock();
$recessDriver->expects($this->once())->method('command');
$filesystem = $this->getMock('Symfony\Component\Filesystem\Filesystem');
@@ -30,18 +32,14 @@ class CompilerTest extends \PhraseanetPHPUnitAbstract
$compiler->compile(__DIR__ . '/output.css', __FILE__);
}
public function testCreate()
{
$compiler = Compiler::create(self::$DI['app']);
$this->assertInstanceOf('Alchemy\Phrasea\Utilities\Less\Compiler', $compiler);
}
/**
/**
* @expectedException Alchemy\Phrasea\Exception\RuntimeException
*/
public function testCompileFileNotExists()
{
$recessDriver = $this->getMock('Alchemy\BinaryDriver\BinaryInterface');
$recessDriver = $this->getMockBuilder('Alchemy\Phrasea\Command\Developer\Utils\RecessDriver')
->disableOriginalConstructor()
->getMock();
$filesystem = $this->getMock('Symfony\Component\Filesystem\Filesystem');
$filesystem->expects($this->once())->method('mkdir');
@@ -56,7 +54,10 @@ class CompilerTest extends \PhraseanetPHPUnitAbstract
*/
public function testCompileExecutionFailure()
{
$recessDriver = $this->getMock('Alchemy\BinaryDriver\BinaryInterface');
$recessDriver = $this->getMockBuilder('Alchemy\Phrasea\Command\Developer\Utils\RecessDriver')
->disableOriginalConstructor()
->getMock();
$recessDriver->expects($this->once())->method('command')->will(
$this->throwException(new ExecutionFailureException())
);