Esempio n. 1
0
 /**
  * @param WikiLingo\Parsed $parsed
  */
 function __construct(WikiLingo\Parsed $parsed)
 {
     $this->parsed = $parsed;
     $type = $parsed->text;
     $parameters = $parsed->arguments[0]->text;
     if (!isset(self::$parametersParser)) {
         self::$parametersParser = new WikiLingo\Utilities\Parameters\Definition();
     }
     //From "{PLUGIN_NAME( " to "PLUGIN_NAME(", or from "{plugin_name " to "plugin_name"
     $type = substr(trim($type), 1);
     //From "PLUGIN_NAME(" to "PluginName", or from "{plugin_name " to "PluginName"
     if ($type[strlen($type) - 1] === "(") {
         $this->type = $type = self::typeShort(substr($type, 0, -1));
     } else {
         $this->type = $type = self::typeShort($type);
     }
     $this->classType = "WikiLingo\\Plugin\\{$type}";
     $this->exists = class_exists($this->classType);
     //if the plugin doesn't exist, lets see if it does in the customClasses attribute
     if (!$this->exists && isset(self::$customClasses[$type])) {
         if (!isset($parsed->parser->pluginInstances[$this->classType])) {
             $parsed->parser->pluginInstances[$this->classType] = self::$customClasses[$type];
         }
         $this->exists = true;
     }
     //it may exist elsewhere
     if (!$this->exists) {
         $parsed->parser->events->triggerExpressionPluginExists($this);
     }
     $this->index = self::incrementPluginIndex($type);
     $this->key = '§' . md5('plugin:' . $type . '_' . $this->index) . '§';
     $this->ignored = false;
     if ($this->exists == true) {
         if (empty($parsed->parser->pluginInstances[$this->classType])) {
             $parsed->parser->pluginInstances[$this->classType] = $class = new $this->classType($parsed->parser);
         }
         $this->class = $parsed->parser->pluginInstances[$this->classType];
         $this->isVariableContext = $this->class->isVariableContext;
         $this->parsed->expressionPermissible = $this->class->permissible;
         $this->allowLines = $this->class->allowLines;
         $this->allowWhiteSpace = $this->class->allowWhiteSpace;
         if ($parameters != '}') {
             if ($this->inLine) {
                 //{plugin ...}
                 $parameters = substr($parameters, 0, -1);
             } else {
                 //{PLUGIN(...)}
                 $parameters = substr($parameters, 0, -2);
             }
             if (!empty($parameters)) {
                 $this->parametersRaw = self::$parametersParser->parse($parameters);
             }
         }
         $this->parameters = $this->class->parameterValues($this->parametersRaw, $parsed->parser);
     }
 }