Пример #1
0
 function compile($options)
 {
     $this->initOutput();
     if (isset($options['pathTemplate'])) {
         $fileName = $options['pathTemplate'] . '/pageTypes/' . $options['pageType'];
         if (file_exists($fileName)) {
             $this->_fileName = $fileName;
         }
     }
     if (isset($options['mode'])) {
         $this->mode = $options['mode'];
     }
     $pageXml = org_glizy_ObjectFactory::createObject('org.glizy.parser.XML');
     if ($this->_fileName) {
         $pageXml->loadAndParseNS($this->_fileName);
     } else {
         throw new Exception('PageType not found ' . $options['pageType']);
     }
     $pageRootNode = $pageXml->documentElement;
     $registredNameSpaces = $pageXml->namespaces;
     $registredNameSpaces['glz'] = 'org.glizy.components';
     // $idPrefix 				= isset($options['idPrefix']) ? $options['idPrefix'] : '';
     $this->_path = $options['path'];
     // include i componenti usati
     foreach ($registredNameSpaces as $key => $value) {
         if ($key != 'glz' && substr($value, -1, 1) == '*' && !in_array($value, $this->_importedPaths)) {
             glz_loadLocale($value);
             $this->output .= 'glz_loadLocale(\'' . $value . '\')' . GLZ_COMPILER_NEWLINE;
             $this->_importedPaths[] = $value;
         }
     }
     $this->_className = glz_basename($this->_cacheObj->getFileName());
     $this->_classSource .= 'class ' . $this->_className . '{' . GLZ_COMPILER_NEWLINE2;
     $this->_classSource .= 'function ' . $this->_className . '(&$application, $skipImport=false, $idPrefix=\'\') {' . GLZ_COMPILER_NEWLINE2;
     $this->_classSource .= '$mode = "' . $this->mode . '"' . GLZ_COMPILER_NEWLINE;
     $counter = 0;
     $this->_compileXml($pageRootNode, $registredNameSpaces, $counter, '$application', '');
     $this->_classSource .= '}' . GLZ_COMPILER_NEWLINE2;
     $this->_classSource .= '}' . GLZ_COMPILER_NEWLINE2;
     $this->output .= $this->_classSource;
     $this->output .= $this->_customClassSource;
     return $this->save();
 }
Пример #2
0
 /**
  * @param $options
  *
  * @return mixed
  */
 function compile($options)
 {
     $this->initOutput();
     if (isset($options['mode'])) {
         $this->mode = $options['mode'];
     }
     $pageXml = org_glizy_ObjectFactory::createObject('org.glizy.parser.XML');
     $pageXml->loadAndParseNS($this->_fileName);
     $pageRootNode = $pageXml->documentElement;
     $registredNameSpaces = $pageXml->namespaces;
     $registredNameSpaces['glz'] = 'org.glizy.components';
     // include i componenti usati
     foreach ($registredNameSpaces as $key => $value) {
         if ($key != 'glz' && substr($value, -1, 1) == '*') {
             $this->output .= 'glz_loadLocale(\'' . $value . '\')' . GLZ_COMPILER_NEWLINE;
         }
     }
     $className = glz_basename($this->_cacheObj->getFileName());
     $componentClassInfo = $this->_getComponentClassInfo($pageRootNode->nodeName, $registredNameSpaces);
     //if (!empty($componentClassInfo['classPath']))
     //{
     //	$this->_classSource .= 'glz_import(\''.$componentClassInfo['classPath'].'\')'.GLZ_COMPILER_NEWLINE;
     //}
     $this->_classSource .= 'class ' . $className . ' extends ' . $componentClassInfo['className'] . ' {' . GLZ_COMPILER_NEWLINE2;
     $this->_classSource .= 'function ' . $className . '(&$application, &$parent, $tagName=\'\', $id=\'\', $originalId=\'\', $skipImport=false) {' . GLZ_COMPILER_NEWLINE2;
     if (isset($options['originalClassName'])) {
         $this->_classSource .= '$this->_className = \'' . $options['originalClassName'] . '\'' . GLZ_COMPILER_NEWLINE;
     }
     $this->_classSource .= 'parent::__construct($application, $parent, $tagName, $id, $originalId)' . GLZ_COMPILER_NEWLINE;
     $this->_classSource .= '$mode = ""' . GLZ_COMPILER_NEWLINE;
     $this->_classSource .= '$idPrefix = ""' . GLZ_COMPILER_NEWLINE;
     $this->_classSource .= '$n0 = &$this' . GLZ_COMPILER_NEWLINE;
     $this->_classSource .= 'if (!empty($id)) $id .= \'-\'' . GLZ_COMPILER_NEWLINE;
     $this->_classSource .= 'if (!empty($originalId)) $originalId .= \'-\'' . GLZ_COMPILER_NEWLINE;
     if (count($pageRootNode->attributes)) {
         // compila  gli attributi
         $this->_classSource .= '$attributes = array(';
         foreach ($pageRootNode->attributes as $index => $attr) {
             if ($attr->name != 'id') {
                 // NOTA: su alcune versioni di PHP (es 5.1)  empty( $attr->prefix ) non viene valutato in modo corretto
                 $prefix = $attr->prefix == "" || is_null($attr->prefix) ? "" : $attr->prefix . ":";
                 $this->_classSource .= '\'' . $prefix . $attr->name . '\' => \'' . addslashes($attr->value) . '\', ';
             }
         }
         $this->_classSource .= ')' . GLZ_COMPILER_NEWLINE;
         $this->_classSource .= '$this->setAttributes( $attributes )' . GLZ_COMPILER_NEWLINE;
     }
     $counter = 0;
     $oldcounter = $counter;
     foreach ($pageRootNode->childNodes as $nc) {
         $counter++;
         $this->_compileXml($nc, $registredNameSpaces, $counter, '$n' . $oldcounter, '$id.', '$originalId.');
     }
     if (isset($options['originalClassName']) && $pageRootNode->hasAttribute('allowModulesSnippets') && $pageRootNode->getAttribute('allowModulesSnippets') == "true") {
         $modulesState = org_glizy_Modules::getModulesState();
         $modules = org_glizy_Modules::getModules();
         foreach ($modules as $m) {
             $isEnabled = !isset($modulesState[$m->id]) || $modulesState[$m->id];
             if ($isEnabled && $m->pluginInPageType && $m->pluginSnippet) {
                 $counter++;
                 $this->compile_glzinclude($m->pluginSnippet, $registredNameSpaces, $counter, '$n' . $oldcounter, '$id.');
             }
         }
     }
     $this->_classSource .= '}' . GLZ_COMPILER_NEWLINE2;
     $this->_classSource .= '}' . GLZ_COMPILER_NEWLINE2;
     $this->output .= $this->_classSource;
     $this->output .= $this->_customClassSource;
     return $this->save();
 }
