Example #1
0
/**
* Creates a Route XML
* generate_route module area id 
* @command generate_route
*/
function pestle_cli($argv)
{
    $module_info = askForModuleAndReturnInfo($argv);
    $module = $module_info->name;
    $legend = ['frontend' => 'standard', 'adminhtml' => 'admin'];
    $areas = array_keys($legend);
    $area = inputOrIndex('Which area? [frontend, adminhtml]', 'frontend', $argv, 1);
    $router_id = $legend[$area];
    if (!in_array($area, $areas)) {
        throw new Exception("Invalid areas");
    }
    $frontname = inputOrIndex('Frontname/Route ID?', null, $argv, 2);
    $route_id = $frontname;
    $path = $module_info->folder . '/etc/' . $area . '/routes.xml';
    if (!file_exists($path)) {
        $xml = simplexml_load_string(getBlankXml('routes'));
        writeStringToFile($path, $xml->asXml());
    }
    $xml = simplexml_load_file($path);
    simpleXmlAddNodesXpath($xml, "router[@id={$router_id}]/" . "route[@id={$route_id},@frontName={$frontname}]/" . "module[@name={$module}]");
    writeStringToFile($path, formatXmlString($xml->asXml()));
    $class = str_replace('_', '\\', $module) . '\\Controller\\Index\\Index';
    $controllerClass = createControllerClass($class, $area);
    $path_controller = getPathFromClass($class);
    writeStringToFile($path_controller, $controllerClass);
    output($path);
    output($path_controller);
}
Example #2
0
/**
* Searches controllers
* @command search_controllers
*/
function pestle_cli($argv)
{
    $base = inputOrIndex("Which folder to search?", 'vendor/magento', $argv, 0);
    $controllers = getAllControllerFiles($base);
    $controllers = getControllersWithExecuteMethod($controllers);
    $controllers = getExecuteMethods($controllers);
}
Example #3
0
/**
* 
* @command check_class_and_namespace
*/
function pestle_cli($argv)
{
    $path = inputOrIndex('Which folder?', '/path/to/magento/app/code/Pulsestorm', $argv, 0);
    $files = glob_recursive($path . '/*');
    foreach ($files as $file) {
        $file = realpath($file);
        if (strpos($file, '.php') === false) {
            output("NOT .php: Skipping {$file}");
            continue;
        }
        $contents = file_get_contents($file);
        $namespace = parseNamespace($contents);
        if (!$namespace) {
            output("No Namspace: Skipping {$file}");
            continue;
        }
        $class = parseClass($contents);
        if (!$class) {
            output("No Class: Skipping {$class}");
            continue;
        }
        $full_class = $namespace . '\\' . $class;
        $path = str_replace('\\', '/', $full_class) . '.php';
        if (strpos($file, $path) === false) {
            output("ERROR: Path `{$path}` not in");
            output($file);
        } else {
            output('.');
        }
    }
}
Example #4
0
/**
* This is a test
* @command dev_namespace
*/
function pestle_cli($argv)
{
    $file = inputOrIndex("File?", '', $argv, 0);
    $contents = file_get_contents($file);
    preg_match('%namespace (.+?);%', $contents, $matches);
    $namespace = $matches[1];
    $namespace = strToLower($namespace);
    $path = 'modules/' . str_replace('\\', '/', $namespace);
    $full_name = $path . '/module.php';
    if (!is_dir($path)) {
        mkdir($path, 0755, true);
    }
    copy($file, $full_name);
    rename($file, $file . '.moved');
}
Example #5
0
/**
* Converts a markdown files to an aiff
* @command md_to_say
*/
function pestle_cli($argv)
{
    $file = inputOrIndex("Path to Markdown File?", null, $argv, 0);
    $contents = file_get_contents($file);
    $html = Markdown::defaultTransform($contents);
    $html = preg_replace('%<pre><code>.+?</code></pre>%six', '<p>[CODE SNIPPED].</p>', $html);
    $html = str_replace('</p>', '</p><br>', $html);
    $tmp = tempnam('/tmp', 'md_to_say') . '.html';
    file_put_contents($tmp, $html);
    $cmd = 'textutil -convert txt ' . $tmp;
    `{$cmd}`;
    $tmp_txt = swapExtension($tmp, 'html', 'txt');
    $tmp_aiff = swapExtension($tmp, 'html', 'aiff');
    $cmd = "say -f {$tmp_txt} -o {$tmp_aiff}";
    output($cmd);
    `{$cmd}`;
    // $tmp_txt = preg_replace('%\.html$%','.txt', $tmp);
    output($tmp_aiff);
    output("Done");
}
Example #6
0
function limitArgumentsIfPresentInDocBlock($arguments, $parsed_doc_block)
{
    if (!array_key_exists('argument', $parsed_doc_block)) {
        return $arguments;
    }
    $new_arguments = [];
    $c = 0;
    foreach ($parsed_doc_block['argument'] as $argument) {
        list($argument_name, $text) = explode(' ', $argument, 2);
        $text_parts = parseQuestionAndDefaultFromText($text, $new_arguments);
        $question = $text_parts['question'];
        $default = trim($text_parts['default']);
        $new_arguments[$argument_name] = inputOrIndex($question, $default, $arguments, $c);
        $c++;
    }
    return $new_arguments;
}
Example #7
0
function askForModuleAndReturnFolder($argv)
{
    $module_folder = inputOrIndex("Which module?", 'Magento_Catalog', $argv, 0);
    list($package, $vendor) = explode('_', $module_folder);
    return getBaseMagentoDir() . "/app/code/{$package}/{$vendor}";
}
Example #8
0
function limitArgumentsIfPresentInDocBlock($arguments, $parsed_doc_block, $reflected_command)
{
    if (!array_key_exists('argument', $parsed_doc_block)) {
        return $arguments;
    }
    $new_arguments = [];
    $c = 0;
    foreach ($parsed_doc_block['argument'] as $argument) {
        $parts = explode(' ', $argument, 2);
        if (count($parts) !== 2) {
            throw new Exception("@argument {$argument} invalid -- needs argument name AND description");
        }
        $argument_name = $parts[0];
        $text = $parts[1];
        $text_parts = parseQuestionAndDefaultFromText($text, $new_arguments);
        $question = $text_parts['question'];
        $default = trim($text_parts['default']);
        if (strpos($question, '@callback ') === 0) {
            $parts = explode('@callback ', $question);
            $callback = $reflected_command->getNamespaceName() . '\\' . array_pop($parts);
            $r = new ReflectionFunction($callback);
            $new_arguments[$argument_name] = $r->invokeArgs([$arguments, $c]);
        } else {
            $new_arguments[$argument_name] = inputOrIndex($question, $default, $arguments, $c);
        }
        $c++;
    }
    return $new_arguments;
}