Ejemplo n.º 1
0
 public function __construct()
 {
     if ($this->_resources = Axis::cache()->load('axis_acl_resources')) {
         return;
     }
     foreach (Axis::app()->getModules() as $moduleName => $path) {
         if ('Axis_Admin' === $moduleName) {
             $path = $path . '/controllers';
         } else {
             $path = $path . '/controllers/Admin';
         }
         if (!is_dir($path)) {
             continue;
         }
         foreach ($this->_scanDirectory($path) as $file) {
             if (strstr($file, "Controller.php") == false) {
                 continue;
             }
             include_once $file;
         }
     }
     $resource = 'admin';
     $resources = array($resource);
     $camelCaseToDash = new Zend_Filter_Word_CamelCaseToDash();
     foreach (get_declared_classes() as $class) {
         if (!is_subclass_of($class, 'Axis_Admin_Controller_Back')) {
             continue;
         }
         list($module, $controller) = explode('Admin_', $class, 2);
         $module = rtrim($module, '_');
         if (empty($module)) {
             $module = 'Axis_Core';
         } elseif ('Axis' === $module) {
             $module = 'Axis_Admin';
         }
         $module = strtolower($camelCaseToDash->filter($module));
         list($namespace, $module) = explode('_', $module, 2);
         $resource .= '/' . $namespace;
         $resources[$resource] = $resource;
         $resource .= '/' . $module;
         $resources[$resource] = $resource;
         $controller = substr($controller, 0, strpos($controller, "Controller"));
         $controller = strtolower($camelCaseToDash->filter($controller));
         $resource .= '/' . $controller;
         $resources[$resource] = $resource;
         foreach (get_class_methods($class) as $action) {
             if (false == strstr($action, "Action")) {
                 continue;
             }
             $action = substr($action, 0, strpos($action, 'Action'));
             $action = strtolower($camelCaseToDash->filter($action));
             //                $resources[$namespace][$module][$controller][] = $action;
             $resources[$resource . '/' . $action] = $resource . '/' . $action;
         }
         $resource = 'admin';
     }
     asort($resources);
     Axis::cache()->save($resources, 'axis_acl_resources', array('modules'));
     $this->_resources = $resources;
 }
 public function testFilterSeparatesCamelCasedWordsWithDashes()
 {
     $string = 'CamelCasedWords';
     $filter = new Zend_Filter_Word_CamelCaseToDash();
     $filtered = $filter->filter($string);
     $this->assertNotEquals($string, $filtered);
     $this->assertEquals('Camel-Cased-Words', $filtered);
 }
Ejemplo n.º 3
0
 public function helpAction()
 {
     $cc2d = new Zend_Filter_Word_CamelCaseToDash();
     foreach (glob(__DIR__ . '/*.php') as $file) {
         if (!preg_match('/.*\\/(\\w+).php$/', $file, $matches) || $matches[1] == 'Abstract') {
             continue;
         }
         print $_SERVER['argv'][0] . ' ' . strtolower($cc2d->filter($matches[1])) . PHP_EOL;
     }
 }
Ejemplo n.º 4
0
 public function helpAction()
 {
     $cc2d = new Zend_Filter_Word_CamelCaseToDash();
     foreach (get_class_methods($this) as $method) {
         if (!preg_match('/^(\\w+)Action$/', $method, $matches) || $matches[1] == 'Abstract') {
             continue;
         }
         print $_SERVER['argv'][0] . ' ' . $_SERVER['argv'][1] . ' ' . strtolower($cc2d->filter($matches[1])) . PHP_EOL;
     }
 }
Ejemplo n.º 5
0
 /**
  * Установить шаблон для формы
  *
  * @param string $template Имя файла с шаблоном без расширения
  */
 public function setTemplate($template, $options = null)
 {
     if (is_null($options)) {
         $options = array();
     }
     if (is_array($options)) {
         $filter = new Zend_Filter_Word_CamelCaseToDash();
         $template = $filter->filter($template);
         $options['viewScript'] = 'forms/' . $template . '.phtml';
     }
     $this->setDecorators(array(array('viewScript', $options)));
 }
