Ejemplo n.º 1
0
 public function __construct($options = array())
 {
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     } else {
         if (!is_array($options)) {
             $options = func_get_args();
             $temp['format'] = array_shift($options);
             if (!empty($options)) {
                 $temp['locale'] = array_shift($options);
             }
             $options = $temp;
         }
     }
     if (array_key_exists('format', $options)) {
         $this->setFormat($options['format']);
     }
     if (!array_key_exists('locale', $options)) {
         if (Registry::isRegistered('Zend_Locale')) {
             $options['locale'] = Registry::get('Zend_Locale');
         }
     }
     if (array_key_exists('locale', $options)) {
         $this->setLocale($options['locale']);
     }
 }
Ejemplo n.º 2
0
 public function __construct($colum)
 {
     $this->conn = Registry::get('db');
     $this->request = $_GET;
     $this->colum = array_keys($colum);
     $this->tipodados = array_values($colum);
     $this->init();
 }
Ejemplo n.º 3
0
 public function __construct($filename)
 {
     $route = Registry::get('route');
     $this->_filename = APPLICATION_PATH . '/application/Module/' . ucwords($route->getModule()) . '/view/partials/' . $filename;
     if (!file_exists($this->_filename)) {
         throw new Exception('Partial file does not exist');
     }
 }
Ejemplo n.º 4
0
 public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
 {
     $route = Registry::get('route');
     $baseUrl = trim($route->getBaseUrl(), '/');
     $url = $baseUrl . '/example/' . $urlOptions['controller'] . '/' . $urlOptions['action'];
     return $url;
     /*$route = Registry::get('route');
       $route = new Rewrite();
       return $route->assemble($urlOptions, $name, $reset, $encode);*/
 }
Ejemplo n.º 5
0
 public function getRelativePath($forceCreation = false)
 {
     if (null === $this->getFilepath()) {
         return null;
     }
     $fullPath = $this->getFullPath($forceCreation);
     $route = Registry::get('route');
     $baseUrl = $route->getBaseUrl();
     $documentRoot = Library::getDocumentRoot() . $baseUrl . '/public';
     return substr($fullPath, strlen($documentRoot));
 }
Ejemplo n.º 6
0
 protected function configure()
 {
     $config = Registry::get('config');
     $this->mail->CharSet = 'utf-8';
     $this->mail->IsSMTP();
     $this->mail->IsHtml();
     $this->mail->Host = $config['phpmailer.host'];
     $this->mail->Port = $config['phpmailer.port'];
     $this->mail->SMTPAuth = $config['phpmailer.smtpAuth'];
     $this->mail->Username = $config['phpmailer.username'];
     $this->mail->Password = $config['phpmailer.password'];
     $this->mail->SMTPSecure = $config['phpmailer.smtpSecure'];
     $this->mail->From = array_key_exists('phpmailer.from', $config) ? $config['phpmailer.from'] : '';
     $this->mail->FromName = array_key_exists('phpmailer.fromName', $config) ? $config['phpmailer.fromName'] : '';
 }
Ejemplo n.º 7
0
 public function getContainer()
 {
     if (null === $this->_container) {
         // try to fetch from registry first
         if (Registry::isRegistered('Life\\Navigation')) {
             $nav = Registry::get('Life\\Navigation');
             if ($nav instanceof Container) {
                 return $this->_container = $nav;
             }
         }
         // nothing found in registry, create new container
         $this->_container = new Navigation();
     }
     return $this->_container;
 }
Ejemplo n.º 8
0
 public function __construct($iniConfigurationFilepath)
 {
     $config = Library::parse_ini_file_advanced($iniConfigurationFilepath);
     $this->config = $config[APPLICATION_ENV];
     $this->route = new Route();
     $this->request = new Request();
     $this->_loadPHPSettings();
     if (php_sapi_name() !== 'cli') {
         $this->route->setCurrentUrl($_SERVER['REQUEST_URI']);
     }
     $baseUrl = rtrim('/' . trim($this->config['general.baseUrl'], '/'), '/');
     $url = str_replace($baseUrl, '', $this->route->getCurrentUrl());
     Registry::set('config', $this->config);
     Registry::set('route', $this->route);
     Registry::set('request', $this->request);
     $this->route->setDefaultModule($this->config['general.defaultModule'])->setDefaultController($this->config['general.defaultController'])->setDefaultAction($this->config['general.defaultAction'])->setDefaultLayout($this->config['general.defaultLayout'])->setBaseUrl($baseUrl)->dispatchFromURL($url);
 }
