merged 2.0
This commit is contained in:
commit
de9cf88676
@ -79,7 +79,7 @@ class UniqueEntityValidator extends ConstraintValidator
|
||||
|
||||
if (count($relatedId) > 1) {
|
||||
throw new ConstraintDefinitionException(
|
||||
"Associated entities are not allowed have more than one identifier field to be " .
|
||||
"Associated entities are not allowed to have more than one identifier field to be " .
|
||||
"part of a unique constraint in: " . $class->name . "#" . $fieldName
|
||||
);
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ class ProfilerListener implements EventSubscriberInterface
|
||||
protected $onlyMasterRequests;
|
||||
protected $exception;
|
||||
protected $children;
|
||||
protected $requests;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -49,7 +50,7 @@ class ProfilerListener implements EventSubscriberInterface
|
||||
$this->matcher = $matcher;
|
||||
$this->onlyException = (Boolean) $onlyException;
|
||||
$this->onlyMasterRequests = (Boolean) $onlyMasterRequests;
|
||||
$this->children = array();
|
||||
$this->children = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,6 +67,11 @@ class ProfilerListener implements EventSubscriberInterface
|
||||
$this->exception = $event->getException();
|
||||
}
|
||||
|
||||
public function onKernelRequest(GetResponseEvent $event)
|
||||
{
|
||||
$this->requests[] = $event->getRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the onKernelResponse event.
|
||||
*
|
||||
@ -89,24 +95,42 @@ class ProfilerListener implements EventSubscriberInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if ($profile = $this->profiler->collect($event->getRequest(), $event->getResponse(), $exception)) {
|
||||
if ($master) {
|
||||
foreach ($this->children as $child) {
|
||||
if (!$profile = $this->profiler->collect($event->getRequest(), $event->getResponse(), $exception)) {
|
||||
return;
|
||||
}
|
||||
|
||||
array_pop($this->requests);
|
||||
|
||||
// keep the profile as the child of its parent
|
||||
if (!$master) {
|
||||
$parent = $this->requests[count($this->requests) - 1];
|
||||
if (!isset($this->children[$parent])) {
|
||||
$profiles = array($profile);
|
||||
} else {
|
||||
$profiles = $this->children[$parent];
|
||||
$profiles[] = $profile;
|
||||
}
|
||||
|
||||
$this->children[$parent] = $profiles;
|
||||
}
|
||||
|
||||
// store the profile and its children
|
||||
if (isset($this->children[$event->getRequest()])) {
|
||||
foreach ($this->children[$event->getRequest()] as $child) {
|
||||
$child->setParent($profile);
|
||||
$profile->addChild($child);
|
||||
$this->profiler->saveProfile($child);
|
||||
}
|
||||
$this->children[$event->getRequest()] = array();
|
||||
}
|
||||
|
||||
$this->profiler->saveProfile($profile);
|
||||
$this->children = array();
|
||||
} else {
|
||||
$this->children[] = $profile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
KernelEvents::REQUEST => 'onKernelRequest',
|
||||
KernelEvents::RESPONSE => array('onKernelResponse', -100),
|
||||
KernelEvents::EXCEPTION => 'onKernelException',
|
||||
);
|
||||
|
@ -90,6 +90,16 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
|
||||
':time' => $profile->getTime(),
|
||||
':created_at' => time(),
|
||||
);
|
||||
|
||||
if ($this->read($profile->getToken())) {
|
||||
try {
|
||||
$this->exec($db, 'UPDATE sf_profiler_data SET parent = :parent, data = :data, ip = :ip, url = :url, time = :time, created_at = :created_at WHERE token = :token', $args);
|
||||
$this->cleanup();
|
||||
$status = true;
|
||||
} catch (\Exception $e) {
|
||||
$status = false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$this->exec($db, 'INSERT INTO sf_profiler_data (token, parent, data, ip, url, time, created_at) VALUES (:token, :parent, :data, :ip, :url, :time, :created_at)', $args);
|
||||
$this->cleanup();
|
||||
@ -97,6 +107,8 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
|
||||
} catch (\Exception $e) {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->close($db);
|
||||
|
||||
return $status;
|
||||
|
@ -215,7 +215,7 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
||||
|
||||
$this->setExpectedException(
|
||||
'Symfony\Component\Validator\Exception\ConstraintDefinitionException',
|
||||
'Associated entities are not allowed have more than one identifier field'
|
||||
'Associated entities are not allowed to have more than one identifier field'
|
||||
);
|
||||
$violationsList = $validator->validate($associated);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
||||
touch($path);
|
||||
chmod($path, 0333);
|
||||
|
||||
if (substr(sprintf('%o', fileperms($path)), -4) == '0333') {
|
||||
if (get_current_user() != 'root' && substr(sprintf('%o', fileperms($path)), -4) == '0333') {
|
||||
$this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');
|
||||
MimeTypeGuesser::getInstance()->guess($path);
|
||||
} else {
|
||||
|
@ -72,9 +72,14 @@ class SqliteProfilerStorageTest extends \PHPUnit_Framework_TestCase
|
||||
public function testStoreDuplicateToken()
|
||||
{
|
||||
$profile = new Profile('token');
|
||||
$profile->setUrl('http://example.com/');
|
||||
|
||||
$this->assertTrue(true === self::$storage->write($profile), '->write() returns true when the token is unique');
|
||||
$this->assertTrue(false === self::$storage->write($profile), '->write() return false when the token is already present in the DB');
|
||||
$this->assertTrue(self::$storage->write($profile), '->write() returns true when the token is unique');
|
||||
|
||||
$profile->setUrl('http://example.net/');
|
||||
|
||||
$this->assertTrue(self::$storage->write($profile), '->write() returns true when the token is already present in the DB');
|
||||
$this->assertEquals('http://example.net/', self::$storage->read('token')->getUrl(), '->write() overwrites the current profile data');
|
||||
}
|
||||
|
||||
public function testRetrieveByIp()
|
||||
|
@ -18,6 +18,13 @@ use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
abstract class AbstractAnnotationLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
if (!class_exists('Doctrine\\Common\\Version')) {
|
||||
$this->markTestSkipped('Doctrine is not available.');
|
||||
}
|
||||
}
|
||||
|
||||
public function getReader()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
|
||||
|
@ -25,6 +25,8 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->loader = $this->getClassLoader($this->getReader());
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = new AnnotationDirectoryLoader(new FileLocator(), $this->getClassLoader($this->reader));
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = new AnnotationFileLoader(new FileLocator(), $this->getClassLoader($this->reader));
|
||||
}
|
||||
|
Reference in New Issue
Block a user