protected function processErrors() { $errors = libxml_get_errors(); if (count($errors) == 0) { $this->rollback(); throw new LoadingException('Fehler beim Laden des XMLS, es konnten aber keine Fehlerinformationen ermittelt werden.'); } $cnt = count($errors); if ($cnt == 1) { $msg = 'Beim Laden des XMLs ist ein Fehler aufgetreten: '; } else { $msg = sprintf('Beim Laden des XMLs sind %d Fehler aufgetreten: ', $cnt); } $that = $this; $e = new LoadingException($msg . "\n" . \Webforge\Common\ArrayUtil::joinc($errors, "\n %s\n\n", function ($error) use($that) { return $that->errorToString($error); })); $e->libxmlErrors = $errors; libxml_clear_errors(); $this->rollback(); throw $e; }
public function generatePHP(array $imports = array()) { if (!isset($this->gClass)) { throw new ClassWritingException('Klasse nicht gesetzt. (zuerst setClass() dann write().'); } $use = NULL; /* merge mit params */ foreach ($imports as $iClass) { $alias = NULL; if (is_array($iClass)) { list($iClass, $alias) = $iClass; } if (!$iClass instanceof GClass) { throw new \Psc\Exception('Imports können nur vom typ GClass sein'); } $this->addImport($iClass, $alias); } if (count($this->foundImports) > 0) { $useImports = array(); foreach ($this->foundImports as $alias => $gClass) { // wir filten nach den imports, die im selben Namespace sind und keinen besonderen Alias haben if ($alias !== $gClass->getClassName() || $gClass->getNamespace() !== $this->gClass->getNamespace()) { $useImports[$alias] = $gClass; } } /* Render PHP */ $classAlias = function ($gClass, $alias) { if ($alias === $gClass->getClassName()) { return $gClass->getFQN(); } else { return $gClass->getFQN() . ' AS ' . $alias; } }; if (count($useImports) > 0) { $use .= "\n"; // abstand zu namespace (neue Zeile) if ($this->useStyle === self::USE_STYLE_LINES) { $use .= A::joinc($useImports, "use %s;\n", $classAlias); } else { $use .= 'use ' . A::implode($useImports, ",\n ", $classAlias); $use .= ';'; $use .= "\n"; // abstand zu class (neue Zeile) } } } $php = TPL::miniTemplate($this->template, array('class' => $this->gClass->php(), 'use' => $use, 'namespace' => $this->gClass->getNamespace() != NULL ? 'namespace ' . ltrim($this->gClass->getNamespace(), '\\') . ';' : NULL)); return $php; }
protected function debugTokens(array $tokens) { return \Webforge\Common\ArrayUtil::joinc($tokens, ', ', function ($token) { return is_string($token) ? $token : j_token_name($token); }); }
/** * Gibt die Klasse als PHP Code zurück * * die Klasse ist noch nicht mit Namespace vor class notiert! * Eingerückt wird mit 2 whitespaces. * Em Ende befindet sich hinter der schließenden Klammer ein LF */ public function php() { $cr = "\n"; $php = $this->phpDocBlock(0); $ms = array(self::MODIFIER_ABSTRACT => 'abstract', self::MODIFIER_FINAL => 'final'); foreach ($ms as $const => $modifier) { if (($const & $this->modifiers) == $const) { $php .= $modifier . ' '; } } $php .= 'class ' . $this->getClassName() . ' '; /* Extends */ if (isset($this->parentClass)) { if ($this->parentClass->getNamespace() === $this->getNamespace()) { $php .= 'extends ' . $this->parentClass->getClassName() . ' '; // don't prefix namespace } else { $php .= 'extends ' . '\\' . $this->parentClass->getFQN() . ' '; } } /* Interfaces */ if (count($this->getInterfaces()) > 0) { $php .= 'implements '; $that = $this; $php .= A::implode($this->getInterfaces(), ', ', function (GClass $iClass) use($that) { if ($that->getNamespace() === $iClass->getNamespace()) { return $iClass->getClassName(); } else { return '\\' . $iClass->getFQN(); } }); $php .= ' '; } $php .= '{' . $cr; /* Die Funktionen machen immer den Abstand nach oben. Also vor jedem Property und jeder Methode macht dies ein "\n" */ /* Constants */ $php .= A::joinc($this->getConstants(), ' ' . $cr . '%s;' . $cr, function ($constant) { return $constant->php(2); }); /* Properties */ $php .= A::joinc($this->getProperties(), ' ' . $cr . '%s;' . $cr, function ($property) { return $property->php(2); // hier jetzt auch wegen DocBlock einrücken }); /* Methods */ $php .= A::joinc($this->getMethods(), ' ' . $cr . '%s' . $cr, function ($method) { return $method->php(2); // rückt selbst zwischen den Klammern ein, aber wir wollen ja den body z.b. auf 4 haben nicht auf 2 }); $php .= '}'; // kein umbruch hinten, immer abstand nach oben! return $php; }
public function debug() { return \Webforge\Common\ArrayUtil::joinc($this->values, '%2$s: %1$s' . "\n", function ($value) { if (is_array($value)) { return implode('; ', $value); } return $value; }); }