Ejemplo n.º 6
0
 /**
  * Create action for the view-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 view name that ' . $tense . ' used with other providers is "' . $name . '";' . ' not "' . $originalName . '" as supplied', array('color' => array('yellow')));
     }
     try {
         $viewResource = self::createResource($this->_loadedProfile, $name, $controllerName, $module);
     } catch (Exception $e) {
         $response->setException($e);
         return;
     }
     // view spec
     $inflectedController = strtolower($camelCaseToDashFilter->filter($controllerName));
     $viewPath = str_replace(basename($viewResource->getContext()->getPath()), '', $viewResource->getContext()->getPath());
     $basePath = str_replace("application/views/scripts/{$inflectedController}", '', $viewPath);
     $specNameFilter = new DashToCamelCase();
     $specName = UCFirst::apply($specNameFilter->filter($name));
     $moduleController = $inflectedController;
     if ($module !== null) {
         $moduleController .= strtolower($camelCaseToDashFilter->filter($module));
     }
     $viewSpecPath = realpath($basePath . '/spec/views') . '/' . $moduleController . '/' . $specName . 'Spec.php';
     $specContent = $this->_getSpecContent($name, $controllerName, $module);
     if ($request->isPretend()) {
         $response->appendContent('Would create a view script in location ' . $viewResource->getContext()->getPath());
         $response->appendContent('Would create a spec at ' . $viewSpecPath);
     } else {
         $response->appendContent('Creating a view script in location ' . $viewResource->getContext()->getPath());
         $viewResource->create();
         $response->appendContent('Creating a spec at ' . $viewSpecPath);
         if (!is_dir($basePath . '/spec/views')) {
             mkdir($basePath . '/spec/views');
         }
         if (!is_dir($basePath . '/spec/views/' . $inflectedController)) {
             mkdir($basePath . '/spec/views/' . $inflectedController);
         }
         file_put_contents($viewSpecPath, $specContent);
     }
 }
Ejemplo n.º 7
0
 public function __call($name, $arguments)
 {
     $this->_mail = new Zend_Mail('utf-8');
     $options = $arguments[0];
     $f = new Zend_Filter_Word_CamelCaseToDash();
     $tplDir = APPLICATION_PATH . '/../emailing/';
     $mailView = new Zend_View();
     $layoutView = new Zend_View();
     $mailView->setScriptPath($tplDir);
     $layoutView->setScriptPath($tplDir);
     $template = strtolower($f->filter($name)) . '.phtml';
     $subjects = new Zend_Config_Ini(APPLICATION_PATH . '/configs/mailing.ini', 'subjects');
     $subjects = $subjects->toArray();
     if (!is_readable(realpath($tplDir . $template))) {
         throw new Zend_Mail_Exception('No existe template para este email');
     }
     if (!array_key_exists($name, $subjects) || trim($subjects[$name]) == "") {
         throw new Zend_Mail_Exception('Subject no puede ser vacío, verificar mailing.ini');
     } else {
         $options['subject'] = $subjects[$name];
     }
     if (!array_key_exists('to', $options)) {
         throw new Zend_Mail_Exception('Falta indicar destinatario en $options["to"]');
     } else {
         $v = new Zend_Validate_EmailAddress();
         if (!$v->isValid($options['to'])) {
             //throw new Zend_Mail_Exception('Email inválido');
             // En lugar de lanzar un error, mejor lo logeo.
             $log = Zend_Registry::get('log');
             $log->warn('Email inválido: ' . $options['to']);
         }
     }
     foreach ($options as $key => $value) {
         $mailView->assign($key, $value);
         $options['subject'] = str_replace('{%' . $key . '%}', $value, $options['subject']);
     }
     $mailView->addHelperPath('Core/View/Helper', 'Core_View_Helper');
     $layoutView->addHelperPath('Core/View/Helper', 'Core_View_Helper');
     $mailViewHtml = $mailView->render($template);
     $layoutView->assign('emailTemplate', $mailViewHtml);
     $mailHtml = $layoutView->render('_layout.phtml');
     $this->_mail->setBodyHtml($mailHtml);
     $this->_mail->addTo($options['to']);
     $this->_mail->setSubject($options['subject']);
     $this->_mail->send();
 }
Ejemplo n.º 8
0
 /**
  * convertToClientNaming()
  *
  * Convert words to client specific naming, in this case is lower, dash separated
  *
  * Filters are lazy-loaded.
  *
  * @param string $string
  * @return string
  */
 public function convertToClientNaming($string)
 {
     if (!$this->_filterToClientNaming) {
         $filter = new Zend_Filter();
         $filter->addFilter(new Zend_Filter_Word_CamelCaseToDash());
         $filter->addFilter(new Zend_Filter_StringToLower());
         $this->_filterToClientNaming = $filter;
     }
     return $this->_filterToClientNaming->filter($string);
 }
