Skip to content

Commit 2547a9f

Browse files
committed
Initial commit
0 parents  commit 2547a9f

File tree

5 files changed

+208
-0
lines changed

5 files changed

+208
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the JirafeMailChimpBundle.
5+
*
6+
* (c) 2011 Jirafe <http://www.jirafe.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Jirafe\Bundle\MailChimpBundle\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Extension\Extension;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
17+
use Symfony\Component\Config\FileLocator;
18+
19+
class JirafeMailChimpExtension extends Extension
20+
{
21+
/**
22+
* {@inheritDoc}
23+
*/
24+
public function load(array $configs, ContainerBuilder $builder)
25+
{
26+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
27+
$loader->load('mail_chimp.xml');
28+
29+
$config = $this->mergeConfigs($configs);
30+
31+
if (empty($config['api_key'])) {
32+
throw new \Exception('You must define the \'api_key\' parameter in the \'jirafe_mail_chimp\' configuration section.');
33+
}
34+
35+
$builder->setParameter('mail_chimp.api.key', $config['api_key']);
36+
37+
if (isset($config['secure'])) {
38+
$builder->getDefinition('mail_chimp.api');
39+
$builder->setParameter(1, $config['secure']);
40+
}
41+
42+
if (isset($config['timeout'])) {
43+
$builder->getDefinition('mail_chimp.api');
44+
$builder->addMethodCall('setTimeout', array($config['timeout']));
45+
}
46+
}
47+
48+
/**
49+
* Merges the given configurations
50+
*
51+
* @param array $configs An array of configurations
52+
*
53+
* @return array The merged configuration
54+
*/
55+
public function mergeConfigs(array $configs)
56+
{
57+
$merged = array();
58+
foreach ($configs as $config) {
59+
if (isset($config['api-key'])) {
60+
$merged['api_key'] = $config['api-key'];
61+
} else if (isset($config['api_key'])) {
62+
$merged['api_key'] = $config['api_key'];
63+
}
64+
65+
if (isset($config['secure'])) {
66+
$merged['secure'] = true === $config['secure'] ? true : false;
67+
}
68+
69+
if (isset($config['timeout'])) {
70+
$merged['timeout'] = intval($merged['timeout']);
71+
}
72+
}
73+
74+
return $merged;
75+
}
76+
77+
/**
78+
* {@inheritDoc}
79+
*/
80+
public function getXsdValidationBasePath()
81+
{
82+
return __DIR__.'/../Resources/config/schema';
83+
}
84+
85+
/**
86+
* {@inheritDoc}
87+
*/
88+
public function getNamespace()
89+
{
90+
return 'http://www.jirafe.com/schema/dic/mail_chimp_bundle';
91+
}
92+
}

JirafeMailChimpBundle.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the JirafeMailChimpBundle.
5+
*
6+
* (c) 2011 Jirafe <http://www.jirafe.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Jirafe\Bundle\MailChimpBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle
15+
16+
class JirafeMailChimpBundle extends Bundle
17+
{
18+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) 2011 Jirafe
2+
3+
The MIT license
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is furnished
10+
to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
MailChimpBundle
2+
===============
3+
4+
The MailChimp API for your Symfony2 projects.
5+
6+
Installation
7+
------------
8+
9+
First, you need to add the MailChimp library in your project:
10+
11+
$ git add submodule git://github.com/switzer/mailchimp.git vendor/mailchimp
12+
13+
And the bundle:
14+
15+
$ git add submodule git://github.com/jirafe/MailChimpBundle.git vendor/bundles/Jirafe/Bundle/MailChimpBundle
16+
17+
Then, add it to the autoloader:
18+
19+
// app/autoload.php
20+
$loader->registerNamespaces(array(
21+
22+
// ... other namespaces
23+
24+
'Jirafe' => __DIR__ . '/../src',
25+
'Mailchimp' => __DIR__ . '/../vendor/mailchimp/src',
26+
));
27+
28+
Add the bundle to your kernel:
29+
30+
// app/AppKernel.php
31+
32+
$bundles = array(
33+
34+
// ... other bundles
35+
36+
new Jirafe\Bundle\MailChimpBundle\JirafeMailChimpBundle(),
37+
);
38+
39+
Finally, configure it:
40+
41+
# app/config/config.yml
42+
# MailChimp Configuration
43+
jirafe_mail_chimp:
44+
api_key: yourSecretKey # your api key providen by MailChimp
45+
secret: false # whether to use the secret mode (optional)
46+
timeout: 10 # timeout in seconds (optional)
47+
48+
Usage
49+
-----
50+
51+
In your controller, you can easily access the MailChimp api:
52+
53+
// src/FooVendor/Bundle/BarBundle/Controller/DefaultController
54+
55+
public function foobarAction()
56+
{
57+
$mailChimp = $this->get('mail_chimp.api');
58+
59+
$mailChimp->campaignUnschedule($cid);
60+
}

Resources/config/mail_chimp.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="mail_chimp.api.class">MailChimp\MCAPI</parameter>
9+
<parameter key="mail_chimp.api.key">null</parameter>
10+
</parameters>
11+
12+
<services>
13+
<service id="mail_chimp.api" class="%mail_chimp.api.class%">
14+
<argument>%mail_chimp.api.key%</argument>
15+
</service>
16+
</services>
17+
</container>

0 commit comments

Comments
 (0)