Skip to content

Commit cd3f6e5

Browse files
Sandip PatelSandip Patel
Sandip Patel
authored and
Sandip Patel
committed
PCB V5.0 Released
0 parents  commit cd3f6e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2282
-0
lines changed

Diff for: LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Sandip Patel
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
10+
furnished 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 THE
21+
SOFTWARE.
22+

Diff for: PCB/Configuration/Configuration.php

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------
5+
* PHP CODE BOOSTER
6+
* ---------------------------------
7+
*
8+
* @Author: Sandip Patel
9+
* @package PHPCodebooster
10+
* @version 5.0
11+
* @copyright (c) 2014, Sandip Patel
12+
**/
13+
namespace PCB\Configuration;
14+
15+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16+
use Symfony\Component\Config\Definition\ConfigurationInterface;
17+
18+
class Configuration implements ConfigurationInterface {
19+
20+
public function getConfigTreeBuilder() {
21+
22+
$treeBuilder = new TreeBuilder();
23+
$rootNode = $treeBuilder->root('framework');
24+
25+
$rootNode
26+
->children()
27+
->scalarNode('environment')
28+
->defaultValue('production')
29+
->end()
30+
->arrayNode('database')
31+
->useAttributeAsKey('name')
32+
->prototype('array')
33+
->children()
34+
->scalarNode('dbname')->end()
35+
->scalarNode('user')->end()
36+
->scalarNode('password')->end()
37+
->scalarNode('host')->end()
38+
->scalarNode('driver')
39+
->isRequired()
40+
->validate()
41+
->ifNotInArray(array('pdo_mysql'))
42+
->thenInvalid('Invalid database driver "%s"')
43+
->end()
44+
->end()
45+
->end()
46+
->end()
47+
->end()
48+
->arrayNode('memcache')
49+
->useAttributeAsKey('name')
50+
->prototype('array')
51+
->children()
52+
->scalarNode('host')->end()
53+
->scalarNode('port')->end()
54+
->end()
55+
->end()
56+
->end()
57+
->arrayNode('js')
58+
->prototype('scalar')
59+
->end()
60+
->end()
61+
->arrayNode('css')
62+
->prototype('scalar')
63+
->end()
64+
->end()
65+
->arrayNode('helpers')
66+
->prototype('scalar')
67+
->end()
68+
->end()
69+
->end()
70+
;
71+
72+
$this->addCacheSettings($rootNode);
73+
$this->addDoctrineSettings($rootNode);
74+
$this->addUserSettings($rootNode);
75+
$this->addRouterSettings($rootNode);
76+
$this->addSessionSettings($rootNode);
77+
$this->addValidatorSettings($rootNode);
78+
$this->addRequestSettings($rootNode);
79+
$this->addTemplateSettings($rootNode);
80+
$this->addViewSettings($rootNode);
81+
82+
return $treeBuilder;
83+
}
84+
85+
private function addCacheSettings($rootNode) {
86+
$rootNode
87+
->children()
88+
->arrayNode('cache')
89+
->info('cache configuration')
90+
->canBeUnset()
91+
->children()
92+
->end()
93+
->end()
94+
->end()
95+
->end()
96+
;
97+
}
98+
99+
private function addDoctrineSettings($rootNode) {
100+
$rootNode
101+
->children()
102+
->arrayNode('doctrine')
103+
->info('doctrine configuration')
104+
->canBeUnset()
105+
->children()
106+
->end()
107+
->end()
108+
->end()
109+
->end()
110+
;
111+
}
112+
113+
private function addUserSettings($rootNode) {
114+
$rootNode
115+
->children()
116+
->arrayNode('user')
117+
->info('user configuration')
118+
->canBeUnset()
119+
->children()
120+
->end()
121+
->end()
122+
->end()
123+
->end()
124+
;
125+
}
126+
127+
private function addRouterSettings($rootNode) {
128+
$rootNode
129+
->children()
130+
->arrayNode('router')
131+
->info('router configuration')
132+
->canBeUnset()
133+
->children()
134+
->end()
135+
->end()
136+
->end()
137+
->end()
138+
;
139+
}
140+
141+
private function addSessionSettings($rootNode) {
142+
$rootNode
143+
->children()
144+
->arrayNode('session')
145+
->info('session configuration')
146+
->canBeUnset()
147+
->children()
148+
->end()
149+
->end()
150+
->end()
151+
->end()
152+
;
153+
}
154+
155+
private function addValidatorSettings($rootNode) {
156+
$rootNode
157+
->children()
158+
->arrayNode('validator')
159+
->info('validator configuration')
160+
->canBeUnset()
161+
->children()
162+
->end()
163+
->end()
164+
->end()
165+
->end()
166+
;
167+
}
168+
169+
private function addRequestSettings($rootNode) {
170+
$rootNode
171+
->children()
172+
->arrayNode('request')
173+
->info('request configuration')
174+
->canBeUnset()
175+
->children()
176+
->end()
177+
->end()
178+
->end()
179+
->end()
180+
;
181+
}
182+
183+
private function addTemplateSettings($rootNode) {
184+
$rootNode
185+
->children()
186+
->arrayNode('template')
187+
->info('template configuration')
188+
->canBeUnset()
189+
->children()
190+
->end()
191+
->end()
192+
->end()
193+
->end()
194+
;
195+
}
196+
197+
private function addViewSettings($rootNode) {
198+
$rootNode
199+
->children()
200+
->arrayNode('view')
201+
->info('view configuration')
202+
->canBeUnset()
203+
->children()
204+
->end()
205+
->end()
206+
->end()
207+
->end()
208+
;
209+
}
210+
}