Ejemplo n.º 9
0
 protected function _init()
 {
     $this->setDispatcher(new Kwf_Controller_Dispatcher());
     $this->setControllerDirectory('controllers');
     $this->returnResponse(true);
     $this->setParam('disableOutputBuffering', true);
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Welcome', 'kwf_controller_action_welcome');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/User', 'kwf_controller_action_user');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Error', 'kwf_controller_action_error');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Pool', 'kwf_controller_action_pool');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Debug', 'kwf_controller_action_debug');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Cli', 'kwf_controller_action_cli');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Cli/Web', 'kwf_controller_action_cli_web');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Media', 'kwf_controller_action_media');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Spam', 'kwf_controller_action_spam');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Enquiries', 'kwf_controller_action_enquiries');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Redirects', 'kwf_controller_action_redirects');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Maintenance', 'kwf_controller_action_maintenance');
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Trl', 'kwf_controller_action_trl');
     if (file_exists('controllers/Cli')) {
         $this->addControllerDirectory('controllers/Cli', 'cli');
     }
     $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Component', 'kwf_controller_action_component');
     if (is_dir('controllers')) {
         //automatically add controller directories from web based on existing directories in filesystem in web
         $iterator = new DirectoryIterator('controllers');
         $filter = new Zend_Filter_Word_CamelCaseToDash();
         foreach ($iterator as $fileinfo) {
             if (!$fileinfo->isDot() && $fileinfo->isDir() && $fileinfo->getBasename() != 'Cli') {
                 $this->addControllerDirectory($fileinfo->getPathname(), strtolower($filter->filter($fileinfo->getBasename())));
             }
         }
     }
     $plugin = new Zend_Controller_Plugin_ErrorHandler();
     $plugin->setErrorHandlerModule('kwf_controller_action_error');
     if (PHP_SAPI == 'cli') {
         $plugin->setErrorHandlerController('cli');
     }
     $this->registerPlugin($plugin);
     $this->setBaseUrl(Kwf_Setup::getBaseUrl());
 }
Ejemplo n.º 10
0
 /**
  * convertToClientNaming()
  *
  * Convert words to client specific naming, in this case is lower, dash separated
  *
  * Filters are lazy-loaded.
  *
  * @param string $string
  * @return string
  */
 public function convertToClientNaming($string)
 {
     if (!$this->_filterToClientNaming) {
         #require_once 'Zend/Filter.php';
         #require_once 'Zend/Filter/Word/CamelCaseToDash.php';
         #require_once 'Zend/Filter/StringToLower.php';
         $filter = new Zend_Filter();
         $filter->addFilter(new Zend_Filter_Word_CamelCaseToDash());
         $filter->addFilter(new Zend_Filter_StringToLower());
         $this->_filterToClientNaming = $filter;
     }
     return $this->_filterToClientNaming->filter($string);
 }
Ejemplo n.º 11
0
 /**
  * @param Doctrine_Import_Builder $builder
  * @param array $definition
  */
 protected function _buildRecord($builder, $definition)
 {
     $className = $definition['className'];
     if (strpos($className, "Model_") === false) {
         throw ZFDoctrine_DoctrineException::invalidZendModel($className);
     }
     $classPrefix = substr($className, 0, strpos($className, 'Model_') + strlen('Model_'));
     $camelCaseToDash = new Zend_Filter_Word_CamelCaseToDash();
     $moduleName = current(explode("_", $className));
     $moduleName = strtolower($camelCaseToDash->filter($moduleName));
     if (!isset($this->_modules[$moduleName])) {
         throw ZFDoctrine_DoctrineException::unknownModule($moduleName, $className);
     }
     $builder->setTargetPath($this->_modules[$moduleName]);
     $builder->buildRecord($definition);
     if ($this->_listener) {
         $this->_listener->notifyRecordBuilt($className, $moduleName);
     }
 }
Ejemplo n.º 12
0
 public function urlizeOptions($urlOptions, $actionControllerModuleOnly = true)
 {
     $ccToDash = new Zend_Filter_Word_CamelCaseToDash();
     foreach ($urlOptions as $n => $v) {
         if (in_array($n, array('action', 'controller', 'module'))) {
             $urlOptions[$n] = $ccToDash->filter($v);
         }
     }
     return $urlOptions;
 }
