Ejemplo n.º 1
0
$debug = false;
foreach ($argv as $value) {
    if ($value === "--debug") {
        $debug = true;
    }
}
// add default parameters
$json += array('templates' => 'vendor/*/*', 'template' => 'locale/template.json', 'template_text' => false, 'templates_ignore' => array('/test/', '/tests/'), 'translation_functions' => array('t', 'ht'), 'translation_markers' => array('i18n'), 'extensions' => array('.php', '.haml'), 'include_plural' => true, 'depth' => 3);
if ($debug) {
    echo "Loaded JSON: " . print_r($json, true) . "\n";
}
if (!is_array($json['templates'])) {
    $json['templates'] = array($json['templates']);
}
// make target directories as necessary
make_target_directories(array($json['template']));
// now load all of the components
$all_dirs = array();
foreach ($json['templates'] as $dir) {
    $all_dirs = array_merge($all_dirs, get_all_directories($root . "/" . $dir, $json['depth']));
}
echo "Found " . count($all_dirs) . " potential subdirectories\n";
// this function is from Openclerk::I18n
function strip_i18n_key($key)
{
    $key = preg_replace("/[\r\n]+/im", " ", $key);
    $key = preg_replace("/[\\s]{2,}/im", " ", $key);
    return trim($key);
}
function strip_comments($text)
{
Ejemplo n.º 2
0
}
$root = $argv[1];
if (!file_exists($root . "/translation-discovery.json")) {
    throw new Exception("No translation-discovery.json found in '{$root}'");
}
$json = json_decode(file_get_contents($root . "/translation-discovery.json"), true);
// add default parameters
$json += array('src' => 'vendor/*/*', 'translations' => array(), 'generate_php' => true, 'depth' => 3);
if (!is_array($json['src'])) {
    $json['src'] = array($json['src']);
}
if (!$json['translations']) {
    throw new Exception("No translations defined in translation-discovery.json");
}
// make target directories as necessary
make_target_directories($json['translations']);
// now load all of the components
$all_dirs = get_all_directories($root, $json['depth']);
echo "Found " . count($all_dirs) . " potential subdirectories\n";
$selected_dirs = array();
foreach ($json['src'] as $pattern) {
    $selected_dirs = array_merge($selected_dirs, get_directories_to_search($all_dirs, $pattern));
}
echo "Filtered to " . count($selected_dirs) . " matching paths\n";
// default translation strings are empty
$translations = array();
foreach ($json['translations'] as $code => $ignored) {
    $translations[$code] = array();
}
if ($selected_dirs) {
    $filename = "translations.json";
Ejemplo n.º 3
0
    fwrite($fp, file_get_contents($include));
    fwrite($fp, "\n");
}
fclose($fp);
echo "Processing " . count($images) . " image paths...\n";
// recursive copy
foreach ($images as $include) {
    echo "Copying " . count($include['files']) . " images from " . $include['parent'] . "...\n";
    foreach ($include['files'] as $file) {
        $relative = str_replace($include['parent'] . "/", "", $file);
        // strip off the first part
        $relative = explode("/", $relative, 2);
        $relative = $relative[1];
        $destination = $json['images'] . $relative;
        // make the target directory if it does not exist
        make_target_directories(array($destination));
        copy($file, $destination);
    }
}
function get_all_images($root, $relative, $filetypes)
{
    $result = array();
    if ($handle = opendir($root . $relative)) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != "..") {
                if (is_dir($root . $relative . $entry)) {
                    // is directory?
                    $result = array_merge($result, get_all_images($root, $relative . $entry . "/", $filetypes));
                } elseif (strpos($entry, ".") !== false) {
                    // is file?
                    $extension = strtolower(substr($entry, strrpos($entry, ".") + 1));
Ejemplo n.º 4
0
$json = json_decode(file_get_contents($discovery), true);
if (!$json) {
    throw new Exception("Could not load JSON from {$discovery}");
}
// add default parameters
$json += array('namespace' => 'DiscoveredComponents', 'src' => 'vendor/*/*', 'dest' => 'generated/components', 'depth' => 3, 'composer_depth' => 3, 'autoload' => 'vendor/autoload.php');
if (!is_array($json['src'])) {
    $json['src'] = array($json['src']);
}
echo "Loaded " . count($json['components']) . " component discovery patterns\n";
// load autoloader if necessary
if ($json["autoload"]) {
    require $json["autoload"];
}
// make target directories as necessary
make_target_directories(array($json['dest'] . "/"));
// now load all of the components
$all_dirs = get_all_directories($root, $json['depth']);
echo "Found " . count($all_dirs) . " potential subdirectories\n";
$selected_dirs = array();
foreach ($json['src'] as $pattern) {
    $selected_dirs = array_merge($selected_dirs, get_directories_to_search($all_dirs, $pattern));
}
echo "Filtered to " . count($selected_dirs) . " matching paths\n";
$component_discoverers = array();
$namespace = $json['namespace'];
if ($selected_dirs) {
    foreach ($json['components'] as $key => $component_value) {
        if (!is_array($component_value)) {
            $component_value = array("file" => $component_value);
        }