/*
* This file is part of phpMorphy project
*
* Copyright (c) 2007-{$current_year} Kamaev Vladimir <*****@*****.**>
*
*     This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
*     This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
*     You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/

EOS;
phpMorphy_Util_Fs::applyToEachFile(getcwd(), '~\\.php$~', function ($path) use($copyright_text, $marker_text) {
    $content = file_get_contents($path);
    if (substr($content, 0, 5) !== '<' . '?php' || strpos($content, $marker_text) !== false) {
        echo "Skip {$path}\n";
        return;
    }
    $content = '<' . '?php' . PHP_EOL . $copyright_text . substr($content, 5);
    file_put_contents($path, $content);
}, true);
#!/usr/bin/env php
<?php 
set_include_path(__DIR__ . '/../../src/' . PATH_SEPARATOR . get_include_path());
require 'phpMorphy.php';
$root_dir = PHPMORPHY_DIR . '/phpMorphy';
$out_dir = PHPMORPHY_DIR;
phpMorphy_Util_Fs::applyToEachFile($root_dir, '/\\.php$/', function ($path) use($out_dir) {
    convert_file($path, $out_dir, 'logger');
});
phpMorphy_Util_Fs::deleteEmptyDirectories($root_dir, 'logger');
function convert_file($path, $outDir, $log)
{
    global $out_dir;
    $lines = array_map('rtrim', file($path));
    try {
        $descriptor = phpMorphy_Generator_PhpFileParser::parseFile($path);
    } catch (Exception $e) {
        throw new phpMorphy_Exception("Can`t parse '{$path}': " . $e->getMessage());
    }
    if (count($descriptor->classes) < 1) {
        return;
    }
    $first_class = $descriptor->classes[0];
    $first_significant_line = null === $first_class->phpDoc ? $first_class->startLine : $first_class->phpDoc->startLine;
    $header = array_slice($lines, 0, $first_significant_line - 1);
    $header = implode(PHP_EOL, $header);
    $out_files = array();
    $classes_count = count($descriptor->classes);
    foreach ($descriptor->classes as $class_descriptor) {
        $class_name = $class_descriptor->name;
        $out_path = $outDir . DIRECTORY_SEPARATOR . phpMorphy_Loader::classNameToFilePath($class_name);
        print_usage();
    }
    generate_decorators_from_file($input_file, $out_dir, 'logger');
} else {
    if (isset($opts['decoratee'])) {
        if (false === $opts['decorator'] || false === $opts['decoratee']) {
            print_usage();
        }
        $decoratee = $opts['decoratee'];
        $decorator = $opts['decorator'];
        generate_decorator($decoratee, $decorator, $out_dir, 'logger');
    } else {
        if (isset($opts['regenerate'])) {
            $root_dir = PHPMORPHY_DIR . '/phpMorphy';
            phpMorphy_Util_Fs::applyToEachFile($root_dir, '/Decorator\\.php$/', function ($path) use($out_dir) {
                regenerate_decorator($path, $out_dir, 'logger');
            });
        } else {
            print_usage();
        }
    }
}
function generate_decorators_from_file($fileName, $outDir, $log)
{
    $file_descriptor = phpMorphy_Generator_PhpFileParser::parseFile($fileName);
    foreach ($file_descriptor->classes as $class_desc) {
        $class = $class_desc->name;
        $decorator = phpMorphy_Generator_Decorator_Generator::getDecoratorClassName($class);
        generate_decorator($class, $decorator, $outDir, $log);
    }
}