diff --git a/Readme.md b/Readme.md index 791b61d1e..ac0862dae 100755 --- a/Readme.md +++ b/Readme.md @@ -12,14 +12,33 @@ Here is the most recent developed code for the next major version (v2). You can Most part of the code can possibly change, a large part will be refactor soon, graphical setup does not exist yet. +Requirements +------------ + +* php 5.4 +* apache 2 +* mysql 5 + +If you use Mac OSX, it still doesn't use php 5.4 as default php version... There are many solutions for you : + +* use linux (the best one) +* use last MAMP version and put the php bin directory in your path : + +```bash +export PATH=/Applications/MAMP/bin/php/php5.4.x/bin/:$PATH +``` + +* configure a complete development environment : http://php-osx.liip.ch/ +* use a virtual machine with vagrant and puppet : https://puphpet.com/ + Installation ------------ ``` bash $ git clone --recursive https://github.com/thelia/thelia.git $ cd thelia -$ wget http://getcomposer.org/composer.phar -$ php composer.phar install +$ curl -sS https://getcomposer.org/installer | php +$ php composer.phar install --optimize-autoloader ``` Finish the installation using cli tools : diff --git a/composer.json b/composer.json index 2d315bd3a..4a3798384 100755 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ "simplepie/simplepie": "dev-master", "imagine/imagine": "dev-master", - "symfony/icu": "1.0" + "symfony/icu": "1.0", + "swiftmailer/swiftmailer": "5.0.*" }, "require-dev" : { "phpunit/phpunit": "3.7.*", @@ -53,9 +54,5 @@ "": "local/modules/", "Thelia" : "core/lib/" } - }, - "scripts" : { - "post-update-cmd": "composer dump-autoload -o", - "post-install-cmd": "composer dump-autoload -o" } } diff --git a/composer.lock b/composer.lock index 61160ea49..b0310c075 100755 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "28dfdc7a840f9e70df422581f82a871f", + "hash": "a40be01c82e68ba0c446dc204d2667da", "packages": [ { "name": "imagine/imagine", @@ -445,6 +445,55 @@ ], "time": "2013-07-02 16:38:47" }, + { + "name": "swiftmailer/swiftmailer", + "version": "v5.0.2", + "source": { + "type": "git", + "url": "https://github.com/swiftmailer/swiftmailer.git", + "reference": "f3917ecef35a4e4d98b303eb9fee463bc983f379" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/f3917ecef35a4e4d98b303eb9fee463bc983f379", + "reference": "f3917ecef35a4e4d98b303eb9fee463bc983f379", + "shasum": "" + }, + "require": { + "php": ">=5.2.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "files": [ + "lib/swift_required.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Chris Corbyn" + } + ], + "description": "Swiftmailer, free feature-rich PHP mailer", + "homepage": "http://swiftmailer.org", + "keywords": [ + "mail", + "mailer" + ], + "time": "2013-08-30 12:35:21" + }, { "name": "symfony-cmf/routing", "version": "1.0.0", diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 0c0973db9..2a344bad9 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -267,6 +267,10 @@ + + + + diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 19e62a400..3c4c0a5bc 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -281,4 +281,16 @@ class BaseController extends ContainerAware $this->accessDenied(); } } + + /** + * + * return an instance of \Swift_Mailer with good Transporter configured. + * + * @return \Swift_Mailer + */ + public function getMailer() + { + $mailer = $this->container->get('mailer'); + return $mailer->getSwiftMailer(); + } } diff --git a/core/lib/Thelia/Core/Event/MailTransporterEvent.php b/core/lib/Thelia/Core/Event/MailTransporterEvent.php new file mode 100644 index 000000000..d47ac693f --- /dev/null +++ b/core/lib/Thelia/Core/Event/MailTransporterEvent.php @@ -0,0 +1,52 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\Event; + + +/** + * Class MailTransporterEvent + * @package Thelia\Core\Event + * @author Manuel Raynaud + */ +class MailTransporterEvent extends ActionEvent { + /** + * @var \Swift_Transport + */ + protected $transporter; + + public function setMailerTransporter(\Swift_Transport $transporter) + { + $this->transporter = $transporter; + } + + public function getTransporter() + { + return $this->transporter; + } + + public function hasTransporter() + { + return null !== $this->transporter; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Event/TheliaEvents.php b/core/lib/Thelia/Core/Event/TheliaEvents.php index a305f134a..ffa87f11c 100755 --- a/core/lib/Thelia/Core/Event/TheliaEvents.php +++ b/core/lib/Thelia/Core/Event/TheliaEvents.php @@ -401,4 +401,9 @@ final class TheliaEvents const BEFORE_DELETEFEATURE_AV = "action.before_deleteFeatureAv"; const AFTER_DELETEFEATURE_AV = "action.after_deleteFeatureAv"; + /** + * sent when system find a mailer transporter. + */ + const MAILTRANSPORTER_CONFIG = 'action.mailertransporter.config'; + } diff --git a/core/lib/Thelia/Mailer/MailerFactory.php b/core/lib/Thelia/Mailer/MailerFactory.php new file mode 100644 index 000000000..5cd952270 --- /dev/null +++ b/core/lib/Thelia/Mailer/MailerFactory.php @@ -0,0 +1,91 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Mailer; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Thelia\Core\Event\MailTransporterEvent; +use Thelia\Core\Event\TheliaEvents; +use Thelia\Model\ConfigQuery; + + +/** + * Class MailerFactory + * @package Thelia\Mailer + * @author Manuel Raynaud + */ +class MailerFactory { + /** + * @var \Swift_Mailer + */ + protected $swiftMailer; + + protected $dispatcher; + + public function _construct(EventDispatcherInterface $dispatcher) + { + + $this->dispatcher = $dispatcher; + + $transporterEvent = new MailTransporterEvent(); + $this->dispatcher->dispatch(TheliaEvents::MAILTRANSPORTER_CONFIG, $transporterEvent); + + if($transporterEvent->hasTransporter()) { + $transporter = $transporterEvent->getTransporter(); + } else { + if (ConfigQuery::read("smtp.enabled")) { + $transporter = $this->configureSmtp(); + } else { + $transporter = \Swift_MailTransport::newInstance(); + } + } + + $this->swiftMailer = new \Swift_Mailer($transporter); + } + + private function configureSmtp() + { + $smtpTransporter = new \Swift_SmtpTransport(); + $smtpTransporter->setHost(Configquery::read('smtp.host', 'localhost')) + ->setPort(ConfigQuery::read('smtp.host')) + ->setEncryption(ConfigQuery::read('smtp.encryption')) + ->setUsername(ConfigQuery::read('smtp.username')) + ->setPassword(ConfigQuery::read('smtp.password')) + ->setAuthMode(ConfigQuery::read('smtp.authmode')) + ->setTimeout(ConfigQuery::read('smtp.timeout', 30)) + ->setSourceIp(ConfigQuery::read('smtp.sourceip')) + ; + return $smtpTransporter; + } + + public function send(\Swift_Mime_Message $message, &$failedRecipients = null) + { + $this->swiftMailer->send($message, $failedRecipients); + } + + public function getSwiftMailer() + { + return $this->swiftMailer; + } + + +} \ No newline at end of file diff --git a/reset_install.sh b/reset_install.sh index 399156b67..380a80a5f 100755 --- a/reset_install.sh +++ b/reset_install.sh @@ -8,7 +8,7 @@ echo -e "\n\e[01;34m[INFO] Clearing caches\e[00m\n" php Thelia cache:clear echo -e "\n\e[01;34m[INFO] Downloading vendors\e[00m\n" -composer install --prefer-dist +composer install --prefer-dist --optimize-autoloader cd local/config/