Esempio n. 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}");
}
Esempio n. 2
0
/**
* Generates new module XML, adds to file system
* This command generates the necessary files and configuration
* to add a new module to a Magento 2 system.
*
*    pestle.phar Pulsestorm TestingCreator 0.0.1
*
* @argument namespace Vendor Namespace? [Pulsestorm]
* @argument name Module Name? [Testbed]
* @argument version Version? [0.0.1]
* @command generate_module
*/
function pestle_cli($argv)
{
    $namespace = $argv['namespace'];
    $name = $argv['name'];
    $version = $argv['version'];
    $full_module_name = implode('_', [$namespace, $name]);
    $config = simplexml_load_string(getBlankXml('module'));
    $module = $config->addChild('module');
    $module->addAttribute('name', $full_module_name);
    $module->addAttribute('setup_version', $version);
    $xml = $config->asXml();
    $base_dir = getBaseMagentoDir();
    $module_dir = implode('/', [$base_dir, 'app/code', $namespace, $name]);
    $etc_dir = $module_dir . '/etc';
    $reg_path = $module_dir . '/registration.php';
    if (is_dir($etc_dir)) {
        output("Module directory [{$etc_dir}] already exists, bailing");
        return;
    }
    mkdir($etc_dir, 0777, $etc_dir);
    writeStringToFile($etc_dir . '/module.xml', $xml);
    output("Created: " . $etc_dir . '/module.xml');
    $register = templateRegistrationPhp($full_module_name);
    writeStringToFile($reg_path, $register);
    output("Created: " . $reg_path);
}
Esempio n. 3
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);
}
Esempio n. 4
0
function createViewXmlFile($base_folder, $package, $theme, $area)
{
    $path = $base_folder . '/etc/view.xml';
    $xml = simplexml_load_string(getBlankXml('view'));
    $media = simpleXmlAddNodesXpath($xml, 'media');
    output("Creating: {$path}");
    writeStringToFile($path, formatXmlString($xml->asXml()));
}
Esempio n. 5
0
function createHandleFile($module_info, $area, $template, $class, $handle)
{
    $xml = simplexml_load_string(getBlankXml('layout_handle'));
    $name = strToLower($module_info->name) . '_block_' . strToLower(getShortClassNameFromClass($class));
    simpleXmlAddNodesXpath($xml, 'referenceBlock[@name=content]/block[' . '@template=' . $template . ',' . '@class=' . $class . ',' . '@name=' . $name . ']');
    $path = $module_info->folder . '/view/' . $area . '/layout/' . $handle . '.xml';
    output("Creating: {$path}");
    writeStringToFile($path, $xml->asXml());
}
Esempio n. 6
0
function createDiIfNeeded($module_dir)
{
    $path_di_xml = $module_dir . '/etc/di.xml';
    if (!file_exists($path_di_xml)) {
        $xml_di = simplexml_load_string(getBlankXml('di'));
        simpleXmlAddNodesXpath($xml_di, 'type[@name=Magento\\Framework\\Console\\CommandList]');
        writeStringToFile($path_di_xml, formatXmlString($xml_di->asXml()));
    }
    return $path_di_xml;
}
Esempio n. 7
0
function loadOrCreateDiXml($module_info)
{
    $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);
    return ['path' => $path_di, 'xml' => $xml];
}
Esempio n. 8
0
function createRoutesXmlFile($module_info, $area, $frontname, $router_id, $route_id)
{
    $module = $module_info->name;
    $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()));
    output($path);
    return $xml;
}
Esempio n. 9
0
/**
* One Line Description
*
* @command generate_acl
* @argument module_name Which Module? [Pulsestorm_HelloWorld]
* @argument rule_ids Rule IDs? [<$module_name$>::top,<$module_name$>::config,]
*/
function pestle_cli($argv)
{
    extract($argv);
    $rule_ids = explode(',', $rule_ids);
    $rule_ids = array_filter($rule_ids);
    $xml = simplexml_load_string(getBlankXml('acl'));
    $nodes = $xml->xpath('//resource[@id="Magento_Backend::admin"]');
    $node = array_shift($nodes);
    foreach ($rule_ids as $id) {
        $id = trim($id);
        $node = $node->addChild('resource');
        $node->addAttribute('id', $id);
        $node->addAttribute('title', 'TITLE HERE FOR ' . $id);
    }
    $path = getBaseModuleDir($module_name) . '/etc/acl.xml';
    writeStringToFile($path, formatXmlString($xml->asXml()));
    output("Created {$path}");
}
Esempio n. 10
0
/**
* One Line Description
*
* @command generate_acl
* @argument module_name Which Module? [Pulsestorm_HelloWorld]
* @argument rule_ids Rule IDs? [<$module_name$>::top,<$module_name$>::config,]
*/
function pestle_cli($argv)
{
    extract($argv);
    $rule_ids = explode(',', $rule_ids);
    $rule_ids = array_filter($rule_ids);
    $path = getBaseModuleDir($module_name) . '/etc/acl.xml';
    if (!file_exists($path)) {
        $xml = simplexml_load_string(getBlankXml('acl'));
        writeStringToFile($path, $xml->asXml());
    }
    $xml = simplexml_load_file($path);
    $xpath = 'acl/resources/resource[@id=Magento_Backend::admin]';
    foreach ($rule_ids as $id) {
        $id = trim($id);
        $xpath .= '/resource[@id=' . $id . ',@title=TITLE HERE FOR]';
    }
    simpleXmlAddNodesXpath($xml, $xpath);
    writeStringToFile($path, formatXmlString($xml->asXml()));
    output("Created {$path}");
}
Esempio n. 11
0
function loadOrCreateMenuXml($path)
{
    if (!file_exists($path)) {
        $xml = simplexml_load_string(getBlankXml('menu'));
        writeStringToFile($path, $xml->asXml());
    }
    $xml = simplexml_load_file($path);
    return $xml;
}
Esempio n. 12
0
function generateDiXml($module_info)
{
    $path_di = $module_info->folder . '/etc/adminhtml/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);
    $item = simpleXmlAddNodesXpath($xml, 'type[@name=Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\CollectionFactory]/' . 'arguments/argument[@name=collections,@xsi:type=array]/' . 'item[@name=pulsestorm_commercebug_log_data_source,@xsi:type=string]');
    $item[0] = 'Pulsestorm\\Commercebug\\Model\\ResourceModel\\Log\\Grid\\Collection';
    $virtualType = addVirtualType($xml, 'Pulsestorm\\Commercebug\\Model\\ResourceModel\\Log\\Grid\\Collection', 'Magento\\Framework\\View\\Element\\UiComponent\\DataProvider\\SearchResult');
    $arguments = $virtualType->addChild('arguments');
    $argument = addArgument($arguments, 'mainTable', 'string', 'pulsestorm_commercebug_log');
    $argument = addArgument($arguments, 'resourceModel', 'string', 'Pulsestorm\\Commercebug\\Model\\ResourceModel\\Log');
    return $xml;
}