Advertisement
xenoside

phpstorm 9 all project encoding change

Sep 4th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.33 KB | None | 0 0
  1. <?php
  2.  
  3. $files = glob('*/.idea/encodings.xml');
  4.  
  5. foreach($files as $file) {
  6.     addProjectEncoding($file);
  7. }
  8.  
  9. function addProjectEncoding($filename) {
  10.     $dom = new DOMDocument();
  11.     $dom->load($filename);
  12.  
  13.     $encoding = null;
  14.     $components = $dom->getElementsByTagName('component');
  15.  
  16.     foreach($components as $component) {
  17.         if($component->getAttribute('name') != 'Encoding') continue;
  18.         $encoding = $component;
  19.         break;
  20.     }
  21.  
  22.     if(!$encoding) {
  23.         $encoding = $dom->createElement('component');
  24.         $encoding->setAttribute('name', 'Encoding');
  25.         $dom->appendChild($encoding);
  26.     }
  27.  
  28.     $encoding->setAttribute('useUTFGuessing', 'true');
  29.     $encoding->setAttribute('native2AsciiForPropertiesFiles', 'false');
  30.     $encoding->setAttribute('defaultCharsetForPropertiesFiles', 'UTF-8');
  31.  
  32.     $project = null;
  33.     $files = $encoding->getElementsByTagName('file');
  34.  
  35.     foreach($files as $file) {
  36.         if($file->getAttribute('url') != 'PROJECT') continue;
  37.         $project = $file;
  38.         break;
  39.     }
  40.     if(!$project) {
  41.         $project = $dom->createElement('file');
  42.         $project->setAttribute('url', 'PROJECT');
  43.         $encoding->appendChild($project);
  44.     }
  45.     $project->setAttribute('charset', 'UTF-8');
  46.  
  47.     $dom->save($filename);
  48.     echo $filename, "\n";
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement