/** * @param array $composerJsonData * * @return string */ protected function getBundleName(array $composerJsonData) { $nameParts = explode('/', $composerJsonData[self::KEY_NAME]); $bundleName = array_pop($nameParts); $filter = new DashToCamelCase(); return $filter->filter($bundleName); }
/** * 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); }
/** * * @param string $controller * @param string $action * @param array $params * @return array */ public function makeArguments($controller, $action, array $params) { $filter = new DashToCamelCase(); $action = lcfirst($filter->filter($action)); $result = array(); if (isset($this->config['injections'][$controller][$action])) { $injections = $this->config['injections'][$controller][$action]; reset($injections); foreach ($params as $variable => $value) { $name = key($injections); $injection = current($injections); if (is_array($injection)) { list($entity, $manager, $isRequired) = $injection; if (is_scalar($value)) { $entity = call_user_func_array([$this->objectManagers[$manager]->getRepository($entity), 'find'], [$value]); if (!$entity && $isRequired) { throw new EntityNotFoundException(); } $result[$name] = $entity; } } else { $result[$variable] = $value; } next($injections); } } return $result; }
/** * @param mixed $value * * @return string */ public function filter($value) { $dashToCamelCaseFilter = new DashToCamelCase(); $underscoreToCamelCaseFilter = new UnderscoreToCamelCase(); $value = $dashToCamelCaseFilter->filter($value); $value = $underscoreToCamelCaseFilter->filter($value); return $value; }
/** * @param mixed $value * * @return array|mixed */ public function filter($value) { $list = parent::filter($value); $dashToCamelCaseFilter = new DashToCamelCase(); $underscoreToCamelCaseFilter = new UnderscoreToCamelCase(); foreach ($list as $listKey => $listOption) { $listOption = $dashToCamelCaseFilter->filter($listOption); $listOption = $underscoreToCamelCaseFilter->filter($listOption); $list[$listKey] = $listOption; } return $list; }
/** * * @param MvcEvent $event */ public function onDispatch(MvcEvent $event) { $filter = new DashToCamelCase(); $assertionManager = $this->serviceLocator->get('AssertionManager'); $routeMatch = $event->getRouteMatch(); $controller = $routeMatch->getParam('controller'); $action = lcfirst($filter->filter($routeMatch->getParam('action'))); $assertsConfig = $assertionManager->findConfig($controller, $action); foreach ($assertsConfig as $config) { $assert = $assertionManager->get($config['assert']); if (!$assert->test($event, $config['options'])) { return call_user_func_array([$assert, 'onFail'], [$event]); } } }
/** * @param InputInterface $input * @param OutputInterface $output * * @return null */ protected function execute(InputInterface $input, OutputInterface $output) { $transformer = new DashToCamelCase(); $filter = new Alpha(); $name = $input->getArgument('name'); $className = $filter->filter($transformer->filter(ucfirst($name))); $description = $input->getArgument('description'); $filesystem = new Filesystem(new Adapter(dirname(dirname(dirname(dirname(dirname(__DIR__))))))); $template = $filesystem->read('vendor/middleout/mdo-bundle-zf2-cli/templates/Command/TemplateCommand.php'); $template = str_replace(['TemplateCommandName', 'TemplateCommandDescription', 'TemplateCommandLiteralName'], [$className . 'Command', $description, $name], $template); $filesystem->write('module/Cli/src/Command/' . $className . 'Command.php', $template); $output->writeln(''); $output->writeln('Created command succesfully in path "module/Cli/src/Command/' . $className . 'Command.php"'); $output->writeln(''); }
/** * @param string $service * @return AbstractService * @throws Exception */ public function getService($service, $optionsKey, array $options) { $service = trim($service); if (!isset($this->_options[$optionsKey])) { throw new Exception("Service '{$optionsKey}' options not found"); } $filter = new DashToCamelCase(); $className = 'Autowp\\ExternalLoginService\\' . ucfirst($filter->filter($service)); $serviceOptions = array_replace($this->_options[$optionsKey], $options); $serviceObj = new $className($serviceOptions); if (!$serviceObj instanceof AbstractService) { throw new Exception("'{$className}' is not AbstractService"); } return $serviceObj; }
/** * (non-PHPdoc) * * @see \Zend\Validator\ValidatorInterface::isValid() */ public function isValid($value, $context = []) { // Controller prüfen if (false === isset($context['controller'])) { $this->error(self::INVALID_CONTROLLER); return false; } $controller = $context['controller']; if (false == $this->controllerExists($controller)) { $this->error(self::INVALID_CONTROLLER); return false; } // Action prüfen $controller = $this->getServiceLocator()->get('controllermanager')->get($controller); $filter = new DashToCamelCase(); $action = $filter->filter($value) . 'Action'; if (false === method_exists($controller, $action)) { $this->error(self::INVALID_ACTION); return false; } return true; }
/** * @param string $dashedWord * * @return array|string */ private function dashToCamelCase($dashedWord) { $filter = new DashToCamelCase(); return $filter->filter($dashedWord); }
/** * Set grid columns by mapping entity attributes to grid columns * * @param bool $dataOnly * * @return $this|mixed */ public function setGridColumns($dataOnly = false) { $adjustment = 0; if (!$this->_columnsSet) { $filter = new DashToCamelCase(); $utils = new ArrayUtils(); $mapping = $this->getEntityManager()->getClassMetadata($this->getEntity()); $reflectionClass = new \ReflectionClass($this->getEntity()); $configDefaults = $this->_config['default_values']; if (is_string($configDefaults)) { $configDefaults = $this->getServiceLocator()->get($configDefaults); } /** @var $service \SynergyDataGrid\Service\GridService' */ $service = $this->getServiceLocator()->get('synergy\\service\\grid'); $entityKey = $service->getEntityKeyFromClassname($this->getEntity()); $entityAttr = lcfirst($filter->filter($entityKey)); $specificValues = $entityAttr && isset($configDefaults['specific'][$entityAttr]) ? $configDefaults['specific'][$entityAttr] : array(); $defaultValues = array_merge($reflectionClass->getDefaultProperties(), (array) $configDefaults['global'], $specificValues); $excludedColumns = array_merge(array_values($this->_config['tree_grid_options']['treeReader']), $this->_config['excluded_columns']); $excludedColumns = array_unique($excludedColumns); $count = 10; foreach ($mapping->fieldMappings as $map) { $adjustment = 0; $fieldName = $map['fieldName']; $default = isset($defaultValues[$fieldName]) ? $defaultValues[$fieldName] : null; if (in_array($fieldName, $excludedColumns)) { continue; } $data = array('name' => $fieldName, 'edittype' => self::TYPE_TEXT, 'editable' => true, 'hidden' => false, 'editoptions' => array('data-field-type' => $map['type'], 'defaultValue' => $default, 'NullIfEmpty' => isset($map['nullable']) && $map["nullable"]), 'editrules' => array('edithidden' => false)); switch ($map['type']) { case 'smallint': case 'integer': $data['editrules']['number'] = true; break; case 'string': if (isset($map['length'])) { $data['editoptions']['maxlength'] = $map['length']; $data['editoptions']['size'] = $map['length']; break; } $data['searchoptions']['sopt'] = $this->getSearchOptions('cn'); break; } if ($map['columnName'] == 'id') { $data['editable'] = false; $data['key'] = true; $data['formoptions']['rowpos'] = 1; $data['formoptions']['colpos'] = 1; $data['searchoptions']['sopt'] = $this->getSearchOptions('bw'); $adjustment = 10; if ($this->isTreeGrid) { $this->_config['column_model'][$fieldName]['width'] = $this->_config['tree_grid_options']['ExpandColumnWidth']; } } if (isset($map['length']) and $map['length'] >= 255 or $map['type'] == 'text') { $data['edittype'] = self::TYPE_TEXTAREA; $data['hidden'] = true; $data['editrules']['edithidden'] = true; } if ('boolean' == $map['type']) { $data['align'] = 'center'; $data['formatter'] = 'checkbox'; $data['edittype'] = 'checkbox'; $data['stype'] = self::TYPE_SELECT; $data['searchoptions']['sopt'] = array('eq', 'ne'); $data['searchoptions']['value'] = ':;0:No;1:Yes'; $data['editoptions']['value'] = '1:0'; } if (in_array($fieldName, $this->_config['hidden_columns'])) { $data['hidden'] = true; $data['editrules']['edithidden'] = true; } if (in_array($fieldName, $this->_config['non_editable_columns'])) { $data['editable'] = false; $data['hidden'] = true; } if (isset($this->_config['column_type_mapping'][$fieldName])) { $data['edittype'] = $data['stype'] = $this->_config['column_type_mapping'][$fieldName]; } if (isset($this->_config['column_model'][$fieldName])) { $data = $utils->arrayMergeRecursiveCustom($data, $this->_config['column_model'][$fieldName]); } if (empty($data['searchoptions']['sopt'])) { $data['searchoptions']['sopt'] = $this->getSearchOptions(); } if ($this->isRequired($map, $data, $fieldName, $default)) { $data['editrules']['required'] = true; $data['formoptions']['elmprefix'] = '<i class="req">*</i>'; } else { $data['editrules']['required'] = false; $data['formoptions']['elmprefix'] = '<i class="nq"></i>'; } //@todo temporary fix to tree expand column when hidden elements appear before it $colIndex = $data['hidden'] ? $count + 99 : $count - $adjustment; $columnData[$colIndex] = $data; $count++; } foreach ($mapping->associationMappings as $map) { $data = array(); $fieldName = $map['fieldName']; $default = isset($defaultValues[$fieldName]) ? $defaultValues[$fieldName] : null; if (in_array($fieldName, $this->_config['excluded_columns'])) { continue; } if ($this->_isSubGridAsGrid($fieldName) and !$this->_isSubGrid($fieldName)) { $this->_subGridsAsGrid[] = $this->createSubGridAsGrid($map); $this->setSubGrid(true); continue; } else { if (!$this->_hasSubGrid and $this->_isSubGrid($fieldName)) { $index = count($this->_subGrid); /** @var $subGrid \SynergyDataGrid\Grid\GridType\BaseGrid */ $subGrid = $this->getSubGridModel($map); $target = $fieldName; $generator = null; if (is_string($this->_config['grid_url_generator'])) { $generator = $this->_serviceLocator->get($this->_config['grid_url_generator']); $subGridUrl = $this->getSubGridUrl(); if ($generator instanceof BaseConfigHelper) { $subGridUrl = $generator->execute(array($this->getEntity(), $fieldName, $map['targetEntity'], self::DYNAMIC_URL_TYPE_SUBGRID)); $editUrl = $generator->execute(array($map['targetEntity'], $fieldName, null, self::DYNAMIC_URL_TYPE_GRID)); $subGrid->setUrl($subGridUrl); $subGrid->setEditurl($editUrl); } } elseif (is_callable($this->_config['grid_url_generator'])) { $generator = $this->_config['grid_url_generator']; $subGridUrl = $generator($this->getServiceLocator(), $this->getEntity(), $fieldName, $map['targetEntity'], self::DYNAMIC_URL_TYPE_SUBGRID); $editUrl = $generator($this->getServiceLocator(), $map['targetEntity'], $fieldName, null, self::DYNAMIC_URL_TYPE_GRID); $subGrid->setUrl($subGridUrl); $subGrid->setEditurl($editUrl); } else { $subGridUrl = $this->getSubGridUrl(); } if (strpos($subGridUrl, '?') === false) { $subGridUrl .= '?fieldName=' . $target; } else { $subGridUrl .= '&fieldName=' . $target; } $this->setSubGridModel(array($subGrid)); $this->setSubGridUrl($subGridUrl); $this->_hasSubGrid = true; $this->setSubGrid(true); $this->_subGrid[$index] = $subGrid; } } if (isset($this->_config['column_type_mapping'][$fieldName])) { $type = $this->_config['column_type_mapping'][$fieldName]; } else { $type = self::TYPE_SELECT; } $values = $this->_getRelatedList($map, $fieldName); if (is_array($values)) { $values = implode(';', $values); } $data = array_merge_recursive(array('name' => $fieldName, 'edittype' => $type, 'stype' => $type, 'editable' => true, 'hidden' => false, 'editrules' => array('edithidden' => true), 'searchoptions' => array('value' => $values, 'sopt' => array('eq', 'ne')), 'editoptions' => array('value' => $values)), $data); if ($type = self::TYPE_SELECT && isset($this->_config['select']['options'])) { $data = array_merge_recursive($this->_config['select']['options'], $data); } if ($map['type'] == ClassMetadataInfo::MANY_TO_MANY or $map['type'] == ClassMetadataInfo::ONE_TO_MANY) { $data['editoptions']['multiple'] = true; $data['hidden'] = true; } if (!isset($data['searchoptions']['sopt'])) { $data['searchoptions']['sopt'] = array_keys($this->_expression); } if (isset($this->_config['column_model'][$fieldName])) { $data = $utils->arrayMergeRecursiveCustom($data, $this->_config['column_model'][$fieldName]); } if ($this->isRequired($map, $data, $fieldName, $default)) { $data['editrules']['required'] = true; $data['formoptions']['elmprefix'] = '<i class="req">*</i>'; } else { $data['editrules']['required'] = false; $data['formoptions']['elmprefix'] = '<i class="nq"></i>'; } $columnData[$count - $adjustment] = $data; $count++; } ksort($columnData); $this->addColumns($columnData); // close form after edit if ($actionColumn = $this->getColumn('myac')) { $actionColumn->mergeFormatoptions(array('editOptions' => array('closeAfterEdit' => true))); } $this->_columnsSet = true; } return $this; }