Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for zend-mvc > 3.0 #147

Merged
merged 13 commits into from
Jul 5, 2016
Merged
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm
Expand Down
7 changes: 1 addition & 6 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
use Zend\Version\Version;

class Module implements
AutoloaderProviderInterface,
Expand All @@ -35,11 +34,7 @@ public function onBootstrap(EventInterface $e)

// Listener have only sense when request is via http.
if (!Console::isConsole()) {
if (Version::compareVersion('3.0.0') == -1) {
$em->attach($sm->get('AsseticBundle\Listener'));
} else {
$sm->get('AsseticBundle\Listener')->attach($em);
}
$sm->get('AsseticBundle\Listener')->attach($em);
}
}

Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
}
],
"require": {
"php": ">=5.4",
"php": "^5.6 || ^7.0",
"kriswallsmith/assetic": "^1.2",
"widmogrod/php-functional": "^1.0"
"widmogrod/php-functional": "^1.0",
"zendframework/zend-mvc": "^3.0",
"zendframework/zend-mvc-console": "^1.0",
"zendframework/zend-console": "^2.6"
},
"require-dev": {
"phpunit/phpunit": "^3.7",
"zendframework/zend-mvc": "^2.6",
"zendframework/zend-console": "^2.6",
"zendframework/zend-version": "@stable"
"phpunit/phpunit": "^5.4"
},
"suggest": {
"leafo/lessphp": "Assetic provides the integration with the lessphp LESS compiler",
Expand Down
15 changes: 5 additions & 10 deletions configs/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

return array(
'controllers' => array(
'invokables' => array(
'aliases' => array(
'AsseticBundle\Controller\Console' => 'AsseticBundle\Controller\ConsoleController',
),
'initializers' => array(
'AsseticBundleInitializer' => 'AsseticBundle\Initializer\AsseticBundleInitializer',
'factories' => array(
'AsseticBundle\Controller\ConsoleController' => 'AsseticBundle\Controller\ConsoleControllerFactory'
),
),

Expand All @@ -21,13 +21,8 @@
'AsseticBundle\Service' => 'AsseticBundle\ServiceFactory',
'Assetic\AssetWriter' => 'AsseticBundle\WriterFactory',
'AsseticBundle\FilterManager' => 'AsseticBundle\FilterManagerFactory',
),
'invokables' => array(
'Assetic\AssetManager' => 'Assetic\AssetManager',
'AsseticBundle\Listener' => 'AsseticBundle\Listener',
),
'initializers' => array(
'AsseticBundleInitializer' => 'AsseticBundle\Initializer\AsseticBundleInitializer',
'Assetic\AssetManager' => 'Zend\ServiceManager\Factory\InvokableFactory',
'AsseticBundle\Listener' => 'Zend\ServiceManager\Factory\InvokableFactory',
),
),

Expand Down
7 changes: 0 additions & 7 deletions src/AsseticBundle/AsseticBundleServiceAwareInterface.php

This file was deleted.

5 changes: 2 additions & 3 deletions src/AsseticBundle/Controller/ConsoleController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php
namespace AsseticBundle\Controller;

use AsseticBundle\AsseticBundleServiceAwareInterface;
use AsseticBundle\Service;
use Zend\Mvc\Controller\AbstractActionController;

class ConsoleController extends AbstractActionController implements AsseticBundleServiceAwareInterface
class ConsoleController extends AbstractActionController
{
/**
* @var Service
Expand Down Expand Up @@ -55,4 +54,4 @@ public function setAsseticBundleService(Service $service)
{
$this->assetic = $service;
}
}
}
17 changes: 17 additions & 0 deletions src/AsseticBundle/Controller/ConsoleControllerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
namespace AsseticBundle\Controller;

use Interop\Container\ContainerInterface;

use Zend\ServiceManager\Factory\FactoryInterface;

class ConsoleControllerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$instance = new ConsoleController();
$instance->setAsseticBundleService($container->get('AsseticService'));

return $instance;
}
}
17 changes: 15 additions & 2 deletions src/AsseticBundle/FilterManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,32 @@

use AsseticBundle\FilterManager;

use Interop\Container\ContainerInterface;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class FilterManagerFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $locator
* @param ContainerInterface $locator
* @param String $requestedName
* @param Array $options, optional
* @return \AsseticBundle\FilterManager
*/
public function createService(ServiceLocatorInterface $locator)
public function __invoke(ContainerInterface $locator, $requestedName, array $options = null)
{
$filterManager = new FilterManager($locator);

return $filterManager;
}

/**
* @param ServiceLocatorInterface $locator
* @return \AsseticBundle\FilterManager
*/
public function createService(ServiceLocatorInterface $locator)
{
return $this($locator, 'FilterManager');
}
}
27 changes: 0 additions & 27 deletions src/AsseticBundle/Initializer/AsseticBundleInitializer.php

This file was deleted.

23 changes: 18 additions & 5 deletions src/AsseticBundle/ServiceFactory.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php
namespace AsseticBundle;

use Interop\Container\ContainerInterface;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class ServiceFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $locator
* @param ContainerInterface $locator
* @param String $requestedName
* @param Array $options, optional
* @return \AsseticBundle\Service
*/
public function createService(ServiceLocatorInterface $locator)
public function __invoke(ContainerInterface $locator, $requestedName, array $options = null)
{
$asseticConfig = $locator->get('AsseticConfiguration');
if ($asseticConfig->detectBaseUrl()) {
Expand All @@ -22,9 +26,9 @@ public function createService(ServiceLocatorInterface $locator)
}

$asseticService = new Service($asseticConfig);
$asseticService->setAssetManager($locator->get('AsseticAssetManager'));
$asseticService->setAssetWriter($locator->get('AsseticAssetWriter'));
$asseticService->setFilterManager($locator->get('AsseticFilterManager'));
$asseticService->setAssetManager($locator->get('Assetic\AssetManager'));
$asseticService->setAssetWriter($locator->get('Assetic\AssetWriter'));
$asseticService->setFilterManager($locator->get('Assetic\FilterManager'));

// Cache buster is not mandatory
if ($locator->has('AsseticCacheBuster')){
Expand All @@ -33,4 +37,13 @@ public function createService(ServiceLocatorInterface $locator)

return $asseticService;
}

/**
* @param ServiceLocatorInterface $locator
* @return \AsseticBundle\Service
*/
public function createService(ServiceLocatorInterface $locator)
{
return $this($locator, 'AsseticService');
}
}
19 changes: 16 additions & 3 deletions src/AsseticBundle/WriterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@

use Assetic\AssetWriter;

use Interop\Container\ContainerInterface;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class WriterFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $locator
* @return \Assetic\AssetWriter;
* @param ContainerInterface $locator
* @param String $requestedName
* @param Array $options, optional
* @return \AsseticBundle\FilterManager
*/
public function createService(ServiceLocatorInterface $locator)
public function __invoke(ContainerInterface $locator, $requestedName, array $options = null)
{
$asseticConfig = $locator->get('AsseticConfiguration');
$asseticWriter = new AssetWriter($asseticConfig->getWebPath());

return $asseticWriter;
}

/**
* @param ServiceLocatorInterface $locator
* @return \Assetic\AssetWriter;
*/
public function createService(ServiceLocatorInterface $locator)
{
return $this($locator, 'AssetWriter');
}
}