/** * Implements the create action for the action-spec provider * * @param string $name * @param string $controllerName * @param string $module * @return void */ public function create($name, $controllerName, $module = null) { $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION); if (!is_dir('spec')) { throw new ProviderException('Please run zf generate phpspec, to create the environment'); } $response = $this->_registry->getResponse(); $request = $this->_registry->getRequest(); $originalName = $name; $name = LCFirst::apply($name); $camelCaseToDashFilter = new CamelCaseToDash(); $name = strtolower($camelCaseToDashFilter->filter($name)); // alert the user about inline converted names $tense = $request->isPretend() ? 'would be' : 'is'; if ($name !== $originalName) { $response->appendContent('Note: The canonical action name that ' . $tense . ' used with other providers is "' . $name . '";' . ' not "' . $originalName . '" as supplied', array('color' => array('yellow'))); } try { $controllerResource = ControllerProvider::createResource($this->_loadedProfile, $controllerName, $module); $actionResource = self::createResource($this->_loadedProfile, $name, $controllerName, $module); } catch (Exception $e) { $response->setException($e); return; } // action spec $controllerPath = str_replace(basename($controllerResource->getContext()->getPath()), '', $controllerResource->getContext()->getPath()); $basePath = realpath($controllerPath . '/../..'); $controllerSpecPath = realpath($basePath . '/spec/controllers') . '/' . $controllerName . 'ControllerSpec.php'; $specContent = $this->_getSpecContent($name, $controllerName); if ($request->isPretend()) { $response->appendContent('Would create an action named ' . $name . ' inside controller at ' . $controllerResource->getContext()->getPath()); $response->appendContent('Would create an action spec at ' . $controllerSpecPath); } else { $response->appendContent('Creating an action named ' . $name . ' inside controller at ' . $controllerResource->getContext()->getPath()); $actionResource->create(); $response->appendContent('Creating an action spec at ' . $controllerSpecPath); $content = file_get_contents($controllerSpecPath); file_put_contents($controllerSpecPath, str_replace("\n}", $specContent, $content)); } }
/** * Creates the controller views and actions * * @param Registry $registry * @param Profile $profile * @param string $entity * @param string $commaSeparatedFields * @param string $module */ protected static function _createControllerViewsAndActions(Registry $registry, Profile $profile, $entity, $commaSeparatedFields, $module) { $pluralize = new Pluralize(); $entityPlural = $pluralize->filter($entity); $controllerResource = ControllerProvider::createResource($profile, $entityPlural, $module); $controllerPath = $controllerResource->getContext()->getPath(); self::_addAliasesForTheController($entity, $controllerPath); foreach (self::$_scaffoldActions as $action) { if ($action !== 'add' && $action !== 'update' && $action !== 'delete') { ViewContent::create($registry, $profile, $action, $entity, $commaSeparatedFields, $module); } ActionMethod::create($action, $entity, $controllerPath); } }