Conversation
|
First commit bash+manual, second one automated with this: <?php
$srcDir = __DIR__.'/src/';
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($srcDir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::LEAVES_ONLY) as $newFile) {
$class = substr($newFile, strlen($srcDir), -4);
$oldClass = 'Twig_'.strtr(substr(file_get_contents($newFile), 2, -5), '/', '_');
$newClass = 'Twig\\'.strtr($class, '/', '\\');
$oldFile = '/lib/'.strtr($oldClass, '_', '/').'.php';
$ns = substr($newClass, 0, strrpos($newClass, '\\'));
$newClassBase = substr($newClass, 1 + strrpos($newClass, '\\'));
$dots = str_repeat('/..', substr_count($newClass, '\\'));
file_put_contents($newFile, <<<EOTXT
<?php
namespace $ns;
require __DIR__.'$dots$oldFile';
if (\\false) {
class $newClassBase extends \\$oldClass
{
}
}
EOTXT
);
file_put_contents(__DIR__.$oldFile, <<<EOTXT
class_alias('$oldClass', '$newClass', false);
EOTXT
, FILE_APPEND
);
} |
b78d5c5 to
a56b450
Compare
|
Great move. I don't understand why we need to create an alias and a subclass for each existing class ? |
|
That's a good question :) |
| } | ||
| } | ||
|
|
||
| class_alias('Twig_Node_SetTemp', 'Twig\Node\SetTempNode', false); |
There was a problem hiding this comment.
just wondering: this class has been removed in 2.x
why? missing deprecation notice in 1.x or mistake in 2.x?
There was a problem hiding this comment.
I would say, missing @internal in 1.x
| */ | ||
|
|
||
| /** | ||
| * @internal |
|
@GromNaN using a fully qualified name to access |
|
Wouldn't it be simpler to just add a |
@stof How is that possible? I couldn't find a way to do so. I get one of these errors.
|
|
Nvm, I got it: |
|
Wouldn't it be better to add the new classes together with scalar typehints? |
|
@mindplay-dk the heavy call is the autoloader, not the file hit (when opcache is activated of course), so I prefer doing it this way because it makes it easy to then move gradually to using namespaces internally. @Tobion I prefer keeping one topic per PR. This one is on branch 1.x btw, so php5.3 mini. |
|
Thus, using |
|
Thank you @nicolas-grekas. |
| } | ||
| } | ||
|
|
||
| class_alias('Twig_SimpleFilter', 'Twig\TwigFilter', false); |
There was a problem hiding this comment.
Yeah for that. It gives us a clean migration path from Twig 1.x to 2.x to 3.x 😄
|
Note that before tagging 1.34/2.4, we should make sure that we don't want to rename more classes. Doing it while adding the namespaced aliases makes it easy. |
|
Could you give an 3v4l example about |
No description provided.