Beispiel #1
0
 public static function loopTemplate($moduleName, $templateName, $rows = array())
 {
     $templateText = Locator::getInstance()->getTemplate($moduleName, $templateName);
     return count($rows) > 0 ? Processor::loopText($templateText, $rows) : '';
 }
Beispiel #2
0
<?php

require_once "vendor/autoload.php";
use Kasha\Templar\TextProcessor;
use Kasha\Templar\Locator;
// this should be handled while framework bootstraps
$folders = array('app' => __DIR__ . '/app/', 'shared' => __DIR__ . '/shared/');
Locator::getInstance()->setFolders($folders);
Locator::getInstance()->setLanguage('en');
$params = array('name' => array('first' => 'John', 'last' => 'Doe'));
// to run the test, create a file app/modules/main/templates/index.html
//  and use {{name.first}} and {{name.last|uppercase}} placeholders in its HTML
print TextProcessor::doTemplate('main', 'index', $params) . PHP_EOL;
Beispiel #3
0
 /**
  * Checks if given action exists and is accessible
  *
  * @param string $fullAction
  *
  * @return boolean
  */
 public function checkAction($fullAction)
 {
     $config = Config::getInstance();
     $fileName = '';
     list($module, $action) = explode('/', trim($fullAction), 2);
     $this->moduleName = $module;
     $this->actionName = $action;
     $this->isSharedModule = false;
     if ($module != '' && $action != '') {
         $appFolder = $config->getFolderPath('app');
         $sharedFolder = $config->getFolderPath('shared');
         $fileName = Locator::getAppModuleFilePath($module, "actions/{$action}.php");
         if (!file_exists($fileName)) {
             // module is not defined for the application => search shared space
             $fileName = Locator::getSharedModuleFilePath($module, "actions/{$action}.php");
             if (file_exists($fileName)) {
                 $this->isSharedModule = true;
             } else {
                 $fileName = '';
             }
             $this->addWarning("Did not find the file for action {$fullAction}");
         }
         // Check unauthorized requests
         if (!$this->checkAuthorization($module, $action)) {
             $this->addWarning("Authorization check failed for action {$fullAction}");
             $fileName = '';
         }
     } else {
         $this->addWarning("Malformed action {$fullAction}");
     }
     return $fileName == '' ? false : $fileName;
 }
Beispiel #4
0
 /**
  * Returns result of select query in one of supported format
  *
  * @param array $searchParameters
  * @param array $options
  *
  * @return array
  */
 public function select($searchParameters = array(), $options = array())
 {
     $format = Util::lavnn('format', $options, 'array');
     $sorting = Util::lavnn('sort', $options, '');
     $sqlFileName = get_class($this) . '_Search';
     if (Locator::moduleFileExists($this->moduleName, "sql/{$sqlFileName}.sql")) {
         // We can override default search behaviour with custom SQL
         $query = TextProcessor::doSqlTemplate($this->moduleName, $sqlFileName, $searchParameters);
     } else {
         $where = $this->prepareWhere($searchParameters, $this->getMetadata(), __METHOD__);
         $sqlParams = array('tableName' => $this->tableName, 'whereClause' => count($where) ? 'WHERE ' . join(' AND ', $where) : '', 'orderClause' => $sorting != '' ? 'ORDER BY ' . $sorting : '');
         $query = TextProcessor::doText(file_get_contents(__DIR__ . "/Templates/Search.sql"), $sqlParams);
     }
     return $this->selectByQuery($query, $format);
 }