From 829a58bc2fb59ea7e351feb8eff2979c00b3bfe7 Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 13:08:06 +0300 Subject: [PATCH 01/11] Update composer dependencies. Remove full zend framework. --- .gitignore | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 9 ++++--- 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8f33928 --- /dev/null +++ b/.gitignore @@ -0,0 +1,68 @@ +# Created by .ignore support plugin (hsz.mobi) +### SublimeText template +# cache files for sublime text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# workspace files are user-specific +*.sublime-workspace + +# project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using SublimeText +# *.sublime-project + +# sftp configuration file +sftp-config.json + +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + +### ZendFramework template +# Composer files +composer.phar +vendor/ + +# Local configs +config/autoload/*.local.php + +# Binary gettext files +*.mo + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/ + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +### NetBeans template +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +.nb-gradle/ diff --git a/composer.json b/composer.json index a20b93b..33f2b74 100644 --- a/composer.json +++ b/composer.json @@ -30,13 +30,14 @@ } ], "require": { - "php": ">=5.6", - "zendframework/zend-mail": "~2.0", - "zendframework/zend-http": "~2.0" + "php": "^5.6 || ^7.0", + "zendframework/zend-mail": "^2.6", + "zendframework/zend-http": "^2.5", + "zendframework/zend-mime": "^2.6" }, "require-dev": { "aws/aws-sdk-php-zf2": "~2.0", - "zendframework/zendframework": "~2.0" + "zendframework/zend-servicemanager": "^2.7 || ^3.1" }, "suggest": { "aws/aws-sdk-php-zf2": "If you need to use Amazon SES" From 133571565a8f70633e773541161210b5460bde9c Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 15:01:57 +0300 Subject: [PATCH 02/11] ZF3 compatibility for factories --- .gitignore | 1 + composer.json | 3 +- config/module.config.php | 53 +++++++++---------- .../Factory/ElasticEmailServiceFactory.php | 26 ++++++++- .../Factory/ElasticEmailTransportFactory.php | 25 ++++++++- src/SlmMail/Factory/HttpClientFactory.php | 24 ++++++++- src/SlmMail/Factory/MailgunServiceFactory.php | 26 ++++++++- .../Factory/MailgunTransportFactory.php | 25 ++++++++- .../Factory/MandrillServiceFactory.php | 26 ++++++++- .../Factory/MandrillTransportFactory.php | 25 ++++++++- src/SlmMail/Factory/PostageServiceFactory.php | 26 ++++++++- .../Factory/PostageTransportFactory.php | 25 ++++++++- .../Factory/PostmarkServiceFactory.php | 26 ++++++++- .../Factory/PostmarkTransportFactory.php | 25 ++++++++- .../Factory/SendGridServiceFactory.php | 26 ++++++++- .../Factory/SendGridTransportFactory.php | 25 ++++++++- src/SlmMail/Factory/SesServiceFactory.php | 24 ++++++++- src/SlmMail/Factory/SesTransportFactory.php | 25 ++++++++- 18 files changed, 387 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 8f33928..a152926 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ GitHub.sublime-settings ### ZendFramework template # Composer files composer.phar +composer.lock vendor/ # Local configs diff --git a/composer.json b/composer.json index 33f2b74..0013754 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ }, "require-dev": { "aws/aws-sdk-php-zf2": "~2.0", - "zendframework/zend-servicemanager": "^2.7 || ^3.1" + "zendframework/zend-servicemanager": "^2.7 || ^3.1", + "zendframework/zend-modulemanager": "^2.7" }, "suggest": { "aws/aws-sdk-php-zf2": "If you need to use Amazon SES" diff --git a/config/module.config.php b/config/module.config.php index 22c5e95..43194ac 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -37,40 +37,39 @@ * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://juriansluiman.nl */ +use SlmMail\Factory; +use SlmMail\Service; -return array( - 'service_manager' => array( - 'factories' => array( +return [ + 'service_manager' => [ + 'factories' => [ /** * Transport */ - 'SlmMail\Mail\Transport\ElasticEmailTransport' => 'SlmMail\Factory\ElasticEmailTransportFactory', - 'SlmMail\Mail\Transport\MailgunTransport' => 'SlmMail\Factory\MailgunTransportFactory', - 'SlmMail\Mail\Transport\MandrillTransport' => 'SlmMail\Factory\MandrillTransportFactory', - 'SlmMail\Mail\Transport\PostageTransport' => 'SlmMail\Factory\PostageTransportFactory', - 'SlmMail\Mail\Transport\PostmarkTransport' => 'SlmMail\Factory\PostmarkTransportFactory', - 'SlmMail\Mail\Transport\SendGridTransport' => 'SlmMail\Factory\SendGridTransportFactory', - 'SlmMail\Mail\Transport\SesTransport' => 'SlmMail\Factory\SesTransportFactory', - + 'SlmMail\Mail\Transport\ElasticEmailTransport' => Factory\ElasticEmailTransportFactory::class, + 'SlmMail\Mail\Transport\MailgunTransport' => Factory\MailgunTransportFactory::class, + 'SlmMail\Mail\Transport\MandrillTransport' => Factory\MandrillTransportFactory::class, + 'SlmMail\Mail\Transport\PostageTransport' => Factory\PostageTransportFactory::class, + 'SlmMail\Mail\Transport\PostmarkTransport' => Factory\PostmarkTransportFactory::class, + 'SlmMail\Mail\Transport\SendGridTransport' => Factory\SendGridTransportFactory::class, + 'SlmMail\Mail\Transport\SesTransport' => Factory\SesTransportFactory::class, /** * Services */ - 'SlmMail\Service\ElasticEmailService' => 'SlmMail\Factory\ElasticEmailServiceFactory', - 'SlmMail\Service\MailgunService' => 'SlmMail\Factory\MailgunServiceFactory', - 'SlmMail\Service\MandrillService' => 'SlmMail\Factory\MandrillServiceFactory', - 'SlmMail\Service\PostageService' => 'SlmMail\Factory\PostageServiceFactory', - 'SlmMail\Service\PostmarkService' => 'SlmMail\Factory\PostmarkServiceFactory', - 'SlmMail\Service\SendGridService' => 'SlmMail\Factory\SendGridServiceFactory', - 'SlmMail\Service\SesService' => 'SlmMail\Factory\SesServiceFactory', - + Service\ElasticEmailService::class => Factory\ElasticEmailServiceFactory::class, + Service\MailgunService::class => Factory\MailgunServiceFactory::class, + Service\MandrillService::class => Factory\MandrillServiceFactory::class, + Service\PostageService::class => Factory\PostageServiceFactory::class, + Service\PostmarkService::class => Factory\PostmarkServiceFactory::class, + Service\SendGridService::class => Factory\SendGridServiceFactory::class, + Service\SesService::class => Factory\SesServiceFactory::class, /** * HTTP client */ - 'SlmMail\Http\Client' => 'SlmMail\Factory\HttpClientFactory', - ), - ), - - 'slm_mail' => array( - 'http_adapter' => 'Zend\Http\Client\Adapter\Socket', - ), -); + 'SlmMail\Http\Client' => Factory\HttpClientFactory::class, + ], + ], + 'slm_mail' => [ + 'http_adapter' => \Zend\Http\Client\Adapter\Socket::class, + ], +]; diff --git a/src/SlmMail/Factory/ElasticEmailServiceFactory.php b/src/SlmMail/Factory/ElasticEmailServiceFactory.php index 167aa78..0477dd2 100644 --- a/src/SlmMail/Factory/ElasticEmailServiceFactory.php +++ b/src/SlmMail/Factory/ElasticEmailServiceFactory.php @@ -40,8 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Factory\Exception\RuntimeException; use SlmMail\Service\ElasticEmailService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -52,7 +56,25 @@ class ElasticEmailServiceFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); + return $this($serviceLocator, ElasticEmailService::class); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return ElasticEmailService + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + $config = $container->get('Config'); if (!isset($config['slm_mail']['elastic_email'])) { throw new RuntimeException( @@ -63,7 +85,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) $config = $config['slm_mail']['elastic_email']; $service = new ElasticEmailService($config['username'], $config['key']); - $client = $serviceLocator->get('SlmMail\Http\Client'); + $client = $container->get('SlmMail\Http\Client'); $service->setClient($client); return $service; diff --git a/src/SlmMail/Factory/ElasticEmailTransportFactory.php b/src/SlmMail/Factory/ElasticEmailTransportFactory.php index 0c41574..34f4c5b 100644 --- a/src/SlmMail/Factory/ElasticEmailTransportFactory.php +++ b/src/SlmMail/Factory/ElasticEmailTransportFactory.php @@ -40,7 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Mail\Transport\HttpTransport; +use SlmMail\Service\ElasticEmailService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -51,6 +56,24 @@ class ElasticEmailTransportFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - return new HttpTransport($serviceLocator->get('SlmMail\Service\ElasticEmailService')); + return $this($serviceLocator, 'SlmMail\Mail\Transport\ElasticEmailTransport'); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return HttpTransport + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + return new HttpTransport($container->get(ElasticEmailService::class)); } } diff --git a/src/SlmMail/Factory/HttpClientFactory.php b/src/SlmMail/Factory/HttpClientFactory.php index c410766..6c8141a 100644 --- a/src/SlmMail/Factory/HttpClientFactory.php +++ b/src/SlmMail/Factory/HttpClientFactory.php @@ -40,7 +40,11 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use Zend\Http\Client as HttpClient; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -51,7 +55,25 @@ class HttpClientFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); + return $this($serviceLocator, 'SlmMail\Http\Client'); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return object + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + $config = $container->get('Config'); $client = new HttpClient(); $client->setAdapter($config['slm_mail']['http_adapter']); diff --git a/src/SlmMail/Factory/MailgunServiceFactory.php b/src/SlmMail/Factory/MailgunServiceFactory.php index f38e069..d4fcc70 100644 --- a/src/SlmMail/Factory/MailgunServiceFactory.php +++ b/src/SlmMail/Factory/MailgunServiceFactory.php @@ -40,8 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Factory\Exception\RuntimeException; use SlmMail\Service\MailgunService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -52,7 +56,25 @@ class MailgunServiceFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); + return $this($serviceLocator, MailgunService::class); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return MailgunService + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + $config = $container->get('Config'); if (!isset($config['slm_mail']['mailgun'])) { throw new RuntimeException( @@ -63,7 +85,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) $config = $config['slm_mail']['mailgun']; $service = new MailgunService($config['domain'], $config['key']); - $client = $serviceLocator->get('SlmMail\Http\Client'); + $client = $container->get('SlmMail\Http\Client'); $service->setClient($client); return $service; diff --git a/src/SlmMail/Factory/MailgunTransportFactory.php b/src/SlmMail/Factory/MailgunTransportFactory.php index 33841ad..356264d 100644 --- a/src/SlmMail/Factory/MailgunTransportFactory.php +++ b/src/SlmMail/Factory/MailgunTransportFactory.php @@ -40,7 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Mail\Transport\HttpTransport; +use SlmMail\Service\MailgunService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -51,6 +56,24 @@ class MailgunTransportFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - return new HttpTransport($serviceLocator->get('SlmMail\Service\MailgunService')); + return $this($serviceLocator, 'SlmMail\Mail\Transport\MailgunTransport'); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return HttpTransport + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + return new HttpTransport($container->get(MailgunService::class)); } } diff --git a/src/SlmMail/Factory/MandrillServiceFactory.php b/src/SlmMail/Factory/MandrillServiceFactory.php index 25fd38f..442f9a9 100644 --- a/src/SlmMail/Factory/MandrillServiceFactory.php +++ b/src/SlmMail/Factory/MandrillServiceFactory.php @@ -40,8 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Factory\Exception\RuntimeException; use SlmMail\Service\MandrillService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -52,7 +56,25 @@ class MandrillServiceFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); + return $this($serviceLocator, MandrillService::class); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return MandrillService + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + $config = $container->get('Config'); if (!isset($config['slm_mail']['mandrill'])) { throw new RuntimeException( @@ -62,7 +84,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) $service = new MandrillService($config['slm_mail']['mandrill']['key']); - $client = $serviceLocator->get('SlmMail\Http\Client'); + $client = $container->get('SlmMail\Http\Client'); $service->setClient($client); return $service; diff --git a/src/SlmMail/Factory/MandrillTransportFactory.php b/src/SlmMail/Factory/MandrillTransportFactory.php index a380060..f104347 100644 --- a/src/SlmMail/Factory/MandrillTransportFactory.php +++ b/src/SlmMail/Factory/MandrillTransportFactory.php @@ -40,7 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Mail\Transport\HttpTransport; +use SlmMail\Service\MandrillService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -51,6 +56,24 @@ class MandrillTransportFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - return new HttpTransport($serviceLocator->get('SlmMail\Service\MandrillService')); + return $this($serviceLocator, 'SlmMail\Mail\Transport\MandrillTransport'); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return HttpTransport + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + return new HttpTransport($container->get(MandrillService::class)); } } diff --git a/src/SlmMail/Factory/PostageServiceFactory.php b/src/SlmMail/Factory/PostageServiceFactory.php index 1c988b7..4ce3562 100644 --- a/src/SlmMail/Factory/PostageServiceFactory.php +++ b/src/SlmMail/Factory/PostageServiceFactory.php @@ -40,8 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Factory\Exception\RuntimeException; use SlmMail\Service\PostageService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -52,7 +56,25 @@ class PostageServiceFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); + return $this($serviceLocator, PostageService::class); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return PostageService + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + $config = $container->get('Config'); if (!isset($config['slm_mail']['postage'])) { throw new RuntimeException( 'Config for Postage is not set, did you copy config file into your config/autoload folder ?' @@ -61,7 +83,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) $service = new PostageService($config['slm_mail']['postage']['key']); - $client = $serviceLocator->get('SlmMail\Http\Client'); + $client = $container->get('SlmMail\Http\Client'); $service->setClient($client); return $service; diff --git a/src/SlmMail/Factory/PostageTransportFactory.php b/src/SlmMail/Factory/PostageTransportFactory.php index 782fc7b..89f5246 100644 --- a/src/SlmMail/Factory/PostageTransportFactory.php +++ b/src/SlmMail/Factory/PostageTransportFactory.php @@ -40,7 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Mail\Transport\HttpTransport; +use SlmMail\Service\PostageService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -51,6 +56,24 @@ class PostageTransportFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - return new HttpTransport($serviceLocator->get('SlmMail\Service\PostageService')); + return $this($serviceLocator, 'SlmMail\Mail\Transport\PostageTransport'); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return HttpTransport + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + return new HttpTransport($container->get(PostageService::class)); } } diff --git a/src/SlmMail/Factory/PostmarkServiceFactory.php b/src/SlmMail/Factory/PostmarkServiceFactory.php index 372d9db..385405f 100644 --- a/src/SlmMail/Factory/PostmarkServiceFactory.php +++ b/src/SlmMail/Factory/PostmarkServiceFactory.php @@ -40,8 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Factory\Exception\RuntimeException; use SlmMail\Service\PostmarkService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -52,7 +56,25 @@ class PostmarkServiceFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); + return $this($serviceLocator, PostmarkService::class); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return PostmarkService + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + $config = $container->get('Config'); if (!isset($config['slm_mail']['postmark'])) { throw new RuntimeException( @@ -62,7 +84,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) $service = new PostmarkService($config['slm_mail']['postmark']['key']); - $client = $serviceLocator->get('SlmMail\Http\Client'); + $client = $container->get('SlmMail\Http\Client'); $service->setClient($client); return $service; diff --git a/src/SlmMail/Factory/PostmarkTransportFactory.php b/src/SlmMail/Factory/PostmarkTransportFactory.php index 4a7013b..8f79202 100644 --- a/src/SlmMail/Factory/PostmarkTransportFactory.php +++ b/src/SlmMail/Factory/PostmarkTransportFactory.php @@ -40,7 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Mail\Transport\HttpTransport; +use SlmMail\Service\PostmarkService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -51,6 +56,24 @@ class PostmarkTransportFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - return new HttpTransport($serviceLocator->get('SlmMail\Service\PostmarkService')); + return $this($serviceLocator, 'SlmMail\Mail\Transport\PostmarkTransport'); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return HttpTransport + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + return new HttpTransport($container->get(PostmarkService::class)); } } diff --git a/src/SlmMail/Factory/SendGridServiceFactory.php b/src/SlmMail/Factory/SendGridServiceFactory.php index 1c02386..18713e4 100644 --- a/src/SlmMail/Factory/SendGridServiceFactory.php +++ b/src/SlmMail/Factory/SendGridServiceFactory.php @@ -40,8 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Factory\Exception\RuntimeException; use SlmMail\Service\SendGridService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -52,7 +56,25 @@ class SendGridServiceFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); + return $this($serviceLocator, SendGridService::class); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return SendGridService + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + $config = $container->get('Config'); if (!isset($config['slm_mail']['send_grid'])) { throw new RuntimeException( @@ -63,7 +85,7 @@ public function createService(ServiceLocatorInterface $serviceLocator) $config = $config['slm_mail']['send_grid']; $service = new SendGridService($config['username'], $config['key']); - $client = $serviceLocator->get('SlmMail\Http\Client'); + $client = $container->get('SlmMail\Http\Client'); $service->setClient($client); return $service; diff --git a/src/SlmMail/Factory/SendGridTransportFactory.php b/src/SlmMail/Factory/SendGridTransportFactory.php index c1a54f7..508113b 100644 --- a/src/SlmMail/Factory/SendGridTransportFactory.php +++ b/src/SlmMail/Factory/SendGridTransportFactory.php @@ -40,7 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Mail\Transport\HttpTransport; +use SlmMail\Service\SendGridService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -51,6 +56,24 @@ class SendGridTransportFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - return new HttpTransport($serviceLocator->get('SlmMail\Service\SendGridService')); + return $this($serviceLocator, 'SlmMail\Mail\Transport\SendGridTransport'); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return HttpTransport + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + return new HttpTransport($container->get(SendGridService::class)); } } diff --git a/src/SlmMail/Factory/SesServiceFactory.php b/src/SlmMail/Factory/SesServiceFactory.php index 08526ca..de04a61 100644 --- a/src/SlmMail/Factory/SesServiceFactory.php +++ b/src/SlmMail/Factory/SesServiceFactory.php @@ -40,7 +40,11 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Service\SesService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; use Aws\Sdk; @@ -52,6 +56,24 @@ class SesServiceFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - return new SesService($serviceLocator->get(Sdk::class)->createSes()); + return $this($serviceLocator, SesService::class); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return SesService + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + return new SesService($container->get(Sdk::class)->createSes()); } } diff --git a/src/SlmMail/Factory/SesTransportFactory.php b/src/SlmMail/Factory/SesTransportFactory.php index 69f0800..038be4e 100644 --- a/src/SlmMail/Factory/SesTransportFactory.php +++ b/src/SlmMail/Factory/SesTransportFactory.php @@ -40,7 +40,12 @@ namespace SlmMail\Factory; +use Interop\Container\ContainerInterface; +use Interop\Container\Exception\ContainerException; use SlmMail\Mail\Transport\HttpTransport; +use SlmMail\Service\SesService; +use Zend\ServiceManager\Exception\ServiceNotCreatedException; +use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -51,6 +56,24 @@ class SesTransportFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - return new HttpTransport($serviceLocator->get('SlmMail\Service\SesService')); + return $this($serviceLocator, 'SlmMail\Mail\Transport\SesTransport'); + } + + /** + * Create an object + * + * @param ContainerInterface $container + * @param string $requestedName + * @param null|array $options + * + * @return HttpTransport + * @throws ServiceNotFoundException if unable to resolve the service. + * @throws ServiceNotCreatedException if an exception is raised when + * creating a service. + * @throws ContainerException if any other error occurs + */ + public function __invoke(ContainerInterface $container, $requestedName, array $options = null) + { + return new HttpTransport($container->get(SesService::class)); } } From 9330a6559610377e14dd1393347dba757826ba68 Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 15:11:44 +0300 Subject: [PATCH 03/11] Update README --- CHANGELOG.md | 7 +++++++ README.md | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d91f8af..e26e631 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ # CHANGELOG +## 2.1.0 +- Added ZF3 support +-- which allow install zend-servicemanager both versions v2 or v3 by composer +- Updated & reduced composer dependencies (dropped install full ZF2 framework) +- Small PHP syntax's fixes & added gitignore file + + ## 2.0.0 - bump to aws-sdk-for-php ZF2 module to 2.* -- which in turn bumps support to AWS SDK for PHP v3 diff --git a/README.md b/README.md index ddc4ebc..50a524f 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Requirements ------------ * PHP 5.6 -* [Zend Framework 2](https://github.com/zendframework/zf2) +* [Zend Framework 2](https://github.com/zendframework/zf2) OR [ZF3 components](https://docs.zendframework.com/tutorials/) * [Amazon AWS ZF 2 Module](https://github.com/aws/aws-sdk-php-zf2): only if you plan to use Amazon SES service Installation From 672a4e94d265f3e3d7e644f269edbe8be0377104 Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 15:40:59 +0300 Subject: [PATCH 04/11] MVC as dependencies for tests --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0013754..b491340 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "require-dev": { "aws/aws-sdk-php-zf2": "~2.0", "zendframework/zend-servicemanager": "^2.7 || ^3.1", - "zendframework/zend-modulemanager": "^2.7" + "zendframework/zend-modulemanager": "^2.7", + "zendframework/zend-mvc": "^2.7 || ^3.0" }, "suggest": { "aws/aws-sdk-php-zf2": "If you need to use Amazon SES" From 07a10a2e57161671ae4048f3ecdd7c17b82bc56e Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 16:18:54 +0300 Subject: [PATCH 05/11] Fix for unit tests: work under both versions ServiceManager --- tests/SlmMailTest/Util/ServiceManagerFactory.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/SlmMailTest/Util/ServiceManagerFactory.php b/tests/SlmMailTest/Util/ServiceManagerFactory.php index eb9fda3..7c6f683 100644 --- a/tests/SlmMailTest/Util/ServiceManagerFactory.php +++ b/tests/SlmMailTest/Util/ServiceManagerFactory.php @@ -70,9 +70,14 @@ public static function setConfig(array $config) */ public static function getServiceManager() { - $serviceManager = new ServiceManager(new ServiceManagerConfig( + $serviceConfig = new ServiceManagerConfig( isset(static::$config['service_manager']) ? static::$config['service_manager'] : array() - )); + ); + // If this ServiceManager v3 then __constructor signature pass array instead object + if (method_exists(new ServiceManager(), 'configure')) { + $serviceConfig = $serviceConfig->toArray(); + } + $serviceManager = new ServiceManager($serviceConfig); $serviceManager->setService('ApplicationConfig', static::$config); //$serviceManager->setFactory('ServiceListener', 'Zend\Mvc\Service\ServiceListenerFactory'); From 686116412b9297bd31279f0a1e22646c53ed4a14 Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 17:40:20 +0300 Subject: [PATCH 06/11] Pass unit tests and test in travis both ZF versions --- .travis.yml | 27 ++++++++++++++++--- composer.json | 8 +++++- .../Util/ServiceManagerFactory.php | 9 +++++-- tests/TestConfiguration.php.dist | 4 ++- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 10f717a..8682db1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,34 @@ language: php -php: - - 5.6 - - 7.0 +matrix: + fast_finish: true + include: + - php: 5.6 + env: + - DEPS=lowest + - php: 5.6 + env: + - DEPS=latest + - php: 7.0 + env: + - DEPS=lowest + - php: 7.0 + env: + - DEPS=latest +env: + global: + - COMPOSER_ARGS="--no-interaction --ignore-platform-reqs" cache: directories: - $HOME/.composer/cache -before_script: +install: + - if [[ $DEPS == 'latest' ]]; then travis_retry composer update --prefer-stable --prefer-source $COMPOSER_ARGS ; fi + - if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable --prefer-source $COMPOSER_ARGS ; fi - composer install --dev --prefer-source + - travis_retry composer install --dev $COMPOSER_ARGS + - composer show --installed script: - phpunit --configuration tests/phpunit.xml diff --git a/composer.json b/composer.json index b491340..496df09 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,13 @@ "aws/aws-sdk-php-zf2": "~2.0", "zendframework/zend-servicemanager": "^2.7 || ^3.1", "zendframework/zend-modulemanager": "^2.7", - "zendframework/zend-mvc": "^2.7 || ^3.0" + "zendframework/zend-mvc": "^2.7 || ^3.0", + "zendframework/zend-view": "^2.6", + "zendframework/zend-log": "^2.6", + "zendframework/zend-i18n": "^2.6", + "zendframework/zend-serializer": "^2.6", + "zendframework/zend-config": "^2.6", + "phpunit/phpunit": "^5.5" }, "suggest": { "aws/aws-sdk-php-zf2": "If you need to use Amazon SES" diff --git a/tests/SlmMailTest/Util/ServiceManagerFactory.php b/tests/SlmMailTest/Util/ServiceManagerFactory.php index 7c6f683..bd681e2 100644 --- a/tests/SlmMailTest/Util/ServiceManagerFactory.php +++ b/tests/SlmMailTest/Util/ServiceManagerFactory.php @@ -62,6 +62,11 @@ class ServiceManagerFactory */ public static function setConfig(array $config) { + // If this MVC v3 then used Zend\Router module instead Zend\Mvc\Router + if (class_exists(\Zend\Router\Module::class)) { + $config['modules'][] = 'Zend\\Router'; + } + //die(print_r($config,true)); static::$config = $config; } @@ -80,11 +85,11 @@ public static function getServiceManager() $serviceManager = new ServiceManager($serviceConfig); $serviceManager->setService('ApplicationConfig', static::$config); //$serviceManager->setFactory('ServiceListener', 'Zend\Mvc\Service\ServiceListenerFactory'); - + $serviceManager->setAllowOverride(true); /** @var $moduleManager \Zend\ModuleManager\ModuleManager */ $moduleManager = $serviceManager->get('ModuleManager'); $moduleManager->loadModules(); - //$serviceManager->setAllowOverride(true); + return $serviceManager; } } diff --git a/tests/TestConfiguration.php.dist b/tests/TestConfiguration.php.dist index 1aeb7b8..ddcd1fc 100644 --- a/tests/TestConfiguration.php.dist +++ b/tests/TestConfiguration.php.dist @@ -25,6 +25,8 @@ return array( 'config_glob_paths' => array( __DIR__ . '/testing.config.php', ), - 'module_paths' => array(), + 'module_paths' => array( + 'vendor/', + ), ), ); From f4a78c6aca3b29b3745141f6e8a236e3e77d6a04 Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 18:05:06 +0300 Subject: [PATCH 07/11] Fix for lowest composer dependencies --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 496df09..489ea23 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ }, "require-dev": { "aws/aws-sdk-php-zf2": "~2.0", + "container-interop/container-interop": "^1.1", "zendframework/zend-servicemanager": "^2.7 || ^3.1", "zendframework/zend-modulemanager": "^2.7", "zendframework/zend-mvc": "^2.7 || ^3.0", From 52483300141133c25746d143bfcf5a49c577f5cf Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 18:29:13 +0300 Subject: [PATCH 08/11] Fix for lowest composer dependencies with PHP7 --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 489ea23..3455dd2 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ "zendframework/zend-i18n": "^2.6", "zendframework/zend-serializer": "^2.6", "zendframework/zend-config": "^2.6", + "doctrine/instantiator": "^1.0.5", "phpunit/phpunit": "^5.5" }, "suggest": { From 7073499207ac71b01b97929a9b68ef0717860b98 Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 18:50:01 +0300 Subject: [PATCH 09/11] Clean up git ignore file --- .gitignore | 67 +----------------------------------------------------- 1 file changed, 1 insertion(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index a152926..75d5aeb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,69 +1,4 @@ -# Created by .ignore support plugin (hsz.mobi) -### SublimeText template -# cache files for sublime text -*.tmlanguage.cache -*.tmPreferences.cache -*.stTheme.cache - -# workspace files are user-specific -*.sublime-workspace - -# project files should be checked into the repository, unless a significant -# proportion of contributors will probably not be using SublimeText -# *.sublime-project - -# sftp configuration file -sftp-config.json - -bh_unicode_properties.cache - -# Sublime-github package stores a github token in this file -# https://packagecontrol.io/packages/sublime-github -GitHub.sublime-settings - -### ZendFramework template -# Composer files composer.phar composer.lock vendor/ - -# Local configs -config/autoload/*.local.php - -# Binary gettext files -*.mo - -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/ - -## File-based project format: -*.iws - -## Plugin-specific files: - -# IntelliJ -/out/ - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties -### NetBeans template -nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -nbactions.xml -.nb-gradle/ +.idea/ \ No newline at end of file From 13336cf4e5ba841f0c3c321a8e9366c2b63f1f1e Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 18:58:49 +0300 Subject: [PATCH 10/11] Clean up debug --- tests/SlmMailTest/Util/ServiceManagerFactory.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/SlmMailTest/Util/ServiceManagerFactory.php b/tests/SlmMailTest/Util/ServiceManagerFactory.php index bd681e2..0089c1a 100644 --- a/tests/SlmMailTest/Util/ServiceManagerFactory.php +++ b/tests/SlmMailTest/Util/ServiceManagerFactory.php @@ -66,7 +66,6 @@ public static function setConfig(array $config) if (class_exists(\Zend\Router\Module::class)) { $config['modules'][] = 'Zend\\Router'; } - //die(print_r($config,true)); static::$config = $config; } From d45ae3bdfe67a55597ffc4da405a26d936db02cd Mon Sep 17 00:00:00 2001 From: Alexandr Vronskiy Date: Mon, 10 Oct 2016 20:03:21 +0300 Subject: [PATCH 11/11] Added service manager as main dependency --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3455dd2..00b2232 100644 --- a/composer.json +++ b/composer.json @@ -33,12 +33,12 @@ "php": "^5.6 || ^7.0", "zendframework/zend-mail": "^2.6", "zendframework/zend-http": "^2.5", - "zendframework/zend-mime": "^2.6" + "zendframework/zend-mime": "^2.6", + "zendframework/zend-servicemanager": "^2.7 || ^3.1" }, "require-dev": { "aws/aws-sdk-php-zf2": "~2.0", "container-interop/container-interop": "^1.1", - "zendframework/zend-servicemanager": "^2.7 || ^3.1", "zendframework/zend-modulemanager": "^2.7", "zendframework/zend-mvc": "^2.7 || ^3.0", "zendframework/zend-view": "^2.6",