Ejemplo n.º 13
0
 /**
  * Inflect based on provided vars
  *
  * Allowed variables are:
  * - :moduleDir - current module directory
  * - :module - current module name
  * - :controller - current controller name
  * - :action - current action name
  * - :suffix - view script file suffix
  *
  * @param  array $vars
  * @return string
  */
 protected function _translateSpec(array $vars = array())
 {
     $inflector = $this->getInflector();
     $request = $this->getRequest();
     $dispatcher = $this->getFrontController()->getDispatcher();
     // Format module name
     $module = $dispatcher->formatModuleName($request->getModuleName());
     // Format controller name
     // require_once 'Zend/Filter/Word/CamelCaseToDash.php';
     $filter = new Zend_Filter_Word_CamelCaseToDash();
     $controller = $filter->filter($request->getControllerName());
     $controller = $dispatcher->formatControllerName($controller);
     if ('Controller' == substr($controller, -10)) {
         $controller = substr($controller, 0, -10);
     }
     // Format action name
     $action = $dispatcher->formatActionName($request->getActionName());
     $params = compact('module', 'controller', 'action');
     foreach ($vars as $key => $value) {
         switch ($key) {
             case 'module':
             case 'controller':
             case 'action':
             case 'moduleDir':
             case 'suffix':
                 $params[$key] = (string) $value;
                 break;
             default:
                 break;
         }
     }
     if (isset($params['suffix'])) {
         $origSuffix = $this->getViewSuffix();
         $this->setViewSuffix($params['suffix']);
     }
     if (isset($params['moduleDir'])) {
         $origModuleDir = $this->_getModuleDir();
         $this->_setModuleDir($params['moduleDir']);
     }
     $filtered = $inflector->filter($params);
     if (isset($params['suffix'])) {
         $this->setViewSuffix($origSuffix);
     }
     if (isset($params['moduleDir'])) {
         $this->_setModuleDir($origModuleDir);
     }
     return $filtered;
 }
 /**
  * This returns the URL for an Omeka_Record with a 'slug' property.
  *
  * @param Omeka_Record $record The sluggable record to create the URL for.
  * @param string       $action The action to access the record with.
  *
  * @return string $uri The URI for the record.
  * @author Eric Rochester <*****@*****.**>
  **/
 public static function getSlugURI($record, $action)
 {
     // Copied from omeka/applications/helpers/UrlFunctions.php, record_uri.
     // Yuck.
     $recordClass = get_class($record);
     $inflector = new Zend_Filter_Word_CamelCaseToDash();
     $controller = strtolower($inflector->filter($recordClass));
     $controller = Inflector::pluralize($controller);
     $options = array('controller' => $controller, 'action' => $action, 'id' => $record->slug);
     $uri = url($options, 'id');
     return $uri;
 }
Ejemplo n.º 15
0
    echo __('Description');
    ?>
</th>
            <th><?php 
    echo __('Item Number');
    ?>
</th>
            <th><?php 
    echo __('Collection');
    ?>
