Skip to content

Commit 88454b7

Browse files
committed
Merge pull request propelorm#384 from havvg/1.5
integrate former Symfony Propel1 bridge
2 parents bde72e0 + 38b491a commit 88454b7

33 files changed

Lines changed: 3312 additions & 54 deletions
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.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 Propel\PropelBundle\DataCollector;
13+
14+
use Propel\PropelBundle\Logger\PropelLogger;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\Response;
17+
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
18+
19+
/**
20+
* The PropelDataCollector collector class collects information.
21+
*
22+
* @author William Durand <william.durand1@gmail.com>
23+
*/
24+
class PropelDataCollector extends DataCollector
25+
{
26+
/**
27+
* Propel logger.
28+
*
29+
* @var PropelLogger
30+
*/
31+
private $logger;
32+
33+
/**
34+
* Propel configuration.
35+
*
36+
* @var \PropelConfiguration
37+
*/
38+
protected $propelConfiguration;
39+
40+
/**
41+
* Constructor.
42+
*
43+
* @param PropelLogger $logger A Propel logger.
44+
* @param \PropelConfiguration $propelConfiguration The Propel configuration object.
45+
*/
46+
public function __construct(PropelLogger $logger, \PropelConfiguration $propelConfiguration)
47+
{
48+
$this->logger = $logger;
49+
$this->propelConfiguration = $propelConfiguration;
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function collect(Request $request, Response $response, \Exception $exception = null)
56+
{
57+
$this->data = array(
58+
'queries' => $this->buildQueries(),
59+
'querycount' => $this->countQueries(),
60+
);
61+
}
62+
63+
/**
64+
* Returns the collector name.
65+
*
66+
* @return string
67+
*/
68+
public function getName()
69+
{
70+
return 'propel';
71+
}
72+
73+
/**
74+
* Returns the collected stats for all executed SQL queries.
75+
*
76+
* @return array
77+
*/
78+
public function getQueries()
79+
{
80+
return $this->data['queries'];
81+
}
82+
83+
/**
84+
* Returns the query count.
85+
*
86+
* @return int
87+
*/
88+
public function getQueryCount()
89+
{
90+
return $this->data['querycount'];
91+
}
92+
93+
/**
94+
* Returns the total time spent on running all queries.
95+
*
96+
* @return float
97+
*/
98+
public function getTime()
99+
{
100+
$time = 0;
101+
foreach ($this->data['queries'] as $query) {
102+
$time += (float) $query['time'];
103+
}
104+
105+
return $time;
106+
}
107+
108+
/**
109+
* Computes the stats of all executed SQL queries.
110+
*
111+
* @return array
112+
*/
113+
private function buildQueries()
114+
{
115+
$queries = array();
116+
117+
$outerGlue = $this->propelConfiguration->getParameter('debugpdo.logging.outerglue', ' | ');
118+
$innerGlue = $this->propelConfiguration->getParameter('debugpdo.logging.innerglue', ': ');
119+
120+
foreach ($this->logger->getQueries() as $q) {
121+
$parts = explode($outerGlue, $q, 4);
122+
123+
$times = explode($innerGlue, $parts[0]);
124+
$con = explode($innerGlue, $parts[2]);
125+
$memories = explode($innerGlue, $parts[1]);
126+
127+
$sql = trim($parts[3]);
128+
$con = trim($con[1]);
129+
$time = trim($times[1]);
130+
$memory = trim($memories[1]);
131+
132+
$queries[] = array('connection' => $con, 'sql' => $sql, 'time' => $time, 'memory' => $memory);
133+
}
134+
135+
return $queries;
136+
}
137+
138+
/**
139+
* Returns the total count of SQL queries.
140+
*
141+
* @return int
142+
*/
143+
private function countQueries()
144+
{
145+
return count($this->logger->getQueries());
146+
}
147+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.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 Propel\PropelBundle\DependencyInjection\Security\UserProvider;
13+
14+
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
15+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\DefinitionDecorator;
18+
19+
/**
20+
* PropelFactory creates services for Propel user provider.
21+
*
22+
* @author William Durand <william.durand1@gmail.com>
23+
*/
24+
class PropelFactory implements UserProviderFactoryInterface
25+
{
26+
private $key;
27+
private $providerId;
28+
29+
/**
30+
* Constructor.
31+
*
32+
* @param string $key
33+
* @param string $providerId
34+
*/
35+
public function __construct($key, $providerId)
36+
{
37+
$this->key = $key;
38+
$this->providerId = $providerId;
39+
}
40+
41+
public function create(ContainerBuilder $container, $id, $config)
42+
{
43+
$container
44+
->setDefinition($id, new DefinitionDecorator($this->providerId))
45+
->addArgument($config['class'])
46+
->addArgument($config['property'])
47+
;
48+
}
49+
50+
public function getKey()
51+
{
52+
return $this->key;
53+
}
54+
55+
public function addConfiguration(NodeDefinition $node)
56+
{
57+
$node
58+
->children()
59+
->scalarNode('class')
60+
->isRequired()
61+
->cannotBeEmpty()
62+
->end()
63+
->scalarNode('property')
64+
->defaultNull()
65+
->end()
66+
->end()
67+
;
68+
}
69+
}

0 commit comments

Comments
 (0)