Skip to content

Commit

Permalink
Merge pull request #21 from thomasvargiu/feature/zf2compat
Browse files Browse the repository at this point in the history
ZF2 Compatibility
  • Loading branch information
neeckeloo authored Sep 2, 2016
2 parents 7fc4e2c + fa19115 commit b1a9905
Show file tree
Hide file tree
Showing 24 changed files with 165 additions and 45 deletions.
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
"require": {
"php": "^5.6 || ^7.0",
"container-interop/container-interop": "^1.1.0",
"monolog/monolog": "~1.17",
"zendframework/zend-console": "~2.6",
"zendframework/zend-eventmanager": "~3.0",
"zendframework/zend-http": "~2.5",
"zendframework/zend-mvc": "~3.0",
"zendframework/zend-stdlib": "~3.0"
"monolog/monolog": "^1.17",
"zendframework/zend-console": "^2.6",
"zendframework/zend-eventmanager": "^2.6 || ^3.0",
"zendframework/zend-servicemanager": "^2.7 || ^3.0",
"zendframework/zend-http": "^2.5",
"zendframework/zend-mvc": "^2.7 || ^3.0",
"zendframework/zend-stdlib": "^2.7 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "~5.4",
"phpunit/phpunit": "^5.4",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
Expand Down
17 changes: 15 additions & 2 deletions src/Factory/BackgroundJobListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
use Interop\Container\ContainerInterface;
use NewRelic\Listener\BackgroundJobListener;
use NewRelic\TransactionMatcher;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class BackgroundJobListenerFactory
class BackgroundJobListenerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$client = $container->get('NewRelic\Client');
$options = $container->get('NewRelic\ModuleOptions');
$transactionMatcher = new TransactionMatcher($options->getBackgroundJobs());

return new BackgroundJobListener($client, $options, $transactionMatcher);
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return BackgroundJobListener
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, BackgroundJobListener::class);
}
}
17 changes: 15 additions & 2 deletions src/Factory/ErrorListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@

use Interop\Container\ContainerInterface;
use NewRelic\Listener\ErrorListener;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class ErrorListenerFactory
class ErrorListenerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$client = $container->get('NewRelic\Client');
$options = $container->get('NewRelic\ModuleOptions');
$logger = $container->get('NewRelic\Logger');

return new ErrorListener($client, $options, $logger);
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return ErrorListener
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, ErrorListener::class);
}
}
17 changes: 15 additions & 2 deletions src/Factory/IgnoreApdexListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
use Interop\Container\ContainerInterface;
use NewRelic\Listener\IgnoreApdexListener;
use NewRelic\TransactionMatcher;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class IgnoreApdexListenerFactory
class IgnoreApdexListenerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$client = $container->get('NewRelic\Client');
$options = $container->get('NewRelic\ModuleOptions');
$transactionMatcher = new TransactionMatcher($options->getIgnoredApdex());

return new IgnoreApdexListener($client, $options, $transactionMatcher);
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return IgnoreApdexListener
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, IgnoreApdexListener::class);
}
}
17 changes: 15 additions & 2 deletions src/Factory/IgnoreTransactionListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
use Interop\Container\ContainerInterface;
use NewRelic\Listener\IgnoreTransactionListener;
use NewRelic\TransactionMatcher;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class IgnoreTransactionListenerFactory
class IgnoreTransactionListenerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$client = $container->get('NewRelic\Client');
$options = $container->get('NewRelic\ModuleOptions');
$transactionMatcher = new TransactionMatcher($options->getIgnoredTransactions());

return new IgnoreTransactionListener($client, $options, $transactionMatcher);
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return IgnoreTransactionListener
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, IgnoreTransactionListener::class);
}
}
18 changes: 16 additions & 2 deletions src/Factory/LoggerFactory.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
<?php
namespace NewRelic\Factory;

use Interop\Container\ContainerInterface;
use Monolog\Logger;
use Monolog\Handler\NewRelicHandler;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class LoggerFactory
class LoggerFactory implements FactoryInterface
{
public function __invoke()
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$logger = new Logger('newrelic');
$logger->pushHandler(new NewRelicHandler());

return $logger;
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return Logger
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, Logger::class);
}
}
17 changes: 15 additions & 2 deletions src/Factory/ModuleOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
use Interop\Container\ContainerInterface;
use NewRelic\Exception\RuntimeException;
use NewRelic\ModuleOptions;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class ModuleOptionsFactory
class ModuleOptionsFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('Config');

Expand All @@ -19,4 +21,15 @@ public function __invoke(ContainerInterface $container)

return new ModuleOptions($config['newrelic']);
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return ModuleOptions
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, ModuleOptions::class);
}
}
17 changes: 15 additions & 2 deletions src/Factory/RequestListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@

use Interop\Container\ContainerInterface;
use NewRelic\Listener\RequestListener;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class RequestListenerFactory
class RequestListenerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$client = $container->get('NewRelic\Client');
$options = $container->get('NewRelic\ModuleOptions');