Ejemplo n.º 9
0
 public function __construct(array $viewData = array(), $view = null, $layout = null)
 {
     $num_args = func_num_args();
     $noLayout = $num_args === 3 && $layout === null;
     $route = Registry::get('route');
     $module = $route->getModule();
     $controller = $route->getController();
     //$defaultLayout = $route->getLayout();
     if (null === $view) {
         // Pega o nome da view tratando as letras maiúsculas e colocando o traço
         $action = $route->getAction();
         $view = '';
         for ($i = 0; $i < strlen($action); $i++) {
             if (preg_match('/[A-Z]/', $action[$i])) {
                 $view .= '-';
             }
             $view .= strtolower($action[$i]);
         }
     }
     $route->setAction($view);
     $this->_data = $viewData;
     if (!isset($layout) && !$noLayout) {
         //$layout = 'layout-default';
         $layout = $route->getLayout();
     }
     $file = APPLICATION_PATH . '/application/Module/' . ucwords($module) . '/view/layout/' . $layout . '.phtml';
     $content = APPLICATION_PATH . '/application/Module/' . ucwords($module) . '/view/scripts/' . strtolower($controller) . '/' . $view . '.phtml';
     if (!file_exists($file) && !$noLayout) {
         //$file2 = APPLICATION_PATH . '/application/Layout/' . $defaultLayout . '.phtml';
         $file2 = APPLICATION_PATH . '/application/Layout/' . $layout . '.phtml';
         if (!file_exists($file2) && !$noLayout) {
             throw new Exception('An error ocurred. Layout <small>[' . $file . ']</small> neither <small>[' . $file2 . ']</small> exists');
         } else {
             $file = $file2;
         }
     }
     if (!file_exists($content)) {
         throw new Exception('An error ocurred. View <small>[' . $content . ']</small> doesn\'t exists');
     }
     if ($noLayout) {
         require_once $content;
     } else {
         require_once $file;
     }
 }
Ejemplo n.º 10
0
 public function getAdapter()
 {
     return Registry::get($this->_adapter);
 }
Ejemplo n.º 11
0
 public function render()
 {
     $form = $this->getForm();
     if (isset($form)) {
         $config = Registry::get('config');
         $configurable = false;
         if (array_key_exists('general.dynamicForms', $config)) {
             $configurable = (bool) $config['general.dynamicForms'];
         }
         if ($this instanceof Element or $this instanceof Multi) {
             if ($configurable) {
                 $this->loadConfiguration();
             }
         }
         if ($configurable) {
             $configuration = ConfigFormulario::getInstance();
             $entityFormulario = $configuration->getEntityFormulario();
             $entityCampoFormularioValor = $configuration->getEntityCampoFormularioValor();
             $config = $form->findConfiguration($entityFormulario);
             if ($config instanceof $entityFormulario) {
                 $form->carregarCamposComplementares($config, $entityCampoFormularioValor);
             }
         }
         $type = $form->getType();
         if ($type === $form::TYPE_BASIC) {
             $this->setElementBasic();
         } elseif ($type === $form::TYPE_INLINE) {
             $this->setElementInline();
         } elseif ($type === $form::TYPE_HORIZONTAL) {
             $this->setElementHorizontal();
         }
     }
     if ($this instanceof \Life\Form\Element\Text || $this instanceof \Life\Form\Element\Password || $this instanceof \Life\Form\Element\Select || $this instanceof \Life\Form\Element\Textarea) {
         $this->addAttrib('class', 'form-control');
     }
     if ($this->isRequired()) {
         $this->setAttrib('required', 'required');
     }
     $label = $this->getLabel();
     $input = $this->renderElement();
     $labelRender = '';
     if ($label) {
         $label->setAttrib('for', $this->getName());
         if ($this->isRequired()) {
             $label->addAttrib('class', 'required');
         }
         $labelRender = $this->getLabel()->render();
     }
     if (is_array($input)) {
         $input = implode($this->getSeparator(), $input);
     }
     $errorHTML = $this->getErrorHTML();
     if (is_null($errorHTML)) {
         $this->setErrorHTML($this->errorHTML);
     }
     $messages = $this->getMessages();
     $aMessages = array();
     if (count($messages) > 0) {
         foreach ($messages as $key => $message) {
             $aMessages[] = $message;
         }
         $errorHTML = $this->getErrorHTML();
         if (isset($errorHTML)) {
             $input .= sprintf($errorHTML, implode('<br />', $aMessages));
         } else {
             $input .= implode('<br />', $aMessages);
         }
     }
     $content = $this->getContent();
     if (!is_null($content)) {
         $input = sprintf($content, $input);
     }
     $externalHTML = $this->getExternalHTML();
     if (!is_null($externalHTML)) {
         return sprintf($externalHTML, $labelRender . $input);
     }
     return $labelRender . $input . PHP_EOL;
 }
Ejemplo n.º 12
0
 public function forward($action, $controllerNamespace = null, array $params = null)
 {
     if (null !== $params) {
         $request = Registry::get('request');
         $request->setParams($params);
     }
     if (null !== $controllerNamespace) {
         $this->setControllerNamespace($controllerNamespace)->dispatch();
     }
     $this->setAction($action)->run();
 }
