Potsky\LaravelLocalizationHelpers\Factory\Tools::minifyString PHP Метод

minifyString() публичный статический Метод

Remove all whitesapces, line-breaks, and tabs from string for better regex recognition
public static minifyString ( $string ) : string
$string
Результат string
    public static function minifyString($string)
    {
        $string = str_replace(PHP_EOL, ' ', $string);
        $string = preg_replace('/[\\r\\n]+/', "\n", $string);
        return preg_replace('/[ \\t]+/', ' ', $string);
    }

Usage Example

 /**
  * Extract all translations from the provided file
  *
  * Remove all translations containing :
  * - $  -> auto-generated translation cannot be supported
  * - :: -> package translations are not taken in account
  *
  * @param string $path          the file path
  * @param array  $trans_methods an array of regex to catch
  *
  * @return array an array dot of found translations
  */
 public function extractTranslationFromPhpFile($path, $trans_methods)
 {
     $result = array();
     $string = Tools::minifyString(file_get_contents($path));
     foreach (array_flatten($trans_methods) as $method) {
         preg_match_all($method, $string, $matches);
         foreach ($matches[1] as $k => $v) {
             if (strpos($v, '$') !== false) {
                 unset($matches[1][$k]);
             }
             if (strpos($v, '::') !== false) {
                 unset($matches[1][$k]);
             }
         }
         $result = array_merge($result, array_flip($matches[1]));
     }
     return $result;
 }