Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Commit 7f243fa

Browse files
committed
Initial Import
0 parents  commit 7f243fa

20 files changed

+628
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.project
2+
.settings
3+
vendor

.travis.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: php
2+
3+
php:
4+
- 5.3.3
5+
- 5.3
6+
- 5.4
7+
- 5.5
8+
9+
matrix:
10+
allow_failures:
11+
- php: 5.5
12+
13+
before_script:
14+
- composer self-update
15+
- composer install
16+
17+
script: phpunit -c ./ --coverage-clover "clover"

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SettingsBundle
2+
============
3+
4+
This bundle allows you to manage settings in an application
5+
6+
*note:* Do not use the master version in your application!
7+
8+
The 1.0 branch is compaitble with Symfony 2.2.
9+
The master branch is used for development, and it will break thinks!

composer.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "customscripts/settings-bundle",
3+
"type": "symfony-bundle",
4+
"description": "Manage application settings",
5+
"keywords": [
6+
"settings"
7+
],
8+
"homepage": "http://github.com/CustomScripts/SettingsBundle",
9+
"license": "MIT",
10+
"authors": [
11+
{
12+
"name": "Pierre du Plessis",
13+
"email": "[email protected]"
14+
}
15+
],
16+
"require": {
17+
"php": ">=5.3.3",
18+
"symfony/framework-bundle": "2.2.*@dev",
19+
"customscripts/core-bundle" : "dev-master"
20+
},
21+
"minimum-stability": "dev",
22+
"autoload": {
23+
"psr-0": {
24+
"CS": "src/"
25+
}
26+
}
27+
}

