Exemple #1
0
 public function testBothAtOne()
 {
     pestle_import('Pulsestorm\\Pestle\\Library\\output');
     ob_start();
     output("Hello");
     $string = ob_get_clean();
     $this->assertEquals($string, 'Hello' . "\n");
     pestle_import('Pulsestorm\\Magento2\\Cli\\Test_Output\\output');
     ob_start();
     output("Hello");
     $string = ob_get_clean();
     $this->assertEquals($string, 'I am hard coded and here for a test.');
 }
Exemple #2
0
<?php

namespace Pulsestorm\Magento2\Cli\Generate\Route;

use function Pulsestorm\Pestle\Importer\pestle_import;
use Exception;
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Pestle\\Library\\inputOrIndex');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\askForModuleAndReturnInfo');
pestle_import('Pulsestorm\\Xml_Library\\simpleXmlAddNodesXpath');
pestle_import('Pulsestorm\\Xml_Library\\formatXmlString');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Magento2\\Cli\\Xml_Template\\getBlankXml');
pestle_import('Pulsestorm\\Magento2\\Cli\\Path_From_Class\\getPathFromClass');
function createControllerClassTemplate($class, $extends = false, $implements = false)
{
    $class = trim($class, '\\');
    $parts = explode('\\', $class);
    $name = array_pop($parts);
    $template = '<' . '?' . 'php' . "\n" . 'namespace ' . implode('\\', $parts) . ";\n" . "class {$name}";
    if ($extends) {
        $template .= " extends {$extends}";
    }
    if ($implements) {
        $template .= " implements {$implements}";
    }
    $template .= "\n" . '{' . '<$body$>' . '}' . "\n";
    return $template;
}
function createControllerClass($class, $area)
Exemple #3
0
namespace Pulsestorm\Magento2\Cli\Generate\Route;