Пример #3
0
    function compile($options)
    {
        if (!file_exists($this->_fileName)) {
            throw org_glizy_compilers_CompilerException::fileNotFound($this->_fileName);
        }
        $this->initOutput();
        $xml = org_glizy_ObjectFactory::createObject('org.glizy.parser.XML');
        $xml->loadAndParseNS($this->_fileName);
        $xmlRootNode = $xml->documentElement;
        $className = glz_basename($this->_cacheObj->getFileName());
        $tableName = $xmlRootNode->getAttribute('model:tableName');
        if (empty($tableName)) {
            throw org_glizy_compilers_ModelException::missingTableName($this->_fileName);
        }
        $joinFields = $xmlRootNode->hasAttribute('model:joinFields') ? explode(',', $xmlRootNode->getAttribute('model:joinFields')) : null;
        $modelType = $xmlRootNode->hasAttribute('model:type') ? $xmlRootNode->getAttribute('model:type') : 'activeRecord';
        $dbConnection = $xmlRootNode->hasAttribute('model:connection') ? $dbConnection = $xmlRootNode->getAttribute('model:connection') : '0';
        $usePrefix = $xmlRootNode->hasAttribute('model:usePrefix') && $xmlRootNode->getAttribute('model:usePrefix') == 'true' ? 'true' : 'false';
        $languageField = $xmlRootNode->hasAttribute('model:languageField') ? '$this->setLanguageField(\'' . $xmlRootNode->getAttribute('model:languageField') . '\');' : '';
        $siteField = $xmlRootNode->hasAttribute('model:siteField') ? '$this->setSiteField(\'' . $xmlRootNode->getAttribute('model:siteField') . '\');' : '';
        $originalClassName = isset($options['originalClassName']) ? '$this->_className = \'' . $options['originalClassName'] . '\';' : '';
        if ($modelType == '2tables') {
            list($tableName, $detailTableName) = explode(',', $tableName);
        }
        $baseclassName = $this->resolveBaseClass($modelType);
        $fields = $this->compileFields($xmlRootNode);
        $queries = $this->compileQueries($xmlRootNode);
        $script = $this->compileScript($xmlRootNode);
        if ($baseclassName['type'] == 'activeRecord') {
            $compiledOutput = <<<EOD
class {$className} extends {$baseclassName['activeRecord']}
{
    function __construct(\$connectionNumber={$dbConnection}) {
        parent::__construct(\$connectionNumber);
        {$originalClassName}
        \$this->setTableName('{$tableName}',
                {$usePrefix} ? org_glizy_dataAccessDoctrine_DataAccess::getTablePrefix(\$connectionNumber) : '' );

        \$sm = new org_glizy_dataAccessDoctrine_SchemaManager(\$this->connection);
        \$fields = \$sm->getFields(\$this->getTableName());

        foreach (\$fields as \$field) {
            \$this->addField(\$field);
        }

        {$fields}

        if (__Config::get('MULTISITE_ENABLED')) {
            {$siteField}
        }
    }

    public function createRecordIterator() {
        return new {$className}_iterator(\$this);
    }

    {$script['model']}
    {$queries}
}
class {$className}_iterator extends {$baseclassName['recordIterator']}
{
    {$script['iterator']}
}
EOD;
        } elseif ($baseclassName['type'] == '2tables') {
            $compiledOutput = <<<EOD
class {$className} extends {$baseclassName['activeRecord']}
{
    function __construct(\$connectionNumber={$dbConnection}) {
        parent::__construct(\$connectionNumber);
        \$this->setTableName('{$tableName}',
                {$usePrefix} ? org_glizy_dataAccessDoctrine_DataAccess::getTablePrefix(\$connectionNumber) : '' );

        \$this->setDetailTableName('{$detailTableName}',
                {$usePrefix} ? org_glizy_dataAccessDoctrine_DataAccess::getTablePrefix(\$connectionNumber) : '' );

        \$this->setJoinFields('{$joinFields['0']}', '{$joinFields['1']}');

        \$sm = new org_glizy_dataAccessDoctrine_SchemaManager(\$this->connection);
        \$fields = \$sm->getFields(\$this->getTableName());

        foreach (\$fields as \$field) {
            \$this->addField(\$field);
        }

        \$fields = \$sm->getFields(\$this->getDetailTableName());

        foreach (\$fields as \$field) {
            \$this->addField(\$field, true);
        }

        {$fields}

        {$languageField}

        if (__Config::get('MULTISITE_ENABLED')) {
            {$siteField}
        }
    }

    public function createRecordIterator() {
        return new {$className}_iterator(\$this);
    }

    {$script['model']}
    {$queries}
}
class {$className}_iterator extends {$baseclassName['recordIterator']}
{
    {$script['iterator']}
}
EOD;
        } else {
            $compiledOutput = <<<EOD
class {$className} extends {$baseclassName['activeRecord']}
{
    function __construct(\$connectionNumber={$dbConnection}) {
        parent::__construct(\$connectionNumber);
        {$originalClassName}
        \$this->setTableName('{$tableName}',
                {$usePrefix} ? org_glizy_dataAccessDoctrine_DataAccess::getTablePrefix(\$connectionNumber) : '' );
        \$this->setType('{$tableName}');

        {$fields}
    }

    public function createRecordIterator() {
        return new {$className}_iterator(\$this);
    }

    {$script['model']}
    {$queries}
}
class {$className}_iterator extends {$baseclassName['recordIterator']}
{
    {$script['iterator']}
}
EOD;
        }
        $this->output .= $compiledOutput;
        return $this->save();
    }
