/**
  * Cria classe se ela não existe
  * 
  * @param string $namespace
  * @param string $class
  * @param string $parent
  * @param string $implements
  * @param string $license
  * */
 public static function create($namespace, $class, $parent = NUL, $implements = NULL, $license = NULL)
 {
     $NSTemp = $namespace;
     $namespace = self::NAMESPACE_SEPARATOR == substr($namespace, -1) ? substr($namespace, 0, -1) : $namespace;
     $namespace = $namespace . self::NAMESPACE_SEPARATOR . $class;
     $fullpath = Location::realpathFromNamespace($namespace) . '.php';
     if (TRUE == is_file($fullpath)) {
         return;
     }
     $dirname = dirname($fullpath);
     if (!is_dir($dirname)) {
         mkdir($dirname, 0700, TRUE);
     }
     $content = sprintf('<?php%5$s%1$s%5$s%2$s%5$s%5$s%3$s%5$s%4$s', self::classLicense(), self::classLocation($NSTemp), self::classDoc($NSTemp, $class), self::classDef($class, $parent, $implements), PHP_EOL);
     IOException::throwsExceptionIfParamIsNull(file_put_contents($fullpath, $content, LOCK_EX | FILE_TEXT), self::T_CREATECLASSIFNOTEXISTS_ERROR_ON_CREATE_CLASS);
 }
Example #2
0
 /**
  * retorna se cominho completo da classe (filha de SIALAbstract) informado
  *
  * @param SIALAbstract|string $target
  * @return string
  * @throws SIALException
  * */
 public static function realpathFromNamespace($target)
 {
     return Location::realpathFromNamespace($target);
 }
Example #3
0
 /**
  * Inicializa o bootstrap
  *
  * @return SIALApplication
  * */
 public function initBootstrap()
 {
     $namespace = $this->_config->get('app.mainnamespace') . self::NAMESPACE_SEPARATOR . 'library' . self::NAMESPACE_SEPARATOR . 'Bootstrap';
     require_once Location::realpathFromNamespace($namespace) . '.php';
     $this->_bootstrap = new $namespace($this->_config);
     return $this;
 }
Example #4
0
 /**
  * Construtor.
  *
  * @param ViewAbstract $view
  * */
 public function __construct(ViewAbstract $view)
 {
     # configura a pasta de templates da app
     $this->_applicationPath = $view->config()->get('app.namespace') . self::NAMESPACE_SEPARATOR;
     $this->_applicationPath = Location::realpathFromNamespace($this->_applicationPath);
     $this->_scriptPath = $view->getScriptPaths();
     $this->_type = $view::T_TYPE;
     $this->_extension = '.' == substr($view::T_EXTENSION, 0, 1) ? $view::T_EXTENSION : '.' . $view::T_EXTENSION;
     $this->_view = $view;
 }
 /**
  * retorna o controller que sera executado
  *
  * @return ControllerAbstract
  * @throws ControllerException
  * */
 public function controller()
 {
     $config = $this->config();
     $request = $this->request();
     $module = $request->getModule();
     $funcionality = $request->getFuncionality();
     $action = $request->getAction();
     $namespace = $config->get('app.namespace') . self::NAMESPACE_SEPARATOR;
     if (TRUE === Request::$useModule) {
         $namespace .= $module;
     }
     $namespace .= sprintf('%1$s%2$s%1$smvcb%1$scontroller%1$s%3$sController', self::NAMESPACE_SEPARATOR, $funcionality, ucfirst($funcionality));
     $fullpath = Location::realpathFromNamespace($namespace) . '.php';
     ControllerException::throwsExceptionIfParamIsNull(is_file($fullpath), "Controller::{$funcionality} não implementada");
     $ctrl = new $namespace();
     ControllerException::throwsExceptionIfParamIsNull($ctrl->hasAction($action), "Action '{$namespace}::{$action}' não existe.");
     return $ctrl;
 }
 /**
  * Recupera um método da business referente a controller em uso.
  *
  * @param Controller $target
  * @return BusinessAbstract
  * @throws BusinessException
  * @deprecated
  * @example ControllerAbstract::getBusiness
  * @code
  * <?php
  * ...
  *
  *  try {
  *      $this->getBusiness('save')
  *           ->setViewType('html')
  *           ->getView('sucess');
  *      } catch (Exception $exp) {
  *          $this->setViewType('html')
  *               ->getView('error');
  *      }
  *
  *  ...
  * ?>
  * @encode
  * */
 public function getBusiness($target = NULL)
 {
     $tmpBusinessTarget = $tmpNSBusiness = NULL;
     $target = $this->toggle($target, $this);
     $tmpArrNS = explode('controller' . self::NAMESPACE_SEPARATOR, $this->getClassName($target));
     $tmpBusinessTarget = $this->erReplace(array('Controller$' => 'Business'), (string) end($tmpArrNS));
     $tmpNSBusiness = $target->getNamespaceFuncionality() . self::NAMESPACE_SEPARATOR . 'mvcb' . self::NAMESPACE_SEPARATOR . 'business' . self::NAMESPACE_SEPARATOR . $tmpBusinessTarget;
     $fileClass = Location::realpathFromNamespace($tmpNSBusiness) . '.php';
     if (!is_file($fileClass)) {
         throw BusinessException::businessNotImplemented($tmpNSBusiness);
     }
     return BusinessAbstract::factory($tmpNSBusiness)->applicationRegister($this->_SIALApplication);
 }
Example #7
0
 /**
  * Registra o caminho dos scripts de view baseando-se no controller informado.
  *
  * @param br\gov\sial\core\mvcb\controller\ControllerAbstract $ctrl
  * @return br\gov\sial\core\mvcb\view\ViewAbstract
  * @example ViewAbstract::registerViewScriptBasedFromController
  * @code
  * <?php
  *      ...
  *      class FooController extends ControllerAbstract ()
  *      {
  *      }
  *      ...
  *      $fooController = new FooController();
  *      $this->registerViewScriptBasedFromController($fooController);
  * ?>
  * @encode
  * */
 public function registerViewScriptBasedFromController(ControllerAbstract $ctrl)
 {
     $scriptPath = current(explode('mvcb', $ctrl->getClassName())) . 'mvcb' . self::NAMESPACE_SEPARATOR . 'view' . self::NAMESPACE_SEPARATOR . 'scripts' . self::NAMESPACE_SEPARATOR . $this::T_TYPE;
     $this->addScriptPath(Location::realpathFromNamespace($scriptPath));
     return $this;
 }