public function printUseNameSpaceIfNeeded(Printer $printer)
 {
     if (Helper::isPearStyle($this->descriptor)) {
         // nothing to do.
     } else {
         if ($this->hasNameSpace()) {
             if ($this->enclose_namespace_) {
                 $printer->put("namespace `namespace`\n{\n\n", "namespace", $this->getNameSpace());
             } else {
                 $printer->put("namespace `namespace`;\n\n", "namespace", $this->getNameSpace());
             }
         } else {
             if ($this->enclose_namespace_) {
                 $printer->put("namespace {\n\n");
             }
         }
         //  NOTE: We don't use `use` statement here. it's troublesome.
         $printer->put("// @@protoc_insertion_point(namespace:`name`)\n", "name", $this->descriptor->full_name);
         $printer->put("\n");
     }
 }
Beispiel #2
0
 public function generateAutoloader(Printer $printer, $file_list, $append_mode = false)
 {
     if (!$append_mode) {
         $printer->put("<?php\n");
         $printer->put("spl_autoload_register(function(\$name){\n");
         $printer->indent();
         $printer->put("static \$classmap;\n");
         $printer->put("if (!\$classmap) {\n");
         $printer->indent();
         $printer->put("\$classmap = array(\n");
         $printer->indent();
     }
     foreach ($file_list as $file) {
         $tmp = str_replace("\\", DIRECTORY_SEPARATOR, $file);
         $key = str_replace(DIRECTORY_SEPARATOR, "\\", substr($file, 0, strrpos($file, ".")));
         if (Helper::isPearStyle($this->file)) {
             $printer->put("'`key`' => '`path`',\n", "key", str_replace("\\", "_", ltrim($key, "\\")), "path", DIRECTORY_SEPARATOR . ltrim($tmp, DIRECTORY_SEPARATOR));
         } else {
             $printer->put("'`key`' => '`path`',\n", "key", ltrim($key, "\\"), "path", DIRECTORY_SEPARATOR . ltrim($tmp, DIRECTORY_SEPARATOR));
         }
     }
     if (!$append_mode) {
         $printer->put("// @@protoc_insertion_point(autoloader_scope:classmap)\n");
         $printer->outdent();
         $printer->put(");\n");
         $printer->outdent();
         $printer->put("}\n");
         $printer->put("if (isset(\$classmap[\$name])) {\n");
         $printer->indent();
         $printer->put("require __DIR__ . DIRECTORY_SEPARATOR . \$classmap[\$name];\n");
         $printer->outdent();
         $printer->put("}\n");
         $printer->outdent();
         $printer->put("});\n");
         $printer->put("\n");
         $printer->put("call_user_func(function(){\n");
         $printer->indent();
         $printer->put("\$registry = `class`::getInstance();\n", "class", Helper::getExtensionRegistryClassName($this->file));
         $printer->put("// @@protoc_insertion_point(extension_scope:registry)\n");
         $printer->outdent();
         $printer->put("});\n");
     }
 }