Exemplo n.º 1
0
 protected function importClass($classname)
 {
     $fileName = Gpf::existsClass($classname);
     if (!$fileName) {
         echo "Class '{$classname}' was not found<br>";
         return;
     }
     $this->processClass($fileName, $classname);
 }
 private function renderPrivileges($className, $privilegeList, $privilegeTypes, $hasParentClass)
 {
     if ($fileName = Gpf::existsClass($className)) {
         $file = new Gpf_Io_File($fileName);
         $file->setFileMode('r');
         $content = $file->getContents();
         $file->close();
         if (($pos = strpos($content, self::TAG)) === false) {
             throw new Gpf_Exception('Missing tag ' . self::TAG . ' in privileges class ' . $className . ' !');
         }
         $file = new Gpf_Io_File($fileName);
         $file->open('w');
         $file->write(substr($content, 0, $pos + strlen(self::TAG)) . "\n\n");
         $file->write("\t// Privilege types\n");
         foreach ($privilegeTypes as $privilege) {
             $file->write("\t" . 'const ' . $this->formatPrivilegeType($privilege) . ' = "' . $privilege . '";' . "\n");
         }
         $file->write("\n");
         $file->write("\t// Privilege objects\n");
         foreach ($privilegeList as $object => $privileges) {
             ksort($privileges);
             $privilegeTypeComments = '// ';
             foreach ($privileges as $privilege) {
                 $privilegeTypeComments .= $this->formatPrivilegeType($privilege) . ', ';
             }
             $privilegeTypeComments = rtrim($privilegeTypeComments, ", ");
             $file->write("\t" . 'const ' . strtoupper($object) . ' = "' . $object . '"; ' . $privilegeTypeComments . "\n");
         }
         $file->write("\t\n\n\tprotected function initObjectRelation() {\n\t\t");
         if ($hasParentClass) {
             $file->write('$objectRelation = array_merge_recursive(parent::initObjectRelation(), array(');
         } else {
             $file->write('return array(');
         }
         $comma = "\n\t\t";
         foreach ($privilegeList as $object => $privileges) {
             $file->write($comma . "self::" . strtoupper($object) . "=>array(");
             ksort($privileges);
             $privilegeTypes = '';
             foreach ($privileges as $privilege) {
                 $privilegeTypes .= 'self::' . $this->formatPrivilegeType($privilege) . ', ';
             }
             $file->write(rtrim($privilegeTypes, ", ") . ")");
             $comma = ",\n\t\t";
         }
         $file->write("\n\t\t)" . ($hasParentClass ? ");\r\r\t\tforeach (\$objectRelation as \$key => \$value) {\r\t\t\t\$objectRelation[\$key] = array_unique(\$value);\r\t\t}\r\t\treturn \$objectRelation;" : ';') . "\r\t}\n");
         $file->write("\n}\n?>");
     }
 }
Exemplo n.º 3
0
 /**
  *
  * @param unknown_type $path
  * @return Gpf_Plugins_Definition
  */
 private function createPlugin($path)
 {
     $className = '';
     while (basename($path) != rtrim(Gpf_Paths::PLUGINS_DIR, '/') && basename($path) != 'include') {
         $className = basename($path) . '_' . $className;
         $path = dirname($path);
     }
     $className .= 'Definition';
     if (Gpf::existsClass($className) === false) {
         throw new Gpf_Exception("Plugin definition class is missing in directory '{$path}'");
     }
     return new $className();
 }
Exemplo n.º 4
0
 private function createWidget($className)
 {
     if (Gpf::existsClass($className)) {
         $class = new ReflectionClass($className);
         $widget = $class->newInstance(Gpf_Ui_Controller_Main::getController());
         return $widget;
     }
     throw new Gpf_Templates_NoWidget();
 }