Ejemplo n.º 13
0
 public function render()
 {
     $config = Registry::get('config');
     $configurable = false;
     if (array_key_exists('general.dynamicForms', $config)) {
         $configurable = (bool) $config['general.dynamicForms'];
     }
     if ($configurable) {
         $configuration = ConfigFormulario::getInstance();
         $entityFormulario = $configuration->getEntityFormulario();
         $entityCampoFormularioValor = $configuration->getEntityCampoFormularioValor();
         $config = $this->findConfiguration($entityFormulario);
         if ($config instanceof $entityFormulario) {
             $this->carregarCamposComplementares($config, $entityCampoFormularioValor);
         }
     }
     if ($this->type === self::TYPE_BASIC) {
         $this->setFormBasic();
     } elseif ($this->type === self::TYPE_INLINE) {
         $this->setFormInline();
     } elseif ($this->type === self::TYPE_HORIZONTAL) {
         $this->setFormHorizontal();
     }
     $attribs = $this->getAttribs();
     $aAttribs = array();
     if (count($attribs) > 0) {
         foreach ($attribs as $key => $value) {
             $aAttribs[] = $key . '="' . $value . '"';
         }
     }
     $itensHTML = '';
     $elements = $this->getElementsOrdered();
     if (count($elements) > 0) {
         foreach ($elements as $element) {
             $element->setLabelWidth($this->getLabelWidth())->setElementClassPrefix($this->getElementClassPrefix());
             if (null === $element->getElementWidth()) {
                 $element->setElementWidth($this->getElementWidth());
             }
             $itensHTML .= $element->render() . PHP_EOL;
         }
     }
     $content = $this->getContent();
     if (!is_null($content)) {
         $itensHTML = sprintf($content, $itensHTML);
     }
     $externalHTML = $this->getExternalHTML();
     if (is_null($externalHTML)) {
         $externalHTML = '%s';
     }
     $formHTML = PHP_EOL . '<form ' . implode(' ', $aAttribs) . '>' . PHP_EOL . $itensHTML . '</form>';
     return sprintf($externalHTML, $formHTML) . PHP_EOL;
 }
Ejemplo n.º 14
0
 /**
  * Finds the proper locale based on the input
  * Checks if it exists, degrades it when necessary
  * Detects registry locale and when all fails tries to detect a automatic locale
  * Returns the found locale as string
  *
  * @param string $locale
  * @throws Zend_Locale_Exception When the given locale is no locale or the autodetection fails
  * @return string
  */
 public static function findLocale($locale = null)
 {
     if ($locale === null) {
         if (Registry::isRegistered('Locale')) {
             $locale = Registry::get('Locale');
         }
     }
     if ($locale === null) {
         $locale = new Locale();
     }
     if (!Locale::isLocale($locale, true, false)) {
         if (!Locale::isLocale($locale, false, false)) {
             $locale = Locale::getLocaleToTerritory($locale);
             if (empty($locale)) {
                 throw new Exception("The locale '{$locale}' is no known locale");
             }
         } else {
             $locale = new Locale($locale);
         }
     }
     $locale = self::_prepareLocale($locale);
     return $locale;
 }
Ejemplo n.º 15
0
 public function __construct()
 {
     $this->_route = Registry::get('route');
     $this->_url = '/' . trim($this->_route->getCurrentUrl(), '/');
     $this->_breadcrumbs = new Breadcrumbs($this->_route);
 }
Ejemplo n.º 16
0
 public function execute()
 {
     $stmt = $this->conn->prepare($this->sql);
     try {
         if ($stmt->execute()) {
             if (is_null($this->keyValues)) {
                 $this->keyValues = $this->conn->lastInsertId();
                 if (isset($this->_camposComplementares)) {
                     foreach ($this->_camposComplementares as &$cc) {
                         $cc['codregistro'] = $this->keyValues;
                     }
                 }
             }
             $config = Registry::get('config');
             $configurable = false;
             if (array_key_exists('general.dynamicForms', $config)) {
                 $configurable = (bool) $config['general.dynamicForms'];
             }
             if ($configurable) {
                 $configuration = new FormConfiguration();
                 if (in_array($this->type, array('insert', 'update'))) {
                     if (isset($this->_camposComplementares)) {
                         $repo = $configuration->getRepoCampoFormularioValor();
                         $repo->salvarValores($this->_camposComplementares);
                     }
                 } elseif ($this->type === 'delete') {
                     if (isset($this->_codigosExcluir)) {
                         $configuration = new FormConfiguration();
                         $configuration->delete($this->table, $this->_codigosExcluir);
                     }
                 }
             }
             return $this->setCached(false)->getReference($this->keyValues);
         } else {
             return false;
         }
     } catch (\PDOException $e) {
         throw new Exception($e->getMessage());
     }
 }
Ejemplo n.º 17
0
 public function getRegistry($value)
 {
     return Registry::get($value);
 }
Ejemplo n.º 18
0
 public function getRoute()
 {
     return Registry::get('route');
 }