Skip to content

Instantly share code, notes, and snippets.

@kbsali
Last active December 16, 2015 13:29
Show Gist options
  • Save kbsali/5442372 to your computer and use it in GitHub Desktop.
Save kbsali/5442372 to your computer and use it in GitHub Desktop.
Updates the value of ICU_DATA_VERSION to '4.2' if needed
...
"scripts": {
"post-install-cmd": [
"Mopa\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::postInstallSymlinkTwitterBootstrap",
"vendor/bin/security-checker security:check",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"YourBundle\\Composer\\ScriptHandler::updateIcuVersion"
],
"post-update-cmd": [
"Mopa\\Bundle\\BootstrapBundle\\Composer\\ScriptHandler::postInstallSymlinkTwitterBootstrap",
"vendor/bin/security-checker security:check",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"YourBundle\\Composer\\ScriptHandler::updateIcuVersion"
]
},
...
<?php
namespace YourBundle\Composer;
class ScriptHandler
{
public static function updateIcuVersion($event)
{
if (false === self::isCentos()) {
return;
}
$options = self::getOptions($event);
$vendorDir = $options['symfony-vendor-dir'];
if (!is_dir($vendorDir)) {
echo 'The symfony-vendor-dir ('.$vendorDir.') specified in composer.json was not found in '.getcwd().', can not build bootstrap file.'.PHP_EOL;
return;
}
$LocaleClassFile = $vendorDir.'/symfony/symfony/src/Symfony/Component/Locale/Locale.php';
if (!file_exists($LocaleClassFile)) {
echo 'The Locale class file ('.$LocaleClassFile.') was not found.'.PHP_EOL;
return;
}
$LocaleClass = file_get_contents($LocaleClassFile);
if (false === strpos($LocaleClass, "const ICU_DATA_VERSION = '49';")) {
echo 'String "const ICU_DATA_VERSION = \'49\';" not found in '.$LocaleClassFile.', the script might need an update'.PHP_EOL;
return;
}
$LocaleClass = str_replace("const ICU_DATA_VERSION = '49';", "const ICU_DATA_VERSION = '4.2';", $LocaleClass);
file_put_contents($LocaleClassFile, $LocaleClass);
}
protected static function getOptions($event)
{
$options = array_merge(array(
'symfony-vendor-dir' => 'vendor',
), $event->getComposer()->getPackage()->getExtra());
return $options;
}
protected static function isCentos()
{
$ret = exec('cat /etc/*-release', $release);
foreach ($release as $v) {
if (false !== stripos($v, 'centos')) {
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment