Skip to content

Instantly share code, notes, and snippets.

@co3k
Created March 3, 2010 08:20
Show Gist options
  • Select an option

  • Save co3k/320433 to your computer and use it in GitHub Desktop.

Select an option

Save co3k/320433 to your computer and use it in GitHub Desktop.
<?php
require_once '/home/co3k/www/sf/op3-ebihara/config/ProjectConfiguration.class.php';
ProjectConfiguration::getApplicationConfiguration('pc_frontend', 'prod', false);
$list = '[
{
"old" : "sfOpenPNEView",
"new" : "opView"
},
{
"old" : "sfOpenPNEPluginConfigHandler",
"new" : "opPluginConfigHandler"
},
{
"old" : "sfOpenPNEApplicationConfiguration",
"new" : "opApplicationConfiguration"
},
{
"old" : "sfOpenPNEViewConfigHandler",
"new" : "opViewConfigHandler"
},
{
"old" : "sfOpenPNEMailSend",
"new" : "opMailSend"
},
{
"old" : "sfOpenPNEAuthForm",
"new" : "opAuthForm"
},
{
"old" : "sfOpenPNEPasswordForm",
"new" : "opPasswordForm"
},
{
"old" : "sfOpenPNEExecutionFilter",
"new" : "opExecutionFilter"
},
{
"old" : "sfOpenPNEWebRequest",
"new" : "opWebRequest"
},
{
"old" : "sfOpenPNESecurityUser",
"new" : "opSecurityUser"
},
{
"old" : "sfOpenPNECommunityAction",
"new" : "opCommunityAction"
},
{
"old" : "sfOpenPNEFriendComponents",
"new" : "opFriendComponents"
},
{
"old" : "sfOpenPNEMemberAction",
"new" : "opMemberAction"
},
{
"old" : "sfOpenPNEFriendAction",
"new" : "opFriendAction"
},
{
"old" : "sfOpenPNECommunityComponents",
"new" : "opCommunityComponents"
},
{
"old" : "sfOpenPNEMemberComponents",
"new" : "opMemberComponents"
}
]';
// -------------
$decoded_list = json_decode($list);
// PHP 5.3.0 +
const BC_CLASS_TEMPLATE = '<?php
/**
* This file is part of the OpenPNE package.
* (c) OpenPNE Project (http://www.openpne.jp/)
*
* For the full copyright and license information, please view the LICENSE
* file and the NOTICE file that were distributed with this source code.
*/
/**
* This class is for keeping backward compatibility.
*
* If you want to add new feature to this class, please add this to
* the ##NEW_CLASS## class, a parent class of this class.
* And of course using this class is deprecated. You should not begin to
* use this class, and you have to replace the code that is using this class.
*
* @package OpenPNE
* @subpackage ##SUBPACKAGE##
* @author Kousuke Ebihara <[email protected]>
*/
##DEFINE_KEYWORD## ##OLD_CLASS## extends ##NEW_CLASS##
{
}
';
function replace_op_class_file(stdClass $v)
{
$r = new ReflectionClass($v->old);
$subpackage = 'util';
$matches = array();
if (preg_match('/@subpackage\s+(\S+)\n/', $r->getDocComment(), $matches))
{
$subpackage = $matches[1];
}
$bc_class_keyword = 'class';
if ($r->isAbstract())
{
$bc_class_keyword = 'abstract '.$bc_class_keyword;
}
elseif ($r->isFinal())
{
$bc_class_keyword = 'final '.$bc_class_keyword;
}
elseif ($r->isInterface())
{
$bc_class_keyword = 'interface';
}
$bc_class = strtr(BC_CLASS_TEMPLATE, array(
'##NEW_CLASS##' => $v->new,
'##OLD_CLASS##' => $v->old,
'##SUBPACKAGE##' => $subpackage,
'##DEFINE_KEYWORD##' => $bc_class_keyword,
));
$main_class = file_get_contents($r->getFileName());
$main_class_line = explode("\n", $main_class);
$define_line = $r->getStartLine();
$main_class_line[$define_line - 1] = str_replace($v->old, $v->new, $main_class_line[$define_line - 1]);
$main_class = implode("\n", $main_class_line);
$main_class = str_replace('Kousuke Ebihara <[email protected]>', 'Kousuke Ebihara <[email protected]>', $main_class);
file_put_contents(str_replace($v->old, $v->new, $r->getFileName()), $main_class);
file_put_contents($r->getFileName(), $bc_class);
return $v;
}
array_map('replace_op_class_file', $decoded_list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment