/** * getFullClassName() * * @param string $localClassName * @param string $classContextName */ public function getFullClassName($localClassName, $classContextName = null) { // find the ApplicationDirectory OR ModuleDirectory $currentResource = $this->_resource; do { $resourceName = $currentResource->getName(); if ($resourceName == 'ApplicationDirectory' || $resourceName == 'ModuleDirectory') { $containingResource = $currentResource; break; } } while ($currentResource instanceof Zend_Tool_Project_Profile_Resource && ($currentResource = $currentResource->getParentResource())); $fullClassName = ''; // go find the proper prefix if (isset($containingResource)) { if ($containingResource->getName() == 'ApplicationDirectory') { $prefix = $containingResource->getAttribute('classNamePrefix'); $fullClassName = $prefix; } elseif ($containingResource->getName() == 'ModuleDirectory') { $filter = new Zend_Filter_Word_DashToCamelCase(); $prefix = $filter->filter(ucfirst($containingResource->getAttribute('moduleName'))) . '_'; $fullClassName = $prefix; } } if ($classContextName) { $fullClassName .= rtrim($classContextName, '_') . '_'; } $fullClassName .= $localClassName; return $fullClassName; }
/** * getContents() * * @return string */ public function getContents() { $filter = new Zend_Filter_Word_DashToCamelCase(); $className = $filter->filter($this->_forControllerName) . 'ControllerTest'; $codeGenFile = new Zend_CodeGenerator_Php_File(array('requiredFiles' => array('PHPUnit/Framework/TestCase.php'), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'PHPUnit_Framework_TestCase', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'setUp', 'body' => ' /* Setup Routine */')), new Zend_CodeGenerator_Php_Method(array('name' => 'tearDown', 'body' => ' /* Tear Down Routine */')))))))); return $codeGenFile->generate(); }
public function getContents() { $filter = new Zend_Filter_Word_DashToCamelCase(); $className = $filter->filter($this->_controllerName) . 'Controller'; $codeGenFile = new ZendL_Tool_CodeGenerator_Php_File(array('classes' => array(new ZendL_Tool_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Controller_Action', 'methods' => array(new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'init', 'body' => ' /* Initialize action controller here */')), new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'indexAction', 'body' => ' /* Default action for action controller */')))))))); if ($className == 'ErrorController') { $codeGenFile = new ZendL_Tool_CodeGenerator_Php_File(array('classes' => array(new ZendL_Tool_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Controller_Action', 'methods' => array(new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'init', 'body' => <<<EOS \$errors = \$this->_getParam('error_handler'); switch (\$errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found \$this->getResponse()->setHttpResponseCode(404); \$this->view->message = 'Page not found'; break; default: // application error \$this->getResponse()->setHttpResponseCode(500); \$this->view->message = 'Application error'; break; } \$this->view->env = \$this->getInvokeArg('env'); \$this->view->exception = \$errors->exception; \$this->view->request = \$errors->request; EOS )))))))); } return $codeGenFile->generate(); }
public function testFilterSeparatesCamelCasedWordsWithDashes() { $string = 'camel-cased-words'; $filter = new Zend_Filter_Word_DashToCamelCase(); $filtered = $filter->filter($string); $this->assertNotEquals($string, $filtered); $this->assertEquals('CamelCasedWords', $filtered); }
public function getContents() { $filter = new Zend_Filter_Word_DashToCamelCase(); $className = $filter->filter($this->_controllerName) . 'Controller'; $codeGenFile = new ZendL_Tool_CodeGenerator_Php_File(array('classes' => array(new ZendL_Tool_CodeGenerator_Php_Class(array('name' => $className, 'methods' => array(new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'init', 'body' => ' /* Initialize action controller here */')), new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'indexAction', 'body' => ' /* Default action for action controller */')))))))); if ($className == 'ErrorController') { $classes = $codeGenFile->getClasses(); $classes['ErrorController']->setMethod(new ZendL_Tool_CodeGenerator_Php_Method(array('name' => 'errorAction', 'body' => ' // some errorAction stuff here'))); } return $codeGenFile->generate(); }
public function call($controller, $action, array $arguments = array()) { $d2cc = new Zend_Filter_Word_DashToCamelCase(); $controllerName = 'Application_Controller_' . $d2cc->filter($controller); $actionName = $action . 'Action'; /* @var $controllerInstance Application_Controller_Abstract */ $controllerInstance = new $controllerName(); $controllerInstance->setApplication($this); $controllerInstance->setArguments($arguments); return $controllerInstance->{$actionName}(); }
function __construct($field, $value, $options = array()) { $this->_field = $field; $this->_value = $value; $this->_options = $options; $filter = new Zend_Filter_Word_DashToCamelCase(); foreach ($options as $option => $val) { $method = 'set' . $filter->filter($option); if (method_exists($this, $method)) { $this->{$method}($val); } } }
/** * Get Entity name based on $entity and $module * * @param null|string $entity * @param null|string $module * @return string */ public function getEntityName($entity = null, $module = null) { $dashToCamelCaseFilter = new Zend_Filter_Word_DashToCamelCase(); if (null === $entity) { $entity = ucfirst($dashToCamelCaseFilter->filter($this->getRequest()->getControllerName())); $module = $this->getRequest()->getModuleName(); } if (is_string($module)) { $module = ucfirst($dashToCamelCaseFilter->filter($module)); $entity = $module . '_Model_Entity_' . $entity; } return $entity; }
private function getOperation($element) { $name = $element->getType(); if (isset($this->known[$name])) { return $this->known[$name]; } $filter = new Zend_Filter_Word_DashToCamelCase(); $ucname = $filter->filter(ucfirst($name)); foreach ($this->sources as $prefix => $null) { $class = $prefix . $ucname; if (class_exists($class)) { return $this->known[$name] = new $class(); } } throw new Math_Formula_Runner_Exception(tr('Unknown operation "%0".', $element->getType())); }
/** * convertFromClientNaming() * * Convert words from client specific naming to code naming - camelcased * * Filters are lazy-loaded. * * @param string $string * @return string */ public function convertFromClientNaming($string) { if (!$this->_filterFromClientNaming) { $this->_filterFromClientNaming = new Zend_Filter_Word_DashToCamelCase(); } return $this->_filterFromClientNaming->filter($string); }
/** * convertFromClientNaming() * * Convert words from client specific naming to code naming - camelcased * * Filters are lazy-loaded. * * @param string $string * @return string */ public function convertFromClientNaming($string) { if (!$this->_filterFromClientNaming) { #require_once 'Zend/Filter/Word/DashToCamelCase.php'; $this->_filterFromClientNaming = new Zend_Filter_Word_DashToCamelCase(); } return $this->_filterFromClientNaming->filter($string); }
/** * Constructor. * * @param array $config Context configuratio * @return void */ public function __construct($path, array $config = array()) { $suffix = isset($config['suffix']) ? $config['suffix'] : 'Service'; $namespace = isset($config['namespace']) ? $config['namespace'] : 'Service'; $folderNameService = isset($config['folderNameService']) ? $config['folderNameService'] : 'services'; $separator = isset($config['separatorClass']) ? $config['separatorClass'] : '\\'; $path = realpath($path); $files = glob("{$path}/*/{$folderNameService}/*.php", GLOB_NOSORT); if (empty($files)) { return; } foreach ($files as $file) { if ('.' === $file || '..' === $file) { continue; } $moduleName = substr($file, strlen($path) + 1); $moduleName = substr($moduleName, 0, strpos($moduleName, '/')); $filter = new Zend_Filter_Word_DashToCamelCase(); $fileName = str_replace(array($suffix, '.php'), '', basename($file)); $serviceClass = $filter->filter($moduleName) . $separator . $namespace . $separator . $fileName; unset($config['class']); $this->bind($fileName, $serviceClass, $config); } }
/** * getContents() * * @return string */ public function getContents() { $filter = new Zend_Filter_Word_DashToCamelCase(); $className = $this->_moduleName ? $filter->filter(ucfirst($this->_moduleName)) . '_' : ''; $className .= ucfirst($this->_controllerName) . 'Controller'; $codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Controller_Action', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'init', 'body' => '/* Initialize action controller here */')))))))); if ($className == 'ErrorController') { $codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Controller_Action', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'errorAction', 'body' => <<<EOS \$errors = \$this->_getParam('error_handler'); if (!\$errors || !\$errors instanceof ArrayObject) { \$this->view->message = 'You have reached the error page'; return; } switch (\$errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found \$this->getResponse()->setHttpResponseCode(404); \$priority = Zend_Log::NOTICE; \$this->view->message = 'Page not found'; break; default: // application error \$this->getResponse()->setHttpResponseCode(500); \$priority = Zend_Log::CRIT; \$this->view->message = 'Application error'; break; } // Log exception, if logger available if (\$log = \$this->getLog()) { \$log->log(\$this->view->message, \$priority, \$errors->exception); \$log->log('Request Parameters', \$priority, \$errors->request->getParams()); } // conditionally display exceptions if (\$this->getInvokeArg('displayExceptions') == true) { \$this->view->exception = \$errors->exception; } \$this->view->request = \$errors->request; EOS )), new Zend_CodeGenerator_Php_Method(array('name' => 'getLog', 'body' => <<<EOS \$bootstrap = \$this->getInvokeArg('bootstrap'); if (!\$bootstrap->hasResource('Log')) { return false; } \$log = \$bootstrap->getResource('Log'); return \$log; EOS )))))))); } // store the generator into the registry so that the addAction command can use the same object later Zend_CodeGenerator_Php_File::registerFileCodeGenerator($codeGenFile); // REQUIRES filename to be set return $codeGenFile->generate(); }
/** * getContents() * * @return string */ public function getContents() { $filter = new Zend_Filter_Word_DashToCamelCase(); $className = $filter->filter($this->_projectProviderName) . 'Provider'; $class = new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Tool_Project_Provider_Abstract')); $methods = array(); foreach ($this->_actionNames as $actionName) { $methods[] = new Zend_CodeGenerator_Php_Method(array('name' => $actionName, 'body' => ' /** @todo Implementation */')); } if ($methods) { $class->setMethods($methods); } $codeGenFile = new Zend_CodeGenerator_Php_File(array('requiredFiles' => array('Zend/Tool/Project/Provider/Abstract.php', 'Zend/Tool/Project/Provider/Exception.php'), 'classes' => array($class))); return $codeGenFile->generate(); }
/** * This method will take a Parameter Name and format it for Tool usage, * The Tool will EXPECT this Parameter Name in camelCase * * The Cli Endpoint will PROVIDE the parameter name in 'dashed-lower-format' * * @param string $parameterName */ public function parameterNameForTool($parameterName) { $value = $this->_dashedLowerToCamelCase->filter($parameterName); return strtolower($value[0]) . substr($value, 1); }
/** * Get the form className based on the current Request * * @return string */ public function getFormClassNameByRequest() { $filter = new Zend_Filter_Word_DashToCamelCase(); $request = $this->getRequest(); $formName = ucfirst($filter->filter($request->getModuleName())) . '_Form_' . ucfirst($filter->filter($request->getControllerName())) . ucfirst($filter->filter($request->getActionName())); return $formName; }
private function getPrefixFactory($prefix) { return function ($functionName) use($prefix) { $filter = new Zend_Filter_Word_DashToCamelCase(); $ucname = $filter->filter(ucfirst($functionName)); $class = $prefix . $ucname; if (class_exists($class)) { return new $class(); } }; }
/** * getContents() * * @return string */ public function getContents() { $filter = new Zend_Filter_Word_DashToCamelCase(); $className = $filter->filter($this->_controllerName) . 'Controller'; $codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Controller_Action', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'init', 'body' => '/* Initialize action controller here */')))))))); if ($className == 'ErrorController') { $codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Controller_Action', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'errorAction', 'body' => <<<EOS \$errors = \$this->_getParam('error_handler'); switch (\$errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found \$this->getResponse()->setHttpResponseCode(404); \$this->view->message = 'Page not found'; break; default: // application error \$this->getResponse()->setHttpResponseCode(500); \$this->view->message = 'Application error'; break; } \$this->view->exception = \$errors->exception; \$this->view->request = \$errors->request; EOS )))))))); } // store the generator into the registry so that the addAction command can use the same object later Zend_CodeGenerator_Php_File::registerFileCodeGenerator($codeGenFile); // REQUIRES filename to be set return $codeGenFile->generate(); }
/** * getContents() * * @return string */ public function getContents() { $filter = new Zend_Filter_Word_DashToCamelCase(); $className = $filter->filter($this->_forControllerName) . 'ControllerTest'; /* @var $controllerDirectoryResource Zend_Tool_Project_Profile_Resource */ $controllerDirectoryResource = $this->_resource->getParentResource(); if ($controllerDirectoryResource->getParentResource()->getName() == 'TestApplicationModuleDirectory') { $className = $filter->filter(ucfirst($controllerDirectoryResource->getParentResource()->getForModuleName())) . '_' . $className; } $codeGenFile = new Zend_CodeGenerator_Php_File(array('classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Test_PHPUnit_ControllerTestCase', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'setUp', 'body' => <<<EOS \$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); parent::setUp(); EOS )))))))); return $codeGenFile->generate(); }
/** * Gets the content of the controller spec file * * @param string $name * @param string $actions * @return string */ protected function _getSpecContent($name, $actions) { $dashToCamelCase = new DashToCamelCase(); $camelCaseTDash = new CamelCaseToDash(); $examples = array(); foreach ($actions as $action) { $examples[] = 'function itShouldBeSuccessfulToGet' . UCFirst::apply($dashToCamelCase->filter($action)) . '() { $this->get(\'' . strtolower($camelCaseTDash->filter($name)) . '/' . $action . '\'); $this->response->should->beSuccess(); }'; } $examples = implode(PHP_EOL . PHP_EOL . ' ', $examples); return <<<CONTENT <?php require_once __DIR__ . '/../SpecHelper.php'; class Describe{$name}Controller extends \\PHPSpec\\Context\\Zend\\Controller { {$examples} } CONTENT; }
private function getPrefixFactory($prefix) { return function ($functionName) use($prefix) { $filter = new Zend_Filter_Word_DashToCamelCase(); // Workaround Deprecated errors showing from Zend lib if (error_reporting() & E_DEPRECATED) { $old_error_reporting = error_reporting(); error_reporting($old_error_reporting - E_DEPRECATED); } $ucname = $filter->filter(ucfirst($functionName)); if (isset($old_error_reporting)) { error_reporting($old_error_reporting); } $class = $prefix . $ucname; if (class_exists($class)) { return new $class(); } }; }
/** * Renders the content of the scaffolded controller spec * * @param string $entity * @param array $fields * @param string $module * @return string */ protected static function content($entity, $fields, $module) { $pluralize = new Pluralize(); $dashIt = new CamelCaseToSeparator(); $camelize = new DashToCamelCase(); $lcFirst = new LCFirst(); $ucFirst = new UCFirst(); if ($module === null) { $module = $camelize->filter($module); $namespace = 'namespace ' . $ucFirst->filter($module) . ';' . PHP_EOL; } else { $namespace = ''; } $entityPlural = $pluralize->filter($entity); $lcFirstEntity = $lcFirst->filter($entity); $lcFirstEntityPlural = $lcFirst->filter($entityPlural); $entityPluralDashed = $dashIt->filter($entityPlural); $smallCasedDashedPlural = strtolower($entityPluralDashed); $fieldsAndValues = $rendered = ''; $fields = explode(',', $fields); foreach ($fields as $field) { $fieldAndType = explode(':', $field); list($field, $type) = count($fieldAndType) === 2 ? $fieldAndType : array($field, 'string'); $fieldType = $type === 'text' ? 'textarea' : 'input'; $fieldsAndValues .= "'{$field}' => 'some {$field}'," . PHP_EOL . " "; } $appForm = "Application_Form_{$entity}Form"; return <<<CONTROLLER <?php {$namespace} class Describe{$entityPlural}Controller extends \\PHPSpec\\Context\\Zend\\Controller { // GET index function itAssignsAll{$entityPlural}ToList() { \$mapper = \$this->stub('Application_Model_{$entity}Mapper'); \$mapper->shouldReceive('fetchAll')->andReturn(array()); \$this->inject('Application.Model.{$entity}Mapper', \$mapper); \$this->get('{$smallCasedDashedPlural}/index'); \$this->assigns('{$lcFirstEntityPlural}')->should->be(array()); } // GET show function itAssignsTheRequested{$entity}ToBeShown() { \${$lcFirstEntity} = \$this->stub('Application_Model_{$entity}'); \$mapper = \$this->stub('Application_Model_{$entity}Mapper'); \$mapper->shouldReceive('find')->andReturn(\${$lcFirstEntity}); \$this->inject('Application.Model.{$entity}Mapper', \$mapper); \$this->get('{$smallCasedDashedPlural}/show'); \$this->assigns('{$lcFirstEntity}')->should->be(\${$lcFirstEntity}); } // GET edit function itPopulatesTheEditFormWithA{$entity}() { \${$lcFirstEntity}Array = array( 'id' => 1, {$fieldsAndValues} ); \${$lcFirstEntity} = \$this->stub('Application_Model_{$entity}'); \${$lcFirstEntity}->shouldReceive('toArray') ->andReturn(\${$lcFirstEntity}Array); \$mapper = \$this->stub('Application_Model_{$entity}Mapper'); \$mapper->shouldReceive('find')->andReturn(\${$lcFirstEntity}); \$this->inject('Application.Model.{$entity}Mapper', \$mapper); \$form = \$this->stub('Application_Form_{$entity}Form'); \$form->shouldReceive('populate')->with(\${$lcFirstEntity}Array); \$this->inject('Application.Form.{$entity}Form', \$form); \$this->get('{$smallCasedDashedPlural}/edit/id/1'); \$this->assigns('id')->should->be('1'); \$this->assigns('form')->should->be(\$form); } // GET new function itDisplaysThe{$entity}Form() { \$this->get('{$smallCasedDashedPlural}/new'); \$this->assigns('form')->should->beAnInstanceOf('{$appForm}'); } // POST add function itAddsTheValid{$entity}() { \$mapper = \$this->stub('Application_Model_{$entity}Mapper'); \$mapper->shouldReceive('save')->once(); \$this->inject('Application.Model.{$entity}Mapper', \$mapper); \$form = \$this->stub('Application_Form_{$entity}Form'); \$form->shouldReceive('isValid')->andReturn(true); \$this->inject('Application.Form.{$entity}Form', \$form); \$this->post('{$smallCasedDashedPlural}/add', array( {$fieldsAndValues} )); } // POST update function itUpdatesTheValid{$entity}() { \$mapper = \$this->stub('Application_Model_{$entity}Mapper'); \$mapper->shouldReceive('save'); \$this->inject('Application.Model.{$entity}Mapper', \$mapper); \$form = \$this->stub('Application_Form_{$entity}Form'); \$form->shouldReceive('isValid')->andReturn(true); \$this->inject('Application.Form.{$entity}Form', \$form); \$this->post('{$smallCasedDashedPlural}/update/id/1', array( {$fieldsAndValues} )); } // GET delete function itDeletesThe{$entity}() { \$mapper = \$this->stub('Application_Model_{$entity}Mapper'); \$mapper->shouldReceive('delete'); \$this->inject('Application.Model.{$entity}Mapper', \$mapper); \$this->get('{$smallCasedDashedPlural}/delete/id/1'); \$this->response->should->redirectTo('/{$lcFirstEntityPlural}'); } // this is because we are using the registry as container // not needed with a proper non-static IoC container function after() { \$this->clearContainer(); } } CONTROLLER; }
/** * Creates the content for the spec file * * @param string $name * @param string $controllerName * @return string */ protected function _getSpecContent($name, $controllerName) { $dashToCamelCase = new DashToCamelCase(); $camelCaseToDash = new CamelCaseToDash(); return ' function itShouldBeSuccessfulToGet' . UCFirst::apply($dashToCamelCase->filter($name)) . '() { $this->get(\'' . strtolower($camelCaseToDash->filter($controllerName)) . '/' . $name . '\'); $this->response->should->beSuccess(); } }'; }
/** * Creates the content of the view spec file * * @param string $name * @param string $controllerName * @param string $module * @return string */ protected function _getSpecContent($name, $controllerName, $module) { $namespace = $controllerName; $helperDir = "/../../"; if ($module !== null) { $namespace = UCFirst::apply($module) . "\\{$controllerName}"; $helperDir = "/../../../"; } $specNameFilter = new DashToCamelCase(); $inflectedView = $specNameFilter->filter($name); return <<<CONTENT <?php namespace {$namespace}; require_once __DIR__ . '{$helperDir}SpecHelper.php'; use \\PHPSpec\\Context\\Zend\\View as ViewContext; class Describe{$inflectedView} extends ViewContext { function itRendersTheDefaultContent() { \$this->render(); \$this->rendered->should->contain('{$controllerName}'); \$this->rendered->should->contain('{$name}'); } } CONTENT; }