use function Pulsestorm\Pestle\Importer\pestle_import;
use Exception;
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Pestle\\Library\\inputOrIndex');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\askForModuleAndReturnInfo');
pestle_import('Pulsestorm\\Xml_Library\\simpleXmlAddNodesXpath');
pestle_import('Pulsestorm\\Xml_Library\\formatXmlString');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Magento2\\Cli\\Xml_Template\\getBlankXml');
pestle_import('Pulsestorm\\Magento2\\Cli\\Path_From_Class\\getPathFromClass');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createControllerClassTemplate');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createControllerClass');
/**
* 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");
Exemple #4
0
<?php

namespace Pulsestorm\Cli\Md_To_Say;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Pestle\\Library\\inputOrIndex');
use Michelf\Markdown;
function swapExtension($filename, $from, $to)
{
    return preg_replace('%\\.' . $from . '$%', '.' . $to, $filename);
}
/**
* 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);
Exemple #5
0
<?php

namespace Pulsestorm\Magento2\Cli\Generate\Theme;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getBaseMagentoDir');
pestle_import('Pulsestorm\\Xml_Library\\simpleXmlAddNodesXpath');
pestle_import('Pulsestorm\\Magento2\\Cli\\Xml_Template\\getBlankXml');
pestle_import('Pulsestorm\\Xml_Library\\formatXmlString');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\templateRegistrationPhp');
function createFrontendFolders($base_folder, $package, $theme, $area)
{
    //web/css/source
    //fonts
    //images
    //js
    $folders = [$base_folder . '/web/css/source', $base_folder . '/fonts', $base_folder . '/images', $base_folder . '/js'];
    foreach ($folders as $folder) {
        if (!is_dir($folder)) {
            output("Creating: {$folder}");
            mkdir($folder, 0755, true);
        } else {
            output("Exists: {$folder}");
        }
    }
}
function createThemeXmlFile($base_folder, $package, $theme, $area, $parent_name)
{
    $path = $base_folder . '/theme.xml';
Exemple #6
0
<?php

namespace Pulsestorm\Magento2\Cli\Extract_Mage2_System_Xml_Paths;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getSimpleTreeFromSystemXmlFile');
/**
* Generates Mage2 config.xml
* Extracts configuration path's from a Magento 2 module's
* system.xml file, and then generates a config.xml file
* for the creation of default values
*
* @command extract_mage2_system_xml_paths
*/
function pestle_cli($argv)
{
    $paths = $argv;
    if (count($argv) === 0) {
        $paths = [input("Which system.xml?", './app/code/Magento/Theme/etc/adminhtml/system.xml')];
    }
    foreach ($paths as $path) {
        $tree = getSimpleTreeFromSystemXmlFile($path);
    }
    $xml = simplexml_load_string('<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"><default></default></config>');
    foreach ($tree as $section => $groups) {
        $section = $xml->default->addChild($section);
        foreach ($groups as $group => $fields) {
            $group = $section->addChild($group);
            foreach ($fields as $field) {
Exemple #7
0
<?php

namespace Pulsestorm\Magento2\Cli\Generate\Observer;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createClassTemplate');
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\initilizeModuleConfig');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\createClassFile');
/**
* Generates Magento 2 Observer
* This command generates the necessary files and configuration to add 
* an event observer to a Magento 2 system.
*
*    pestle.phar generate_observer Pulsestorm_Generate controller_action_predispatch pulsestorm_generate_listener3 'Pulsestorm\Generate\Model\Observer3'
*
* @command generate_observer
* @argument module Full Module Name? [Pulsestorm_Generate]
* @argument event_name Event Name? [controller_action_predispatch]
* @argument observer_name Observer Name? [<$module$>_listener]
* @argument model_name Class Name? [<$module$>\Model\Observer]
*/
function pestle_cli($argv)
{
    $module = $argv['module'];
    $event_name = $argv['event_name'];
    $observer_name = $argv['observer_name'];
    $model_name = $argv['model_name'];
    $method_name = 'execute';
Exemple #8
0
namespace Pulsestorm\Magento2\Cli\Generate\Route;

use function Pulsestorm\Pestle\Importer\pestle_import;
use Exception;
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Pestle\\Library\\inputOrIndex');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\askForModuleAndReturnInfo');
pestle_import('Pulsestorm\\Xml_Library\\simpleXmlAddNodesXpath');
pestle_import('Pulsestorm\\Xml_Library\\formatXmlString');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Magento2\\Cli\\Xml_Template\\getBlankXml');
pestle_import('Pulsestorm\\Magento2\\Cli\\Path_From_Class\\getPathFromClass');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createControllerClassTemplate');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createControllerClass');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getModuleInformation');
function createControllerClassName($module, $area = 'frontend')
{
    $class = str_replace('_', '\\', $module) . '\\Controller';
    if ($area === 'adminhtml') {
        $class .= '\\Adminhtml';
    }
    $class .= '\\Index\\Index';
    return $class;
}
function getRouterIdFromArea($area)
{
    $legend = ['frontend' => 'standard', 'adminhtml' => 'admin'];
    $areas = array_keys($legend);
    if (!in_array($area, $areas)) {
        throw new Exception("Could not find router id for area");
Exemple #9
0
<?php

namespace Pulsestorm\Magento2\Cli\Check_Registration;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\templateRegistrationPhp');
/**
* Short Description
* Long
* Description
* @command check_registration
*/
function pestle_cli($argv)
{
    $path = 'app/code';
    if (count($argv) > 0) {
        $Path = $argv[0];
    }
    foreach (glob($path . '/*/*') as $file) {
        $parts = explode('/', $file);
        $module = implode('_', array_slice($parts, count($parts) - 2));
        $file = $file . '/' . 'registration.php';
        if (file_exists($file)) {
            output("Registration Exists");
            $contents = file_get_contents($file);
            if (strpos($contents, "'" . $module . "'") !== false) {
                output("Registration contains {$module} string");
                continue;
            }
Exemple #10
0
<?php

namespace Pulsestorm\Magento2\Cli\Export_Module;

error_reporting(E_ALL);
use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Cli\\Token_Parse\\pestle_token_get_all');
pestle_import('Pulsestorm\\Pestle\\Importer\\getPathFromFunctionName');
function getNextTConstantEncapsedStringFromTokenArray($tokens, $index)
{
    $tokens = array_slice($tokens, $index + 1);
    foreach ($tokens as $token) {
        if ($token->token_name === 'T_CONSTANT_ENCAPSED_STRING') {
            return $token;
        }
    }
}
function isTokenFunction($token, $function, $tokens, $index)
{
    if (!isset($tokens[$index + 1])) {
        return false;
    }
    if ($tokens[$index + 1]->token_name === 'T_WHITESPACE') {
        $index++;
        return isTokenFunction($tokens[$index], $function, $tokens, $index);
    }
    return !($token->token_value !== $function || $tokens[$index + 1]->token_value !== '(');
}
function isTokenPestleImport($token, $tokens, $index)
{
Exemple #11
0
<?php

namespace Pulsestorm\Magento2\Cli\Pestle_Clear_Cache;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Pestle\\Importer\\getCacheDir');
/**
* One Line Description
*
* @command pestle_clear_cache
*/
function pestle_cli($argv)
{
    $cache_dir = getCacheDir();
    rename($cache_dir, $cache_dir . '.' . time());
    getCacheDir();
}
Exemple #12
0
<?php

namespace Pulsestorm\Pestle\Tests;

require_once 'PestleBaseTest.php';
use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createClassTemplate');
pestle_import('Pulsestorm\\Pestle\\Library\\isAboveRoot');
class LibraryTest extends PestleBaseTest
{
    public function setup()
    {
        $path = $this->getPathToModuleFileUnderTest('modules/pulsestorm/magento2/cli/library/module.php');
        require_once $path;
    }
    public function testSetup()
    {
        $this->assertEquals(-1, -1);
    }
    public function testCreateClassTemplate()
    {
        $fixture = '<' . '?php
namespace ;
class Foo
{<$body$>}' . "\n";
        $template = createClassTemplate('Foo');
        $this->assertEquals($template, $fixture);
    }
    public function testIsAboveRoot1()
    {
        $path = '/foo/baz/bar/../../../../';
Exemple #13
0
<?php

namespace Pulsestorm\Magento2\Cli\Magento2_Generate_Ui_Add_Column_Actions;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Xml_Library\\formatXmlString');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\addArgument');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\addItem');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\validateAsListing');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getOrCreateColumnsNode');
function getPackageAndModuleNameFromListingXmlFile($file)
{
    if (strpos($file, 'app/code') === false) {
        output("At the time this command was written, pestle assumed app/code as a working directory");
        output("That file isn't in app/code, so we need to bail :(");
        exit;
    }
    $parts = explode('app/code/', $file);
    $parts = explode('/', array_pop($parts));
    return [$parts[0], $parts[1]];
}
function getGridIdFromListingXmlFile($xml)
{
    $stuff = pathinfo($xml);
    return $stuff['filename'];
}
function generatePageActionsClassFromListingXmlFileAndXml($file, $xml)
{
    list($package, $moduleName) = getPackageAndModuleNameFromListingXmlFile($file);
    $gridId = getGridIdFromListingXmlFile($file);
Exemple #14
0
<?php

namespace Pulsestorm\Cli\Build_Command_List;

use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
use ReflectionFunction;
use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Pestle\\Library\\getDocCommentAsString');
pestle_import('Pulsestorm\\Pestle\\Importer\\getCacheDir');
pestle_import('Pulsestorm\\Pestle\\Runner\\getBaseProjectDir');
pestle_import('Pulsestorm\\Pestle\\Library\\parseDocBlockIntoParts');
function getListOfFilesInModuleFolder()
{
    $path = getBaseProjectDir() . '/modules/';
    $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
    return $objects;
}
function includeAllModuleFiles()
{
    $objects = getListOfFilesInModuleFolder();
    // $path = realpath('modules/');
    // $objects = new RecursiveIteratorIterator(
    //     new RecursiveDirectoryIterator($path),
    //     RecursiveIteratorIterator::SELF_FIRST
    // );
    foreach ($objects as $name => $object) {
        $info = pathinfo($name);
        if ($info['basename'] == 'module.php') {
            require_once $name;
<?php

namespace Pulsestorm\Pestle\Tests\Foo;

use Pulsestorm\Pestle\Tests\PestleBaseTest;
require_once 'PestleBaseTest.php';
use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\createClassTemplate');
pestle_import('Pulsestorm\\PhpDotNet\\glob_recursive');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Pestle\\Importer\\getNamespaceCalledFrom');
class NamespaceRefactoringTest extends PestleBaseTest
{
    public function testsOutput()
    {
        ob_start();
        output("Hello");
        $results = ob_get_clean();
        $this->assertEquals(trim($results), "Hello");
    }
    public function testsFunctionExists()
    {
        $this->assertTrue(function_exists('glob_recursive'));
    }
}
function cleverHackToTestReflectionFunction()
{
    return getNamespaceCalledFrom();
}
/**
* @command library
<?php

namespace Pulsestorm\Pestle\Tests;

require_once 'PestleBaseTest.php';
use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Magento2\\Cli\\Generate\\Mage2_Command\\createNamespaceFromCommandName');
// use function Pulsestorm\Magento2\Cli\Generate\Mage2_Command\createNamespaceFromCommandName;
class GenerateMage2CommandTest extends PestleBaseTest
{
    public function testNamespaceGenerate1()
    {
        $path = createNamespaceFromCommandName('science');
        $this->assertEquals('Pulsestorm\\Magento2\\Cli\\Science', $path);
    }
    public function testNamespaceGenerate2()
    {
        $path = createNamespaceFromCommandName('generate_science');
        $this->assertEquals('Pulsestorm\\Magento2\\Cli\\Generate\\Science', $path);
    }
    public function testNamespaceGenerate3()
    {
        $path = createNamespaceFromCommandName('foo_science');
        $this->assertEquals('Pulsestorm\\Magento2\\Cli\\Foo_Science', $path);
    }
}
Exemple #17
0
<?php

namespace Pulsestorm\Magento2\Cli\Generate\Command;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getBaseMagentoDir');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getModuleInformation');
pestle_import('Pulsestorm\\Xml_Library\\formatXmlString');
pestle_import('Pulsestorm\\Xml_Library\\simpleXmlAddNodesXpath');
pestle_import('Pulsestorm\\Magento2\\Cli\\Xml_Template\\getBlankXml');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\templateCommandClass');
function createPhpClass($module_dir, $namespace, $module_name, $command_name)
{
    $class_file_string = templateCommandClass($namespace, $module_name, $command_name);
    if (!is_dir($module_dir . '/Command')) {
        mkdir($module_dir . '/Command');
    }
    writeStringToFile($module_dir . '/Command/' . $command_name . '.php', $class_file_string);
}
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;
Exemple #18
0
<?php

namespace Pulsestorm\Magento2\Cli\Help;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Runner\\applyCommandNameAlias');
/**
* Alias for list
* @command help
*/
function pestle_cli($argv)
{
    require_once __DIR__ . '/../list_commands/module.php';
    if (isset($argv[0])) {
        $argv[0] = applyCommandNameAlias($argv[0]);
    }
    return \Pulsestorm\Magento2\Cli\List_Commands\pestle_cli($argv);
}
Exemple #19
0
function doPestleImports()
{
    pestle_import('Pulsestorm\\Pestle\\Library\\parseArgvIntoCommandAndArgumentsAndOptions');
    pestle_import('Pulsestorm\\Pestle\\Importer\\getCacheDir');
    pestle_import('Pulsestorm\\Cli\\Token_Parse\\getFunctionFromCode');
    pestle_import('Pulsestorm\\Cli\\Build_Command_List\\buildCommandList');
    pestle_import('Pulsestorm\\Pestle\\Library\\parseDocBlockIntoParts');
    pestle_import('Pulsestorm\\Pestle\\Library\\inputOrIndex');
}
Exemple #20
0
<?php

namespace Pulsestorm\Magento2\Cli\Magento2_Generate_Preference;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getModuleInformation');
pestle_import('Pulsestorm\\Xml_Library\\formatXmlString');
pestle_import('Pulsestorm\\Magento2\\Cli\\Xml_Template\\getBlankXml');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Magento2\\Cli\\Path_From_Class\\getPathFromClass');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createClassTemplate');
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];
}
function generateDiConfiguration($argv)
{
    $moduleInfo = getModuleInformation($argv['module']);
    $pathAndXml = loadOrCreateDiXml($moduleInfo);
    $path = $pathAndXml['path'];
    $di_xml = $pathAndXml['xml'];
    $preference = $di_xml->addChild('preference');
    $preference['for'] = $argv['for'];
Exemple #21
0
<?php

namespace Pulsestorm\Magento2\Cli\Search_Controllers;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\inputOrIndex');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\PhpDotNet\\glob_recursive');
pestle_import('Pulsestorm\\Cli\\Token_Parse\\getFunctionFromClass');
function getAllControllerFiles($base)
{
    $files = glob($base . '/*');
    $controllers = array_filter($files, function ($item) {
        return is_dir($item . '/Controller/');
    });
    $controllers = array_map(function ($item) {
        return glob_recursive($item . '/Controller/*.php');
    }, $files);
    return $controllers;
}
function getControllersWithExecuteMethod($controllers)
{
    $return = [];
    foreach ($controllers as $key => $items) {
        foreach ($items as $item) {
            $contents = file_get_contents($item);
            if (strpos($contents, 'execute') !== false) {
                $return[$item] = $contents;
            }
        }
    }
Exemple #22
0
<?php

namespace Pulsestorm\Magento2\Cli\Generate\Mage2_Command;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\inputOrIndex');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createPathFromNamespace');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createNamespaceFromNamespaceAndCommandName');
/**
* Generates pestle command boiler plate
* This command creates the necessary files 
* for a pestle command
*
*     pestle.phar generate_pestle_command command_name
*
* @command generate_pestle_command
* @argument command_name New Command Name? [foo_bar]
* @argument namespace_module Create in PHP Namespace? [Pulsestorm\Magento2\Cli]
*/
function pestle_cli($argv)
{
    $command_name = $argv['command_name'];
    $namespace = createNamespaceFromNamespaceAndCommandName($argv['namespace_module'], $command_name);
    $command = '<' . '?php' . "\n" . 'namespace ' . $namespace . ';' . "\n" . 'use function Pulsestorm\\Pestle\\Importer\\pestle_import;' . "\n" . 'pestle_import(\'Pulsestorm\\Pestle\\Library\\output\');' . "\n\n" . '/**' . "\n" . '* One Line Description' . "\n" . '*' . "\n" . '* @command ' . $command_name . '' . "\n" . '*/' . "\n" . 'function pestle_cli($argv)' . "\n" . '{' . "\n" . '    output("Hello Sailor");' . "\n" . '}' . "\n";
    output("Creating the following module");
    output($command);
    $path_full = createPathFromNamespace($namespace);
    if (file_exists($path_full)) {
        output("{$path_full} already exists, bailing");
Exemple #23
0
<?php

namespace Pulsestorm\Magento2\Cli\Generate\Crud\Model;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getModuleInformation');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createClassTemplate');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\templateInterface');
pestle_import('Pulsestorm\\Magento2\\Cli\\Path_From_Class\\getPathFromClass');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\generateInstallSchemaTable');
define('BASE_COLLECTION_CLASS', '\\Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection');
define('BASE_RESOURCE_CLASS', '\\Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb');
define('BASE_MODEL_CLASS', '\\Magento\\Framework\\Model\\AbstractModel');
function getCollectionClassNameFromModuleInfo($module_info, $model_name)
{
    return $module_info->vendor . '\\' . $module_info->short_name . '\\Model\\ResourceModel\\' . $model_name . '\\Collection';
}
function getResourceModelClassNameFromModuleInfo($module_info, $model_name)
{
    return $module_info->vendor . '\\' . $module_info->short_name . '\\Model\\ResourceModel\\' . $model_name;
}
function getModelClassNameFromModuleInfo($module_info, $model_name)
{
    return $module_info->vendor . '\\' . $module_info->short_name . '\\Model\\' . $model_name;
}
function templateInstallDataFunction()
{
    return "\n" . '    public function install(\\Magento\\Framework\\Setup\\ModuleDataSetupInterface $setup, \\Magento\\Framework\\Setup\\ModuleContextInterface $context)
    {
Exemple #24
0
<?php

namespace Pulsestorm\Magento2\Cli\Convert_Selenium_Id_For_Codecept;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\indexOrInput');
function getCommandAndTwoArgs($string)
{
    $parts = preg_split('%[\\r\\n]%', $string);
    foreach ($parts as $part) {
        if (!$part) {
            continue;
        }
        preg_match('%<td>(.*)</td>%six', $part, $matches);
        if (!$matches) {
            continue;
        }
        if (count($matches) < 1) {
            var_dump($part);
            exit(__FUNCTION__);
        }
        $stuff[] = str_replace('&gt;', '>', $matches[1]);
        // $part = ltrim($part, '<td>');
        // $part = rtrim($part, '</td>');
        // $part = rtrim('</td>', $part);
        // output($part);
    }
    return ['command' => $stuff[0], 'arg1' => $stuff[1], 'arg2' => $stuff[2]];
}
function parseIntoCommands($contents)
Exemple #25
0
<?php

namespace Pulsestorm\Magento2\Cli\Extract_Session;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
class Session
{
    public static function unserialize($session_data)
    {
        $method = ini_get("session.serialize_handler");
        switch ($method) {
            case "php":
                return self::unserialize_php($session_data);
                break;
            case "php_binary":
                return self::unserialize_phpbinary($session_data);
                break;
            default:
                throw new Exception("Unsupported session.serialize_handler: " . $method . ". Supported: php, php_binary");
        }
    }
    private static function unserialize_php($session_data)
    {
        $return_data = array();
        $offset = 0;
        while ($offset < strlen($session_data)) {
            if (!strstr(substr($session_data, $offset), "|")) {
                throw new Exception("invalid data, remaining: " . substr($session_data, $offset));
            }
Exemple #26
0
<?php

namespace Pulsestorm\Magento2\Cli\Testbed;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getBaseMagentoDir');
pestle_import('Pulsestorm\\Xml_Library\\formatXmlString');
pestle_import('Pulsestorm\\Cli\\Token_Parse\\pestle_token_get_all');
function getFrontendModelNodesFromMagento1SystemXml($xmls)
{
    $items = [];
    foreach ($xmls as $xml_file) {
        $xml = simplexml_load_file($xml_file);
        $items[$xml_file] = [];
        foreach ($xml->sections->children() as $section) {
            $strSection = $section->getName();
            foreach ($section->groups->children() as $group) {
                $strGroup = $group->getName();
                foreach ($group->fields->children() as $field) {
                    if ($field->frontend_model) {
                        $strField = $field->getName();
                        $items[$xml_file][] = implode('/', [$strSection, $strGroup, $strField]) . '::' . (string) $field->frontend_model;
                    }
                }
            }
        }
    }
    return $items;
}
Exemple #27
0
<?php

namespace Pulsestorm\Magento2\Cli\Generate\Observer;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createClassTemplate');
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\initilizeModuleConfig');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
/**
* Generates Magento 2 Observer
* This command generates the necessary files and configuration to add 
* an event observer to a Magento 2 system.
*
*    pestle.phar generate_observer Pulsestorm_Generate controller_action_predispatch pulsestorm_generate_listener3 'Pulsestorm\Generate\Model\Observer3'
*
* @command generate_observer
* @argument module Full Module Name? [Pulsestorm_Generate]
* @argument event_name Event Name? [controller_action_predispatch]
* @argument observer_name Observer Name? [<$module$>_listener]
* @argument model_name Class Name? [<$module$>\Model\Observer]
*/
function pestle_cli($argv)
{
    $module = $argv['module'];
    $event_name = $argv['event_name'];
    $observer_name = $argv['observer_name'];
    $model_name = $argv['model_name'];
    $method_name = 'execute';
    $path_xml_event = initilizeModuleConfig($module, 'events.xml', 'urn:magento:framework:Event/etc/events.xsd');
Exemple #28
0
<?php

namespace Pulsestorm\Magento2\Cli\Generate\Module;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\inputOrIndex');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getBaseMagentoDir');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\addSchemaToXmlString');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\templateRegistrationPhp');
pestle_import('Pulsestorm\\Magento2\\Cli\\Xml_Template\\getBlankXml');
/**
* 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'));
Exemple #29
0
<?php

namespace Pulsestorm\Magento2\Cli\Generate\Plugin_Xml;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Pestle\\Library\\input');
pestle_import('Pulsestorm\\Pestle\\Library\\output');
pestle_import('Pulsestorm\\Magento2\\Cli\\Format_Xml_String\\format_xml');
pestle_import('Pulsestorm\\Pestle\\Library\\inputOrIndex');
pestle_import('Pulsestorm\\Magento2\\Cli\\Xml_Template\\getBlankXml');
pestle_import('Pulsestorm\\Magento2\\Cli\\Library\\getModuleInformation');
pestle_import('Pulsestorm\\Xml_Library\\formatXmlString');
pestle_import('Pulsestorm\\Pestle\\Library\\writeStringToFile');
pestle_import('Pulsestorm\\Cli\\Code_Generation\\createClassTemplate');
pestle_import('Pulsestorm\\Magento2\\Cli\\Path_From_Class\\getPathFromClass');
pestle_import('Pulsestorm\\Xml_Library\\simpleXmlAddNodesXpath');
function getDiXmlTemplate($config_attributes = 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"')
{
    if (!$config_attributes) {
        $config_attributes = 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"';
    }
    return trim('
<?xml version="1.0"?>
<config ' . $config_attributes . '>

</config>
');
}
function underscoreClass($class)
{
    return strToLower(str_replace('\\', '_', $class));
Exemple #30
0
<?php

namespace Pulsestorm\Magento2\Cli\Help;

use function Pulsestorm\Pestle\Importer\pestle_import;
pestle_import('Pulsestorm\\Magento2\\Cli\\List_Commands\\pestle_cli');
/**
* Alias for list
* @command help
*/
function pestle_cli($argv)
{
    require_once __DIR__ . '/../list_commands/module.php';
    return \Pulsestorm\Magento2\Cli\List_Commands\pestle_cli($argv);
}