This commit is contained in:
franck
2013-09-16 18:59:18 +02:00
9 changed files with 238 additions and 9 deletions

View File

@@ -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 :

View File

@@ -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"
}
}

51
composer.lock generated
View File

@@ -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",

View File

@@ -267,6 +267,10 @@
<tag name="thelia.coupon.addCoupon"/>
</service>
<service id="mailer" class="Thelia\Mailer\MailerFactory">
<argument type="service" id="event_dispatcher"/>
</service>
</services>

View File

@@ -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();
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Core\Event;
/**
* Class MailTransporterEvent
* @package Thelia\Core\Event
* @author Manuel Raynaud <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -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';
}

View File

@@ -0,0 +1,91 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
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 <mraynaud@openstudio.fr>
*/
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;
}
}

View File

@@ -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/