Skip to content

Commit

Permalink
Merge pull request #2 from TomHAnderson/feature/zend-servicemanager-3
Browse files Browse the repository at this point in the history
Update to ZF3
  • Loading branch information
bakura10 authored Jan 4, 2018
2 parents 20855a7 + 070061d commit 540583b
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 45 deletions.
6 changes: 5 additions & 1 deletion Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class Module implements ConfigProviderInterface
*/
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
$configProvider = new ConfigProvider();

return [
'service_manager' => $configProvider->getDependencies(),
];
}
}
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,34 @@ ZfrStripeModule

ZfrStripeModule is a Zend Framework 2 module that integrates with [ZfrStripe](https://github.com/zf-fr/zfr-stripe).


Versions
--------
For zend-servicemanager 2 use version 4.0

For zend-servicemanager 3 and above use version 5.0


Installation
------------

To install ZfrStripeModule, use composer:

```sh
php composer.phar require zfr/zfr-stripe-module:~4.0
$ composer require zfr/zfr-stripe-module ^5.0
```

Enable ZfrStripeModule in your `application.config.php`, then copy the file
`vendor/zfr/zfr-stripe-module/config/zfr_stripe.local.php.dist` to the
`config/autoload` directory of your application (don't forget to remove the
`.dist` extension from the file name!).

> ### zf-component-installer
>
> If you use [zf-component-installer](https://github.com/zendframework/zf-component-installer),
> that plugin will install ZfrStripeModule as a module for you.

Usage
-----

Expand Down
17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@
"require": {
"php": ">=5.4",
"zfr/zfr-stripe": "~3.0",
"zendframework/zend-modulemanager": "~2.0",
"zendframework/zend-servicemanager": "~2.0"
"zendframework/zend-modulemanager": "^2.8",
"zendframework/zend-servicemanager": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "~3.7"
},
"autoload": {
"psr-0": {
"psr-4": {
"ZfrStripeModule\\": "src/"
},
"classmap": [
"./"
]
}
},
"extra": {
"zf": {
"component": "ZfrStripeModule",
"config-provider": "ZfrStripeModule\\ConfigProvider"
}
}
}
25 changes: 0 additions & 25 deletions config/module.config.php

This file was deleted.

22 changes: 22 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace ZfrStripeModule;

class ConfigProvider
{
public function __invoke()
{
return [
'dependencies' => $this->getDependencies(),
];
}

public function getDependencies()
{
return [
'factories' => [
'ZfrStripe\Client\StripeClient' => Factory\StripeClientFactory::class,
],
];
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@

namespace ZfrStripeModule\Factory;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
use ZfrStripe\Client\StripeClient;

/**
* @author Michaël Gallego <mic.gallego@gmail.com>
* @author Michaël Gallego <mic.gallego@gmail.com>
* @licence MIT
*
*/
class StripeClientFactory implements FactoryInterface
class StripeClientFactory implements
FactoryInterface
{
/**
* {@inheritDoc}
* @return StripeClient
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $serviceLocator->get('Config');
$config = $container->get('Config');

if (!isset($config['zfr_stripe'])) {
if (! isset($config['zfr_stripe'])) {
throw new Exception\RuntimeException(
'No config was found for Stripe. Did you copy the `zfr_stripe.local.php` file to your autoload folder?'
);
Expand Down
6 changes: 3 additions & 3 deletions tests/ZfrStripeModuleTest/Factory/StripeClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use ZfrStripe\Client\StripeClient;

/**
* @author Michaël Gallego <mic.gallego@gmail.com>
* @author Michaël Gallego <mic.gallego@gmail.com>
* @licence MIT
*
* @covers \ZfrStripeModule\Factory\StripeClientFactory
Expand All @@ -43,9 +43,9 @@ public function testCanCreateFromFactory()
$serviceManager->setService('Config', $config);

$factory = new StripeClientFactory();
$result = $factory->createService($serviceManager);
$result = $factory($serviceManager, 'ZfrStripe\\Client\\StripeClient');

$this->assertInstanceOf('ZfrStripe\Client\StripeClient', $result);
$this->assertInstanceOf('ZfrStripe\\Client\\StripeClient', $result);
$this->assertEquals(StripeClient::LATEST_API_VERSION, $result->getApiVersion());
}
}

0 comments on commit 540583b

Please sign in to comment.