return new RequestListener($client, $options);
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return RequestListener
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, RequestListener::class);
}
}
17 changes: 15 additions & 2 deletions src/Factory/ResponseListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@

use Interop\Container\ContainerInterface;
use NewRelic\Listener\ResponseListener;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class ResponseListenerFactory
class ResponseListenerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$client = $container->get('NewRelic\Client');
$options = $container->get('NewRelic\ModuleOptions');

return new ResponseListener($client, $options);
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return ResponseListener
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, ResponseListener::class);
}
}
2 changes: 1 addition & 1 deletion src/Listener/AbstractTransactionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public function __construct(
*/
protected function isMatchedRequest(MvcEvent $e)
{
return $this->transactionMatcher->isMatched($e->getRouteMatch());
return $this->transactionMatcher->isMatched($e);
}
}
3 changes: 2 additions & 1 deletion src/Listener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Zend\EventManager\EventManagerInterface as Events;
use Zend\Mvc\MvcEvent;
use Zend\Router\RouteMatch;
use Zend\Mvc\Router\RouteMatch as RouteMatchV2;

class RequestListener extends AbstractListener
{
Expand All @@ -29,7 +30,7 @@ public function onRequest(MvcEvent $e)
}

$matches = $e->getRouteMatch();
if ($matches instanceof RouteMatch) {
if ($matches instanceof RouteMatch || $matches instanceof RouteMatchV2) {
$route = $matches->getMatchedRouteName();
$this->client->nameTransaction($route);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace NewRelic;

use Zend\EventManager\ListenerAggregateInterface;
use Zend\Loader\StandardAutoloader;
use Zend\Mvc\MvcEvent;

Expand Down Expand Up @@ -37,8 +38,9 @@ public function onBootstrap(MvcEvent $e)

$moduleOptions = $serviceManager->get(ModuleOptions::class);
foreach ($moduleOptions->getListeners() as $service) {
/** @var ListenerAggregateInterface $listener */
$listener = $serviceManager->get($service);
$eventManager->attach($listener);
$listener->attach($eventManager);
}
}
}
7 changes: 4 additions & 3 deletions src/TransactionMatcher.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace NewRelic;

use Zend\Router\RouteMatch;
use Zend\Mvc\MvcEvent;

class TransactionMatcher implements TransactionMatcherInterface
{
Expand All @@ -16,11 +16,12 @@ public function __construct(array $transactions)
}

/**
* @param RouteMatch $routeMatch
* @param MvcEvent $mvcEvent
* @return bool
*/
public function isMatched(RouteMatch $routeMatch)
public function isMatched(MvcEvent $mvcEvent)
{
$routeMatch = $mvcEvent->getRouteMatch();
$matchedRouteName = $routeMatch->getMatchedRouteName();
if ($this->isRouteMatched($matchedRouteName)) {
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/TransactionMatcherInterface.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
namespace NewRelic;

use Zend\Router\RouteMatch;
use Zend\Mvc\MvcEvent;

interface TransactionMatcherInterface
{
/**
* @param RouteMatch $routeMatch
* @param MvcEvent $mvcEvent
* @return bool
*/
public function isMatched(RouteMatch $routeMatch);
public function isMatched(MvcEvent $mvcEvent);
}
2 changes: 1 addition & 1 deletion tests/Factory/BackgroundJobListenerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testCreateService()
);
$backgroundJobListenerFactory = new BackgroundJobListenerFactory();

$listener = $backgroundJobListenerFactory($container->reveal());
$listener = $backgroundJobListenerFactory($container->reveal(), BackgroundJobListener::class);

$this->assertInstanceOf(BackgroundJobListener::class, $listener);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Factory/ErrorListenerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testCreateService()
);
$errorListenerFactory = new ErrorListenerFactory();

$listener = $errorListenerFactory($container->reveal());
$listener = $errorListenerFactory($container->reveal(), ErrorListener::class);

$this->assertInstanceOf(ErrorListener::class, $listener);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Factory/IgnoreApdexListenerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testCreateService()
);
$ignoreApdexListenerFactory = new IgnoreApdexListenerFactory();

$listener = $ignoreApdexListenerFactory($container->reveal());
$listener = $ignoreApdexListenerFactory($container->reveal(), IgnoreApdexListener::class);

$this->assertInstanceOf(IgnoreApdexListener::class, $listener);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Factory/IgnoreTransactionListenerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testCreateService()
);
$ignoreTransactionListenerFactory = new IgnoreTransactionListenerFactory();

$listener = $ignoreTransactionListenerFactory($container->reveal());
$listener = $ignoreTransactionListenerFactory($container->reveal(), IgnoreTransactionListener::class);
$this->assertInstanceOf(IgnoreTransactionListener::class, $listener);
}

Expand Down
Loading

0 comments on commit b1a9905

Please sign in to comment.