Пример #4
0
 /**
  * @param org_glizy_application_Application $application
  * @param string $pageType
  * @param string $path
  * @param array $options
  *
  * @return mixed
  */
 static function &createPage(&$application, $pageType, $path = NULL, $options = NULL)
 {
     $pageType = org_glizy_ObjectFactory::resolvePageType($pageType);
     $options['pageType'] = $pageType . '.xml';
     $options['path'] = is_null($path) ? org_glizy_Paths::getRealPath('APPLICATION_PAGE_TYPE') : $path;
     $fileName = $options['path'] . $options['pageType'];
     if (isset($options['pathTemplate']) && isset($options['mode'])) {
         $verifyFileName = $options['pathTemplate'] . '/pageTypes/' . $options['pageType'];
         if (file_exists($verifyFileName)) {
             $options['verifyFileName'] = $verifyFileName;
         }
     }
     if (!file_exists($fileName)) {
         $fileName = glz_findClassPath($pageType);
         if (is_null($fileName)) {
             // TODO: file non trovato visualizzare errore
         }
     }
     // TODO
     // controllare l'esistenza del file
     $compiler = org_glizy_ObjectFactory::createObject('org.glizy.compilers.PageType');
     $compiledFileName = $compiler->verify($fileName, $options);
     // TODO verificare se la pagina è stata compilata
     require_once $compiledFileName;
     $idPrefix = isset($options['idPrefix']) ? $options['idPrefix'] : '';
     $className = glz_basename($compiledFileName);
     $newObj = new $className($application, isset($options['skipImport']) ? $options['skipImport'] : false, $idPrefix);
     return $newObj;
 }