Diff for: PCB/Configuration/FrameWorkExtension.php

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
3+
/**
4+
* ---------------------------------
5+
* PHP CODE BOOSTER
6+
* ---------------------------------
7+
*
8+
* @Author: Sandip Patel
9+
* @package PHPCodebooster
10+
* @version 5.0
11+
* @copyright (c) 2014, Sandip Patel
12+
**/
13+
namespace PCB\Configuration;
14+
15+
use Symfony\Component\Yaml\Yaml;
16+
use Symfony\Component\Config\FileLocator;
17+
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
use Symfony\Component\DependencyInjection\Extension\Extension;
20+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
21+
22+
class FrameWorkExtension extends Extension {
23+
24+
public function getAlias() {
25+
return 'pcb.framework.extension';
26+
}
27+
28+
public function load(array $configs, ContainerBuilder $container) {
29+
30+
// time to load services
31+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__. '/Resources'));
32+
33+
// get default and project configs
34+
$config1 = Yaml::parse(__DIR__. '/Resources/settings.yml');
35+
$config2 = Yaml::parse($container->getParameter('pcb.config_dir'). 'settings.yml');
36+
37+
// handle priorities
38+
$configs = $this->processConfiguration(
39+
new Configuration(),
40+
array($config1, $config2)
41+
);
42+
43+
// set configuration settings
44+
$container->setParameter('pcb.settings', $configs);
45+
46+
// set environment
47+
$prod = isset($configs['environment']) && ($configs['environment'] == 'production') ? true : false;
48+
49+
// set errors based on environment
50+
error_reporting( !$prod ? E_ALL : 0 );
51+
ini_set('display_errors', !$prod);
52+
ini_set('display_startup_errors', !$prod);
53+
54+
// session settings
55+
if (isset($configs['session'])) {
56+
$this->loadSessionConfiguration($configs['session'], $container, $loader);
57+
}
58+
59+
// validator settings
60+
if (isset($configs['validator'])) {
61+
$this->loadValidatorConfiguration($configs['validator'], $container, $loader);
62+
}
63+
64+
// request settings
65+
if (isset($configs['request'])) {
66+
$this->loadRequestConfiguration($configs['request'], $container, $loader);
67+
}
68+
69+
// cache settings
70+
if (isset($configs['cache'])) {
71+
$this->loadCacheConfiguration($configs['cache'], $container, $loader);
72+
}
73+
74+
// doctrine settings
75+
if (isset($configs['doctrine'])) {
76+
$this->loadDoctrineConfiguration($configs['doctrine'], $container, $loader);
77+
}
78+
79+
// user settings
80+
if (isset($configs['user'])) {
81+
$this->loadUserConfiguration($configs['user'], $container, $loader);
82+
}
83+
84+
// template settings
85+
if (isset($configs['template'])) {
86+
$this->loadTemplateConfiguration($configs['template'], $container, $loader);
87+
}
88+
89+
// view settings
90+
if (isset($configs['view'])) {
91+
$this->loadViewConfiguration($configs['view'], $container, $loader);
92+
}
93+
94+
// router settings
95+
if (isset($configs['router'])) {
96+
$this->loadRouterConfiguration($configs['router'], $container, $loader);
97+
}
98+
}
99+
100+
private function loadSessionConfiguration($configs, $container, $loader) {
101+
102+
$loader->load('session.yml');
103+
$container->getDefinition('session')
104+
->addMethodCall('start');
105+
}
106+
107+
private function loadCacheConfiguration($configs, $container, $loader) {
108+
$loader->load('cache.yml');
109+
}
110+
111+
private function loadDoctrineConfiguration($configs, $container, $loader) {
112+
$loader->load('doctrine.yml');
113+
}
114+
115+
private function loadUserConfiguration($configs, $container, $loader) {
116+
$loader->load('user.yml');
117+
}
118+
119+
private function loadValidatorConfiguration($configs, $container, $loader) {
120+
$loader->load('validator.yml');
121+
}
122+
123+
private function loadRequestConfiguration($configs, $container, $loader) {
124+
$loader->load('request.yml');
125+
}
126+
127+
private function loadRouterConfiguration($configs, $container, $loader) {
128+
$loader->load('router.yml');
129+
}
130+
131+
private function loadTemplateConfiguration($configs, $container, $loader) {
132+
133+
$loader->load('template.yml');
134+
$container->getDefinition('template')
135+
->addMethodCall('setUser', array(new Reference('user')))
136+
->addMethodCall('setDoctrine', array(new Reference('doctrine')));
137+
}
138+
139+
private function loadViewConfiguration($configs, $container, $loader) {
140+
$loader->load('view.yml');
141+
}
142+
}

Diff for: PCB/Configuration/Resources/cache.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
cache.class: PCB\Services\CacheService
3+
4+
services:
5+
cache:
6+
class: "%cache.class%"
7+
arguments: ["%pcb.root_dir%", "%pcb.settings%"]

Diff for: PCB/Configuration/Resources/doctrine.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
doctrine.class: PCB\Services\DoctrineService
3+
4+
services:
5+
doctrine:
6+
class: "%doctrine.class%"
7+
arguments: ["%pcb.root_dir%", "%pcb.settings%"]

0 commit comments

Comments
 (0)