</th>
        </tr>
    </thead>
    <tbody>
        <?php 
    $filter = new Zend_Filter_Word_CamelCaseToDash();
    ?>
        <?php 
    foreach (loop('search_texts') as $searchText) {
        ?>
        <?php 
        $record = get_record_by_id($searchText['record_type'], $searchText['record_id']);
        ?>
        <?php 
        $recordType = $searchText['record_type'];
        ?>
        <?php 
        set_current_record($recordType, $record);
        ?>
        <tr class="<?php 
        echo strtolower($filter->filter($recordType));
 /**
  * Get all Actions for a modul / controller
  *
  * Method scans modul/controller for actions, which have the Zend Framework
  * action method namespacing, like "indexAction".
  *
  * @param string $modul
  * @param string $controller
  * @return array
  * @access public
  */
 public function getActions($modul, $controller, $virtual)
 {
     $actions = array();
     if ($virtual == 0) {
         $frontController = Zend_Controller_Front::getInstance();
         $className = ucfirst($modul) . '_' . ucfirst($controller) . 'Controller';
         $classFile = ucfirst($controller) . 'Controller.php';
         $directory = $frontController->getControllerDirectory($modul);
         if (file_exists($directory . '/' . $classFile) === FALSE) {
             throw new Admin_Model_Acl_Exception('Controller file could not be found');
         }
         require_once $directory . '/' . $classFile;
         $reflect = new Zend_Reflection_Class($className);
         $CcFilter = new Zend_Filter_Word_CamelCaseToDash();
         foreach ($reflect->getMethods() as $method) {
             if (preg_match('/(\\w+)Action$/', $method->getName(), $match)) {
                 $actionComment = $method->getName();
                 $name = $match[1];
                 $docComment = $method->getDocComment();
                 if (is_string($docComment)) {
                     $commentRows = explode("\n", $docComment);
                     $actionComment = preg_replace("/^\\s*\\*\\s*(.*)\\s*/", '$1', $commentRows[1]);
                     if ($actionComment === "") {
                         $actionComment = $docComment;
                     }
                 }
                 $actions[] = new Admin_Model_DbRow_Action(array('actionName' => strtolower($CcFilter->filter($name)), 'description' => $actionComment));
             }
         }
     } else {
         foreach ($this->hooks as $hook) {
             foreach ($hook->getActions($modul, $controller) as $hAction) {
                 $actions[] = $hAction;
             }
             //$actions = array_merge_recursive($actions, $hook->getActions($modul, $controller));
         }
     }
     return $actions;
 }
Ejemplo n.º 17
0
 /**
  * Retrieve the module name for the plugin (based on the directory name
  * of the plugin).
  * 
  * @param string $pluginDirName Plugin name.
  * @return string Plugin MVC module name.
  */
 protected function _getModuleName($pluginDirName)
 {
     // Module name needs to be lowercased (plugin directories are not,
     // typically).  Module name needs to go from camelCased to dashed
     // (ElementSets --> element-sets).
     $inflector = new Zend_Filter_Word_CamelCaseToDash();
     $moduleName = strtolower($inflector->filter($pluginDirName));
     return $moduleName;
 }
Ejemplo n.º 18
0
Archivo: Mail.php Proyecto: josmel/voy
 public function __call($name, $arguments)
 {
     try {
         $this->_mail = new Zend_Mail('utf-8');
         $options = $arguments[0];
         $f = new Zend_Filter_Word_CamelCaseToDash();
         $tplDir = APPLICATION_PATH . '/entitys/mailing/templates/';
         $mailView = new Zend_View();
         $layoutView = new Zend_View();
         $mailView->setScriptPath($tplDir);
         $layoutView->setScriptPath($tplDir);
         $template = strtolower($f->filter($name)) . '.phtml';
         if (!is_readable(realpath($tplDir . $template))) {
             throw new Zend_Mail_Exception('No existe template para este email');
         }
         $mailConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/mail.ini', 'mail');
         $mailConfig = $mailConfig->toArray();
         $paramsTemplate = array();
         if (array_key_exists($name, $mailConfig)) {
             $paramsTemplate = $mailConfig[$name];
         } else {
             throw new Zend_Mail_Exception('No existe configuración para este template. Verificar mailing.ini');
         }
         $smtpHost = $mailConfig['mailServer'];
         //$smtpConf = $mailConfig['connectionData'][$paramsTemplate['sendAccount']];
         $smtpConf = $mailConfig['connectionData'];
         $transport = new Zend_Mail_Transport_Smtp($smtpHost, $smtpConf);
         if (!array_key_exists('subject', $paramsTemplate) || trim($paramsTemplate['subject']) == "") {
             throw new Zend_Mail_Exception('Subject no puede ser vacío, verificar mailing.ini');
         } else {
             $options['subject'] = $paramsTemplate['subject'];
             if (isset($paramsTemplate['from'])) {
                 $options['from'] = $paramsTemplate['from'];
                 $options['fromName'] = $paramsTemplate['fromName'];
             } else {
                 $options['from'] = $mailConfig['defaults']['from'];
                 $options['fromName'] = $mailConfig['defaults']['fromName'];
             }
         }
         if (!array_key_exists('to', $options)) {
             $options['to'] = $mailConfig['defaults']['from'];
             // throw new Zend_Mail_Exception('Falta indicar destinatario en $options["to"]');
         } else {
             $v = new Zend_Validate_EmailAddress();
             //            if (!$v->isValid($options['to'])) {
             //                //throw new Zend_Mail_Exception('Email inválido');
             //                // En lugar de lanzar un error, mejor lo logeo.
             //                $log = Zend_Registry::get('log');
             //                $log->warn('Email inválido: ' . $options['to']);
             //            }
         }
         foreach ($options as $key => $value) {
             $mailView->assign($key, $value);
             if (!is_array($value)) {
                 $options['subject'] = str_replace('{%' . $key . '%}', $value, $options['subject']);
                 $template = str_replace('{%' . $key . '%}', $value, $template);
             }
         }
         $mailView->mailData = $options;
         $layoutView->mailData = $options;
         //echo $template; exit;
         $mailView->addHelperPath('App/View/Helper', 'App_View_Helper');
         $layoutView->addHelperPath('App/View/Helper', 'App_View_Helper');
         $mailViewHtml = $mailView->render($template);
         //var_dump($transport);exit;
         //echo $mailViewHtml; exit;
         //$layoutView->assign('emailTemplate', $mailViewHtml);
         //$mailHtml = $layoutView->render('_layout.phtml');
         $this->_mail->setBodyHtml($mailViewHtml);
         $this->_mail->setFrom($options['from'], $options['fromName']);
         $this->_mail->addTo($options['to']);
         if (isset($paramsTemplate['Cc'])) {
             $Cc = explode(",", $paramsTemplate['Cc']);
             $this->_mail->addCc($Cc);
         }
         //            $this->_mail->setSubject($options['subject']);
         $this->_mail->setSubject($options['asunto']);
         $this->_mail->send($transport);
         $options['dataMailing']['from'] = $options['from'];
         $options['dataMailing']['subject'] = $options['subject'];
         $options['dataMailing']['template'] = $name;
         //            $modelMail = new Mailing_Model_Mailing();
         //            $modelMail->save($options['dataMailing']);
     } catch (Exception $ex) {
         $stream = @fopen(LOG_PATH . '/mailerror.log', 'a+', false);
         if (!$stream) {
             echo "Error al abrir log.";
         }
         $writer = new Zend_Log_Writer_Stream(LOG_PATH . '/mailerror.log');
         $logger = new Zend_Log($writer);
         $logger->info('***********************************');
         $logger->info('Template: ' . $name);
         $logger->info('Mail Data: ' . Zend_Json_Encoder::encode($arguments));
         $logger->info('Error Message: ' . $ex->getMessage());
         $logger->info('***********************************');
         $logger->info('');
     }
 }
Ejemplo n.º 19
0
 /**
  * This method will take a Parameter Name and format it for Endpoint usage,
  * The Tool will be PROVIDING the Parameter Name in camelCase 
  *
  * The Cli Endpoint will EXPECT the parameter name in 'dashed-lower-format'
  * 
  * @param string $parameterName
  */
 public function parameterNameForEndpoint($parameterName)
 {
     return $this->_camelCaseToDashed->filter($parameterName);
 }
Ejemplo n.º 20
0
 /**
  * @param unknown_type $formName
  * @param unknown_type $options
  * @throws Exception
  * @return Zend_Form
  */
 public function getForm($formName, $options = null, $useTemplate = false)
 {
     if (is_null(self::$_forms)) {
         if (is_file(APPLICATION_PATH . '/configs/forms.ini')) {
             $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/forms.ini');
         } else {
             $config = new Zend_Config(include_once APPLICATION_PATH . '/configs/forms.php');
         }
         $config = $config->toArray();
         self::$_forms = $config;
     }
     if (!array_key_exists($formName, $config)) {
         throw new Exception("Form not exist");
     }
     if ($useTemplate) {
         //$form = new Zend_Form_Template($config[$formName]);
         //$form->setTemplate($formName, $options);
         $form = new Zend_Form($config[$formName]);
         $elements = $form->getElements();
         foreach ($elements as &$element) {
             $element->removeDecorator('Label');
             $element->removeDecorator('HtmlTag');
             $element->removeDecorator('DtDdWrapper');
             $element->removeDecorator('Description');
             $element->removeDecorator('Errors');
             $element->addDecorator(array('data' => 'Errors'), array('tag' => 'p', 'class' => 'description'));
         }
         $filter = new Zend_Filter_Word_CamelCaseToDash();
         $formName = $filter->filter($formName);
         $options['viewScript'] = 'forms/' . $formName . '.phtml';
         $form->setDecorators(array(array('viewScript', $options)));
     } else {
         $form = new Zend_Form($config[$formName]);
         /*  $form->addElementPrefixPath('Zend_Decorator',
             'Zend/Decorator/',
             'decorator');
             $form->setDecorators(array('Default'));*/
         //Zend_Debug::dump($form->getDecorator('Errors'));
         /*$elements = $form->getElements();
                     foreach ($elements as &$element) {
         
                         $element->setDecorators(
                             array(
                             'ViewHelper',
                             'Errors',
                             array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element')),
                             'Label',
                             array(array('row' => 'HtmlTag'), array('tag' => 'li'))
                             )
                         );
         
                         //Zend_Debug::dump($element->getDecorator('Errors'));
         
                     };*/
         /*
                     $form->setElementDecorators(array(
                         'ViewHelper',
                         array('Errors', array('class' => 'help-inline control-error')),
                         array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'controls')),
                         array(array('label' => 'Label'), array('class' => 'control-label')),
                         array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'control-group')),
                     ));
         */
         // $form->addElement("text", "naem", $opt);
         /* $form->setDecorators(array(
                'FormElements',
                array('Form', array('class' => 'form-horizontal'))
            ));*/
         //Zend_Debug::dump($form);
         // вынести декораторы
     }
     $formAction = $form->getAction();
     $routes = $this->getRouterNames();
     $actionParams = array();
     if (is_array($options) && array_key_exists('actionParams', $options)) {
         $actionParams = $options['actionParams'];
     }
     if (in_array($formAction, $routes)) {
         if (array_key_exists("actionParams", $config[$formName]) && is_array($config[$formName]['actionParams'])) {
             $actionParams = $config[$formName]['actionParams'];
         }
         $form->setAction($this->_url($actionParams, $formAction));
     }
     //Zend_Debug::dump($form);
     return $form;
 }
Ejemplo n.º 21
0
 /**
  * Gets the content of scaffolded show view
  *
  * @param string $entity 
  * @param array $fields 
  * @return string
  */
 protected static function _getShowViewContent($entity, $fields)
 {
     $upperFirst = new UCFirst();
     $lowerFirst = new LCFirst();
     $camelCaseToSpace = new CamelCaseToSeparator();
     $camelCaseToDash = new CamelCaseToDash();
     $pluralize = new Pluralize();
     $lowerEntity = $lowerFirst->filter($entity);
     $lowerEntityPlural = $pluralize->filter($lowerEntity);
     $dashedEntityPlural = $camelCaseToDash->filter($lowerEntityPlural);
     $properties = '';
     foreach ($fields as $field) {
         $upper = $upperFirst->filter($field);
         $field = $camelCaseToSpace->filter($field);
         $field = $upperFirst->filter($field);
         $properties .= "  <p>\n    <b>{$field}:</b>\n    <?php echo \$this->escape(\$this->{$lowerEntity}->get{$upper}()) ?></h3>\n  </p>" . PHP_EOL . PHP_EOL;
     }
     return "<h1>Show {$entity}</h1>\n\n{$properties}\n\n<a href=\"<?php echo \$this->baseUrl(" . "'{$dashedEntityPlural}/edit/id/' ." . " (int)\$this->{$lowerEntity}->getId()) ?>\">Edit</a> |\n<a href=\"<?php echo \$this->baseUrl(" . "'{$dashedEntityPlural}') ?>\">Back</a>";
 }
Ejemplo n.º 22
0
    /**
     * 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();
    }
}';
    }
Ejemplo n.º 23
0
 /**
  * Creates the scaffolded delete action
  *
  * @param string $entity 
  * @return string
  */
 protected static function _getDeleteActionContent($entity)
 {
     $camelCaseToDash = new CamelCaseToDash();
     $lcFirst = new LCFirst();
     $pluralize = new Pluralize();
     $lc = $lcFirst->filter($entity);
     $plural = $pluralize->filter($lc);
     $lowerDashedPlural = $camelCaseToDash->filter($plural);
     return "\${$lc}Mapper = \$this->get('Model.{$entity}Mapper');\n        \${$lc} = \${$lc}Mapper->find(\$this->_request->id);\n        \${$lc}Mapper->delete(\${$lc});\n        \$this->_redirect('/{$lowerDashedPlural}');";
 }
Ejemplo n.º 24
0
    /**
     * 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;
    }