Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[do not merge] symfony 5 compatibility #5

Open
wants to merge 10 commits into
base: symfony_4.0
Choose a base branch
from
8 changes: 4 additions & 4 deletions Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ protected function copySchemas(KernelInterface $kernel, $cacheDir)
$filesystem->mkdir($cacheDir);
}

$base = ltrim(realpath($kernel->getRootDir().'/..'), DIRECTORY_SEPARATOR);
$base = ltrim(realpath($kernel->getProjectDir().'/..'), DIRECTORY_SEPARATOR);

$finalSchemas = $this->getFinalSchemas($kernel, $this->bundle);
foreach ($finalSchemas as $schema) {
Expand Down Expand Up @@ -354,7 +354,7 @@ protected function getRelativeFileName(\SplFileInfo $file)
protected function createBuildPropertiesFile(KernelInterface $kernel, $file)
{
$filesystem = new Filesystem();
$buildPropertiesFile = $kernel->getRootDir().'/config/propel.ini';
$buildPropertiesFile = $kernel->getProjectDir().'/config/propel.ini';

if (file_exists($buildPropertiesFile)) {
$filesystem->copy($buildPropertiesFile, $file);
Expand Down Expand Up @@ -655,8 +655,8 @@ private function getPhingArguments(KernelInterface $kernel, $workingDirectory, $
$properties = array_merge(array(
'propel.database' => 'mysql',
'project.dir' => $workingDirectory,
'propel.output.dir' => $kernel->getRootDir().'/propel',
'propel.php.dir' => $kernel->getRootDir().'/..',
'propel.output.dir' => $kernel->getProjectDir().'/propel',
'propel.php.dir' => $kernel->getProjectDir().'/..',
'propel.packageObjectModel' => true,
'propel.useDateTimeClass' => true,
'propel.dateTimeClass' => 'DateTime',
Expand Down
4 changes: 2 additions & 2 deletions Command/FixturesDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
list($name, $defaultConfig) = $this->getConnection($input, $output);
$fixtureDir = $input->getOption('dir') ? $input->getOption('dir') : $this->defaultFixturesDir;

$path = realpath($this->getApplication()->getKernel()->getRootDir() . '/../') . '/' . $fixtureDir;
$path = realpath($this->getApplication()->getKernel()->getProjectDir() . '/../') . '/' . $fixtureDir;

if (!file_exists($path)) {
$output->writeln("<info>The $path folder does not exists.</info>");
Expand All @@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$filename = $path . '/fixtures_' . time() . '.yml';

$dumper = new YamlDataDumper($this->getApplication()->getKernel()->getRootDir());
$dumper = new YamlDataDumper($this->getApplication()->getKernel()->getProjectDir());

try {
$dumper->dump($filename, $name);
Expand Down
8 changes: 4 additions & 4 deletions Command/FixturesLoadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (null !== $this->bundle) {
$this->absoluteFixturesPath = $this->getFixturesPath($this->bundle);
} else {
$this->absoluteFixturesPath = realpath($this->getApplication()->getKernel()->getRootDir() . '/../' . $input->getOption('dir'));
$this->absoluteFixturesPath = realpath($this->getApplication()->getKernel()->getProjectDir() . '/../' . $input->getOption('dir'));
}

if (!$this->absoluteFixturesPath && !file_exists($this->absoluteFixturesPath)) {
Expand Down Expand Up @@ -172,9 +172,9 @@ protected function loadFixtures(InputInterface $input, OutputInterface $output,
list($name, $defaultConfig) = $this->getConnection($input, $output);

if ('yml' === $type) {
$loader = new YamlDataLoader($this->getApplication()->getKernel()->getRootDir(), $this->getContainer());
$loader = new YamlDataLoader($this->getApplication()->getKernel()->getProjectDir(), $this->getContainer());
} elseif ('xml' === $type) {
$loader = new XmlDataLoader($this->getApplication()->getKernel()->getRootDir());
$loader = new XmlDataLoader($this->getApplication()->getKernel()->getProjectDir());
} else {
return;
}
Expand Down Expand Up @@ -204,7 +204,7 @@ protected function loadFixtures(InputInterface $input, OutputInterface $output,
*/
protected function loadSqlFixtures(InputInterface $input, OutputInterface $output)
{
$tmpdir = $this->getApplication()->getKernel()->getRootDir() . '/cache/propel';
$tmpdir = $this->getApplication()->getKernel()->getProjectDir() . '/cache/propel';
$datas = $this->getFixtureFiles('sql');

$this->prepareCache($tmpdir);
Expand Down
2 changes: 1 addition & 1 deletion Command/GraphvizGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$dest = $this->getApplication()->getKernel()->getRootDir() . '/propel/graph/';
$dest = $this->getApplication()->getKernel()->getProjectDir() . '/propel/graph/';

$this->callPhing('graphviz', array(
'propel.graph.dir' => $dest,
Expand Down
2 changes: 1 addition & 1 deletion Command/ReverseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filesystem = new Filesystem();
$generated = $this->getCacheDir().'/schema.xml';
$filename = $name . '_reversed_schema.xml';
$destFile = $this->getApplication()->getKernel()->getRootDir() . '/propel/generated-schemas/' . $filename;
$destFile = $this->getApplication()->getKernel()->getProjectDir() . '/propel/generated-schemas/' . $filename;

if (file_exists($generated)) {
$filesystem->copy($generated, $destFile);
Expand Down
41 changes: 25 additions & 16 deletions Controller/PanelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,43 @@
*/
namespace Propel\Bundle\PropelBundle\Controller;

use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Response;
use Psr\Container\ContainerInterface;
use Twig\Environment;

/**
* PanelController is designed to display information in the Propel Panel.
*
* @author William DURAND <[email protected]>
*/
class PanelController extends ContainerAware
class PanelController
{
use ContainerAwareTrait;

private $twig;

public function __construct(ContainerInterface $container, Environment $twig)
{
$this->container = $container;
$this->twig = $twig;
}

/**
* This method renders the global Propel configuration.
*/
public function configurationAction()
{
$templating = $this->container->get('templating');
$configuration = $this->container->get('propel.configuration')->getParameters();

return $templating->renderResponse(
'PropelBundle:Panel:configuration.html.twig',
array(
'propel_version' => \Propel::VERSION,
'configuration' => $this->container->get('propel.configuration')->getParameters(),
'default_connection' => $this->container->getParameter('propel.dbal.default_connection'),
'logging' => $this->container->getParameter('propel.logging'),
'path' => $this->container->getParameter('propel.path'),
'phing_path' => $this->container->getParameter('propel.phing_path'),
)
);
return new Response($this->twig->render('@Propel/Panel/configuration.html.twig', array(
'propel_version' => \Propel::VERSION,
'configuration' => $configuration,
'default_connection' => $this->container->getParameter('propel.dbal.default_connection'),
'logging' => $this->container->getParameter('propel.logging'),
'path' => $this->container->getParameter('propel.path'),
'phing_path' => $this->container->getParameter('propel.phing_path'),
)));
}

/**
Expand Down Expand Up @@ -73,8 +82,8 @@ public function explainAction($token, $connection, $query)
return new Response('<div class="error">This query cannot be explained.</div>');
}

return $this->container->get('templating')->renderResponse(
'PropelBundle:Panel:explain.html.twig',
return $this->twig->render(
'@Propel/Panel/explain.html.twig',
array(
'data' => $results,
'query' => $query,
Expand Down
2 changes: 1 addition & 1 deletion DataCollector/PropelDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(PropelLogger $logger, \PropelConfiguration $propelCo
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, ?\Throwable $exception = null)
{
$this->data = array(
'queries' => $this->buildQueries(),
Expand Down
2 changes: 1 addition & 1 deletion DataFixtures/Loader/AbstractDataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract protected function transformDataToArray($file);
/**
* {@inheritdoc}
*/
public function load($files = array(), $connectionName)
public function load($files = array(), $connectionName = null)
{
$nbFiles = 0;
$this->deletedClasses = array();
Expand Down
2 changes: 1 addition & 1 deletion DataFixtures/Loader/DataLoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ interface DataLoaderInterface
* @param array $files A set of files containing datas to load.
* @param string $connectionName The Propel connection name
*/
public function load($files = array(), $connectionName);
public function load($files = array(), $connectionName = null);
}
2 changes: 1 addition & 1 deletion DataFixtures/Loader/DataWiper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DataWiper extends AbstractDataLoader
* @param array $files A set of files containing datas to load.
* @param string $connectionName The Propel connection name
*/
public function load($files = array(), $connectionName)
public function load($files = array(), $connectionName = null)
{
$this->deletedClasses = array();
$this->loadMapBuilders($connectionName);
Expand Down
50 changes: 25 additions & 25 deletions Resources/views/Collector/propel.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %}
{% extends '@WebProfiler/Profiler/layout.html.twig' %}

{% block toolbar %}
{% if collector.querycount %}
Expand All @@ -14,7 +14,7 @@

{% set text %}{% endset %}

{% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { link: profiler_url } %}
{% include '@WebProfiler/Profiler/toolbar_item.html.twig' with { link: profiler_url } %}
{% endif %}
{% endblock %}

Expand Down Expand Up @@ -73,33 +73,33 @@
<tr><td>No queries.</td></tr>
{% else %}
{% for i, query in collector.queries %}
<tr>
<td>
<a name="propel-query-{{ i }}" ></a>
<code>{{ query.sql|format_sql }}</code>
{% if app.request.query.has('query') and app.request.query.get('query') == i %}
<div class="SQLExplain">
{% render controller('PropelBundle:Panel:explain', {
'token': token,
'panel': 'propel',
'query': app.request.query.get('query'),
'connection': app.request.query.get('connection')
}) %}
</div>
{% endif %}
<div class="SQLInfo">
Time: {{ query.time }} - Memory: {{ query.memory }} - Connection: {{ query.connection }}

{% if app.request.query.get('query', -1) != i %}
- <a href="{{ path('_profiler', {'panel': 'propel', 'token': token, 'connection': query.connection, 'query': i}) }}#propel-query-{{ i }}">Explain the query</a>
<tr>
<td>
<a name="propel-query-{{ i }}" ></a>
<code>{{ query.sql|format_sql }}</code>
{% if app.request.query.has('query') and app.request.query.get('query') == i %}
<div class="SQLExplain">
{{ render(controller('Propel\\Bundle\\PropelBundle\\Controller\\PanelController::explainAction', {
'token': token,
'panel': 'propel',
'query': app.request.query.get('query'),
'connection': app.request.query.get('connection')
})) }}
</div>
{% endif %}
</div>
</td>
</tr>
<div class="SQLInfo">
Time: {{ query.time }} - Memory: {{ query.memory }} - Connection: {{ query.connection }}

{% if app.request.query.get('query', -1) != i %}
- <a href="{{ path('_profiler', {'panel': 'propel', 'token': token, 'connection': query.connection, 'query': i}) }}#propel-query-{{ i }}">Explain the query</a>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
{% endif %}
</tbody>
</table>

{% render controller('PropelBundle:Panel:configuration') %}
{{ render(controller('Propel\\Bundle\\PropelBundle\\Controller\\PanelController::configurationAction')) }}
{% endblock %}
6 changes: 4 additions & 2 deletions Resources/views/Panel/configuration.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<tr>
<th>Default connection</th>
<td>{{ default_connection }}</td>

</tr>
<tr>
<th>Logging</th>
<td>{{ logging ? 'enabled' : 'disabled' }}</td>
Expand Down Expand Up @@ -57,7 +59,7 @@
<td>
<ul>
{% for key, value in config.connection.options %}
<li>{{ key }} : {{ value }}</li>
<li>{{ key }} : {% if value is iterable %}{{ value|json_encode }}{% else %}{{ value }}{% endif %}</li>
{% endfor %}
</ul>
</td>
Expand All @@ -67,7 +69,7 @@
<td>
<ul>
{% for key, value in config.connection.attributes %}
<li>{{ key }} : {{ value }}</li>
<li>{{ key }} : {% if value is iterable %}{{ value|json_encode }}{% else %}{{ value }}{% endif %}</li>
{% endfor %}
</ul>
</td>
Expand Down
3 changes: 3 additions & 0 deletions Tests/Command/FixturesLoadCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
class FixturesLoadCommandTest extends TestCase
{
protected $command;
protected $fixturesDir;
protected $fixturesFiles;
protected $filesystem;

public function setUp(): void
{
Expand Down
4 changes: 2 additions & 2 deletions Tests/DataFixtures/Dumper/YamlDataDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public function testYamlDump()
$expected = <<<YAML
Propel\Bundle\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor:
BookAuthor_1:
id: '1'
id: 1
name: 'A famous one'
Propel\Bundle\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book:
Book_1:
id: '1'
id: 1
name: 'An important one'
author_id: BookAuthor_1
complementary_infos: !php/object 'O:8:"stdClass":1:{s:15:"first_word_date";s:10:"2012-01-01";}'
Expand Down
10 changes: 10 additions & 0 deletions Translation/ModelTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ private function getColumnPhpname($identifier)
return $this->query->getTableMap()->getColumn($this->getColumnname($identifier))->getPhpName();
}

public function __serialize()
{
return $this->serialize();
}

/**
* {@inheritdoc}
*/
Expand All @@ -249,6 +254,11 @@ public function serialize()
));
}

public function __unserialize($serialized)
{
return $this->unserialize($serialized);
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion Util/PropelInflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class PropelInflector
*/
public static function camelize($word)
{
return lcfirst(str_replace(" ", "", ucwords(strtr($word, "_-", " "))));
return lcfirst(str_replace(" ", "", ucwords(strtr($word ?? '', "_-", " "))));
}
}
2 changes: 1 addition & 1 deletion autoload_aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class_alias(str_replace('Propel\PropelBundle', 'Propel\Bundle\PropelBundle', $cl
}
}

spl_autoload_register('autoload_propel_aliases', false, true);
spl_autoload_register('autoload_propel_aliases', true, true);
21 changes: 14 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
},

"require": {
"php": "^7.2",
"propel/propel1": "^1.6",
"symfony/framework-bundle": "^3.0|^4.0",
"symfony/symfony": "^4.0"
"php": "^7.2|^8.3",
"propel/propel1": "1.6.19|dev-symfony-5",
"symfony/framework-bundle": "^3.0|^4.0|^5.0",
"symfony/symfony": "^4.0|^5.0"
},
"require-dev": {
"ext-sqlite3": "*",
"sensio/framework-extra-bundle": "^4.0",
"fzaninotto/faker": "^1.5",
"sensio/framework-extra-bundle": "^4.0|^5.0",
"fakerphp/faker": "^1.5",
"phpunit/phpunit": "^8.5.27",
"symfony/phpunit-bridge": "^6"
},
Expand All @@ -38,5 +38,12 @@
},
"suggest": {
"propel/propel-acl-bundle": "For using the Propel ACL implementation"
}
},
"repositories": [
{
"type": "git",
"url": "https://github.com/CrossKnowledge/Propel.git",
"packagist.org": false
}
]
}