phpunit.xml.dist

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit bootstrap="./vendor/autoload.php" colors="true">
4+
<testsuites>
5+
<testsuite name="SettingsBundle">
6+
<directory suffix="Test.php">./tests</directory>
7+
</testsuite>
8+
</testsuites>
9+
10+
<filter>
11+
<whitelist>
12+
<directory>./tests</directory>
13+
<exclude>
14+
<directory>./src/CS/SettingsBundle/Resources</directory>
15+
<directory>./src/CS/SettingsBundle/Tests</directory>
16+
<directory>./vendor</directory>
17+
</exclude>
18+
</whitelist>
19+
</filter>
20+
</phpunit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace CS\SettingsBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class CSSettingsBundle extends Bundle
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the CSSettingsBundle package.
5+
*
6+
* (c) Pierre du Plessis <[email protected]>
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 CS\SettingsBundle\Controller;
13+
14+
use CS\CoreBundle\Controller\Controller;
15+
use CS\SettingsBundle\Form\Type\SettingsType;
16+
17+
class SettingsController extends Controller
18+
{
19+
/**
20+
* Settings action
21+
*/
22+
public function indexAction()
23+
{
24+
$settingsRepository = $this->getRepository('CSSettingsBundle:Setting');
25+
$sections = $settingsRepository->getSections(); //array('general', 'quotes', 'invoices', 'email', 'currency', 'Cron');
26+
27+
$settings = $settingsRepository->getAllSettings();
28+
29+
$form = $this->createForm(new SettingsType($this->getEm()), $settings);
30+
31+
return $this->render('CSSettingsBundle:Settings:index.html.twig', array('sections' => $sections, 'form' => $form->createView()));
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace CS\SettingsBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8+
use Symfony\Component\DependencyInjection\Loader;
9+
10+
/**
11+
* This is the class that loads and manages your bundle configuration
12+
*
13+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
14+
*/
15+
class CSSettingsExtension extends Extension
16+
{
17+
/**
18+
* {@inheritDoc}
19+
*/
20+
public function load(array $configs, ContainerBuilder $container)
21+
{
22+
$configuration = new Configuration();
23+
$config = $this->processConfiguration($configuration, $configs);
24+
25+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26+
$loader->load('services.yml');
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace CS\SettingsBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
/**
9+
* This is the class that validates and merges configuration from your app/config files
10+
*
11+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12+
*/
13+
class Configuration implements ConfigurationInterface
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function getConfigTreeBuilder()
19+
{
20+
$treeBuilder = new TreeBuilder();
21+
$rootNode = $treeBuilder->root('cs_settings');
22+
23+
// Here you should define the parameters that are allowed to
24+
// configure your bundle. See the documentation linked above for
25+
// more information on that topic.
26+
27+
return $treeBuilder;
28+
}
29+
}
+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
3+
namespace CS\SettingsBundle\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
7+
8+
/**
9+
* @ORM\Table(name="app_config")
10+
* @ORM\Entity(repositoryClass="CS\SettingsBundle\Repository\SettingsRepository")
11+
* @UniqueEntity("key")
12+
*/
13+
class Setting
14+
{
15+
/**
16+
* @ORM\Column(name="id", type="integer")
17+
* @ORM\Id
18+
* @ORM\GeneratedValue(strategy="AUTO")
19+
*/
20+
private $id;
21+
22+
/**
23+
* @ORM\Column(name="`key`", type="string", length=125, nullable=false, unique=true)
24+
*/
25+
private $key;
26+
27+
/**
28+
* @ORM\Column(name="`value`", type="text", nullable=true)
29+
*/
30+
private $value;
31+
32+
/**
33+
* @ORM\Column(name="description", type="text", nullable=true)
34+
*/
35+
private $description;
36+
37+
/**
38+
* @ORM\Column(name="section", type="string", length=125, nullable=false)
39+
*/
40+
private $section;
41+
42+
/**
43+
* Get id
44+
*
45+
* @return integer
46+
*/
47+
public function getId()
48+
{
49+
return $this->id;
50+
}
51+
52+
/**
53+
* Get key
54+
*
55+
* @return string
56+
*/
57+
public function getKey()
58+
{
59+
return $this->key;
60+
}
61+
62+
/**
63+
* Set key
64+
*
65+
* @param string $key
66+
* @return Setting
67+
*/
68+
public function setKey($key)
69+
{
70+
$this->key = $key;
71+
72+
return $this;
73+
}
74+
75+
/**
76+
* Get value
77+
*
78+
* @return string
79+
*/
80+
public function getValue()
81+
{
82+
return $this->value;
83+
}
84+
85+
/**
86+
* Set value
87+
*
88+
* @param mixed $value
89+
* @return Setting
90+
*/
91+
public function setValue($value)
92+
{
93+
$this->value = $value;
94+
95+
return $this;
96+
}
97+
98+
/**
99+
* Get description
100+
*
101+
* @return string
102+
*/
103+
public function getDescription()
104+
{
105+
return $this->description;
106+
}
107+
108+
/**
109+
* Set description
110+
*
111+
* @param string $description
112+
* @return Setting
113+
*/
114+
public function setDescription($description)
115+
{
116+
$this->description = $description;
117+
118+
return $this;
119+
}
120+
121+
/**
122+
* Get section
123+
*
124+
* @return string
125+
*/
126+
public function getSection()
127+
{
128+
return $this->section;
129+
}
130+
131+
/**
132+
* Set section
133+
*
134+
* @param mixed $section
135+
* @return Setting
136+
*/
137+
public function setSection($section)
138+
{
139+
$this->section = $section;
140+
141+
return $this;
142+
}
143+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the CSSettingsBundle package.
5+
*
6+
* (c) Pierre du Plessis <[email protected]>
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 CS\SettingsBundle\Form\Type;
13+
14+
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\FormBuilderInterface;
16+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
17+
use Symfony\Component\Form\Form;
18+
19+
class Settings extends AbstractType
20+
{
21+
protected $settings;
22+
23+
public function __construct(array $settings)
24+
{
25+
$this->settings = $settings;
26+
}
27+
28+
/**
29+
* (non-PHPdoc)
30+
* @see Symfony\Component\Form.AbstractType::buildForm()
31+
*/
32+
public function buildForm(FormBuilderInterface $builder, array $options)
33+
{
34+
foreach($this->settings as $setting) {
35+
$builder->add($setting->getKey(), null, array('help' => $setting->getDescription()));
36+
}
37+
}
38+
39+
/**
40+
* (non-PHPdoc)
41+
* @see Symfony\Component\Form.FormTypeInterface::getName()
42+
*/
43+
public function getName()
44+
{
45+
return 'settings_general';
46+
}
47+
}

0 commit comments

Comments
 (0)