Example #1
0
/**
* Generates plugin XML
* This command generates the necessary files and configuration 
* to "plugin" to a preexisting Magento 2 object manager object. 
*
*     pestle.phar generate_plugin_xml Pulsestorm_Helloworld 'Magento\Framework\Logger\Monolog' 'Pulsestorm\Helloworld\Plugin\Magento\Framework\Logger\Monolog'
* 
* @argument module_name Create in which module? [Pulsestorm_Helloworld]
* @argument class Which class are you plugging into? [Magento\Framework\Logger\Monolog]
* @argument class_plugin What's your plugin class name? [<$module_name$>\Plugin\<$class$>]
* @command generate_plugin_xml
*/
function pestle_cli($argv)
{
    // $module_info = askForModuleAndReturnInfo($argv);
    $module_info = getModuleInformation($argv['module_name']);
    $class = $argv['class'];
    $class_plugin = $argv['class_plugin'];
    $path_di = $module_info->folder . '/etc/di.xml';
    if (!file_exists($path_di)) {
        $xml = simplexml_load_string(getBlankXml('di'));
        writeStringToFile($path_di, $xml->asXml());
        output("Created new {$path_di}");
    }
    $xml = simplexml_load_file($path_di);
    //     $plugin_name    = strToLower($module_info->name) . '_' . underscoreClass($class);
    //     simpleXmlAddNodesXpath($xml,
    //         "/type[@name=$class]/plugin[@name=$plugin_name,@type=$class_plugin]");
    $type = $xml->addChild('type');
    $type->addAttribute('name', $class);
    $plugin = $type->addChild('plugin');
    $plugin->addAttribute('name', strToLower($module_info->name) . '_' . underscoreClass($class));
    $plugin->addAttribute('type', $class_plugin);
    writeStringToFile($path_di, formatXmlString($xml->asXml()));
    output("Added nodes to {$path_di}");
    $path_plugin = getPathFromClass($class_plugin);
    $body = implode("\n", ['    //function beforeMETHOD($subject, $arg1, $arg2){}', '    //function aroundMETHOD($subject, $procede, $arg1, $arg2){return $proceed($arg1, $arg2);}', '    //function afterMETHOD($subject, $result){return $result;}']);
    $class_definition = str_replace('<$body$>', "\n{$body}\n", createClassTemplate($class_plugin));
    writeStringToFile($path_plugin, $class_definition);
    output("Created file {$path_plugin}");
}
Example #2
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 #3
0
function createControllerClassForRoute($module, $area, $acl)
{
    $class = createControllerClassName($module, $area, $acl);
    $controllerClass = createControllerClass($class, $area);
    $path_controller = getPathFromClass($class);
    writeStringToFile($path_controller, $controllerClass);
    output($path_controller);
}
Example #4
0
function generateNewClass($argv)
{
    $pathType = getPathFromClass($argv['type']);
    $typeGlobalNs = '\\' . trim($argv['for'], '\\');
    $classContents = createClassTemplate($argv['type'], $typeGlobalNs);
    if (isTypeInterface($typeGlobalNs)) {
        $classContents = createClassTemplate($argv['type'], null, $typeGlobalNs);
    }
    $classContents = str_replace('<$body$>', '', $classContents);
    if (!file_exists($pathType)) {
        output("Creating {$pathType}");
        writeStringToFile($pathType, $classContents);
    } else {
        output("{$pathType} already exists, skipping creation");
    }
}
Example #5
0
function createDataClass($module_info, $model_name)
{
    $className = str_replace('_', '\\', $module_info->name) . '\\Setup\\InstallData';
    $path = getPathFromClass($className);
    $template = createClassTemplate($className, false, '\\Magento\\Framework\\Setup\\InstallDataInterface');
    $contents = str_replace('<$body$>', templateInstallDataFunction(), $template);
    if (!file_exists($path)) {
        output("Creating: " . $path);
        writeStringToFile($path, $contents);
    } else {
        output("Data Installer Already Exists: " . $path);
    }
}