/** * Find module by entity namespace * * @param string $root - path to the working directory * @param Mtool_Codegen_Entity_Abstract $entity * @param string $namespace - namespace name * @param array $templateConfig * @return Mtool_Codegen_Entity_Module | null */ public static function byNamespace($root, $entity, $namespace, array $templateConfig) { $configNamespace = $entity->getConfigNamespace(); $mage = new Mtool_Magento($root); // Find all local config.xml files $configs = $mage->findInCode('config.xml', $mage->getCodepoolPath()); try { // Find entity definition through local modules $classPrefix = $entity->lookupOriginEntityClass($namespace, $configs); // Extract module and company names from class prefix list($companyName, $moduleName) = explode('_', $classPrefix); return new Mtool_Codegen_Entity_Module($root, $moduleName, $companyName, $templateConfig); } catch (Mtool_Codegen_Exception_Entity $e) { return null; } catch (Exception $e) { throw $e; } }
/** * Rewrite entity * * @param Mtool_Codegen_Entity_Abstract $entity * @param string $name */ protected function _rewriteEntity($entity, $name, $targetModule = null, $originEntityPath = null, $entityName = null) { if ($targetModule == null) { $targetModule = $this->_ask('Enter the target module (in format of Mycompany/Mymodule)'); } if ($originEntityPath == null) { $originEntityPath = $this->_ask("Enter the magento {$name} path (for example catalog/product_type_simple)"); } if ($entityName == null) { $entityName = $this->_ask("Enter your {$name} path (without namespace, in format of {$name}_path)"); } list($companyName, $moduleName) = explode('/', $targetModule); $module = new Mtool_Codegen_Entity_Module(getcwd(), $moduleName, $companyName, $this->_getConfig()); list($originNamespace, $originEntityName) = explode('/', $originEntityPath); $entity->rewrite($originNamespace, $originEntityName, $entityName, $module); $this->_answer('Done'); }