protected function log(\Exception $e, $contextInfo = NULL) { if ($e instanceof \ErrorException) { $errorType = self::$errors[$e->getSeverity()]; } else { $errorType = Code::getClass($e); } // wir müssen hier den error selbst loggen, da php nichts mehr macht (die faule banane) $php = NULL; $php .= 'PHP ' . $errorType . ': ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . "\n"; $php .= $errorType . ': ' . \Psc\Exception::getExceptionText($e, 'text') . "\n"; error_log($php, 0); /* Debug-Mail */ $debug = NULL; $debug .= '[' . date('d.M.Y H:i:s') . "] "; $debug .= $errorType . ': ' . \Psc\Exception::getExceptionText($e, 'text') . "\n"; if ($e instanceof \Psc\Code\ErrorException) { $debug .= "\n" . $e->contextDump; } if (isset($contextInfo)) { $debug .= "\nContextInfo: \n" . $contextInfo; } if (isset($this->recipient) && !PSC::inTests()) { if ($ret = @mail($this->recipient, '[Psc-ErrorHandler] [' . $e->getCode() . '] ' . $e->getMessage(), $debug, 'From: www@' . PSC::getEnvironment()->getHostName() . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n") === FALSE) { error_log('[\\Psc\\Code\\ErrorHandler.php:' . __LINE__ . '] Die Fehlerinformationen konnten nicht an den lokalen Mailer übergeben werden.', 0); } } }
/** * Ruft den Getter für das Feld $field auf dem Entity auf * * @param string $field der Name des Feldes in CamelCase * @return mixed */ public function callGetter($field) { $f = 'get' . ucfirst($field); if (!method_exists($this, $f)) { throw new \InvalidArgumentException($f . '() existiert nicht in ' . \Psc\Code\Code::getClass($this)); } return $this->{$f}(); }
public function assertRoutingException(Closure $c, $debugMessage = '') { try { $c(); } catch (\Exception $e) { if ($e instanceof \Psc\CMS\Service\ControllerRouteException || $e instanceof \Psc\Net\HTTP\HTTPException || $e instanceof \Psc\Net\RequestMatchingException) { return; } else { $this->fail('Exception: Psc\\CMS\\Service\\ControllerRouteException oder Psc\\Net\\RequestMatchingException erwartet. Es wurde aber ' . \Psc\Code\Code::getClass($e) . ' gecatched. (ExceptionMessage: ' . $e->getMessage() . ') ' . $debugMessage); } } $this->fail('Exception: Psc\\CMS\\Service\\ControllerRouteException oder Psc\\Net\\RequestMatchingException erwartet. Es wurde aber keine gecatched. ' . $debugMessage); }
protected function doInit() { // damit die components der form innerhalb des formpanels an der richtigen stelle stehen // holen wir uns diese aus der Componentsform foreach ($this->form->getComponents() as $key => $component) { try { $this->content['component' . $key] = $component->html(); } catch (\Psc\Exception $e) { throw new \Psc\Exception('Component ' . Code::getClass($component) . ' verursachte einen Fehler beim HTML-Erzeugen', 0, $e); } } parent::doInit(); }
public function testAfterLogoutValidateIsNotOkay() { // pre: validate does not throw exception $this->auth->login($this->id, $this->pw); $this->expectUserInDB(); $this->auth->validate(); // now logout $this->auth->logout(); try { $this->auth->validate(); $this->fail('validate sollte eine exception schmeissen, da der User ausgeloggt ist'); } catch (NoAuthException $e) { return; } $this->fail('Falsche Exception Gecatched: ' . \Psc\Code\Code::getClass($e)); }
/** * @param PscAnnotation|DoctrineAnnotation $annotation */ public function getAnnotationName($annotation) { if ($annotation instanceof PscAnnotation) { $name = $annotation->getAnnotationName(); } else { $name = \Psc\Code\Code::getClass($annotation); } if (isset($this->defaultAnnotationNamespace) && mb_strpos($name, $this->defaultAnnotationNamespace) === 0) { return mb_substr($name, mb_strlen($this->defaultAnnotationNamespace) + 1); } foreach ($this->annotationNamespaceAliases as $alias => $namespace) { if (mb_strpos($name, $namespace) === 0) { return $alias . '\\' . mb_substr($name, mb_strlen($namespace) + 1); } } return '\\' . $name; }
protected function walk($ast) { if (is_object($ast)) { $this->stack[] = Code::getClass($ast); } /* es muss nach der "spezialität" von Klassen sortiert werden die Klassen am tiefsten in der Hierarchie müssen nach oben gleichzeitig ist die Schleife auch Performance-Kritisch */ if ($ast instanceof \Psc\HTML\Page) { return $this->walkPage($ast); } elseif ($ast instanceof \Bugatti\Templates\LanguagePicker) { return $this->walkLanguagePicker($ast); } elseif ($ast instanceof \Bugatti\Templates\Headline) { return $this->walkHeadline($ast); } elseif ($ast instanceof \Bugatti\Templates\NavigationLevel) { return $this->walkNavigationLevel($ast); } elseif ($ast instanceof \Bugatti\Templates\Section) { return $this->walkContainer($ast); } elseif ($ast instanceof \Bugatti\Templates\Container) { return $this->walkContainer($ast); } elseif ($ast instanceof \Psc\Data\ArrayCollection) { return $this->walkCollection($ast); } elseif ($ast instanceof \Bugatti\Templates\LayoutTable) { return $this->walkLayoutTable($ast); } elseif ($ast instanceof \Bugatti\Templates\ContentTable) { return $this->walkContentTable($ast); } if (is_string($ast)) { return $ast; } if (is_int($ast)) { return $ast; } if (is_array($ast)) { return $ast; } var_dump($this->stack); throw new ASTException('kann mit dem Part: ' . Code::varInfo($ast) . ' nichts anfangen'); }
public function compile() { $gClass = new \Psc\Code\Generate\GClass(\Psc\Code\Code::getClass($this)); $gClass->elevateClass(); $this->log('compiling ProjectEntities:'); foreach ($gClass->getMethods() as $method) { if (\Psc\Preg::match($method->getName(), '/^compile[a-z0-9A-Z_]+$/') && $method->isPublic()) { $this->modelCompiler = NULL; // neuen erzeugen damit flags resetted werden, etc $m = $method->getName(); $this->log(' ' . $m . ':'); try { $out = $this->{$m}($this->getModelCompiler()); } catch (\Doctrine\DBAL\DBALException $e) { if (mb_strpos($e->getMessage(), 'Unknown column type') !== FALSE) { $types = A::implode(\Doctrine\DBAL\Types\Type::getTypesMap(), "\n", function ($fqn, $type) { return $type . "\t\t" . ': ' . $fqn; }); throw new \Psc\Exception('Database Error: Unknown Column Type: types are: ' . "\n" . $types, $e->getCode(), $e); } throw $e; } catch (\Exception $e) { $this->log(' Fehler beim Aufruf von ' . $m); throw $e; } if ($out instanceof \Webforge\Common\System\File) { $this->log(' ' . $out . ' geschrieben'); } elseif (is_array($out)) { foreach ($out as $file) { $this->log(' ' . $file . ' geschrieben'); } } elseif ($out instanceof \Psc\Doctrine\EntityBuilder) { $this->log(' ' . $out->getWrittenFile() . ' geschrieben'); } } } $this->log('finished.'); return $this; }
public function decorateWalkable($walkable, $walkedFields) { return '@' . Code::getClass($walkable) . '(' . implode(', ', $walkedFields) . ')'; }
/** * @cc-ignore */ public function __toString() { return '[class ' . Code::getClass($this) . ' not converted to string]'; }
/** * Sucht den ersten der Services, der den Request bearbeiten will * * @throws NoServiceFoundException */ public function findService(ServiceRequest $serviceRequest) { $this->log('Find Services..'); foreach ($this->services as $service) { $this->log('Service: ' . Code::getClass($service) . '::isResponsibleFor'); if ($service->isResponsibleFor($serviceRequest)) { $this->log('ok: Service übernimmt den Request'); return $service; } } throw NoServiceFoundException::build('Es konnte kein passender Service ermittelt werden. Es wurden %d Services (%s) befragt.', count($this->services), \Webforge\Common\ArrayUtil::implode($this->services, ', ', function ($svc) { return Code::getClass($svc); }))->set('serviceRequest', $serviceRequest)->end(); }
/** * Gibt den FQN des Entities zurück * * dies kann man zur Performance überschreiben * @return string */ public function getEntityName() { return \Psc\Code\Code::getClass($this); }
public function registerCacheAdapter(CacheAdapter $adapter, $name = NULL) { if (!isset($name)) { $name = Code::getClassName(Code::getClass($adapter)); } $this->registeredCacheAdapters[$name] = $adapter; return $this; }
public function getRepositoryMock(\Psc\Code\Test\Base $testCase, $entityName, array $methods = NULL) { $realRepository = $this->getRepository($entityName); $class = Code::getClass($realRepository); return $testCase->getMock($class, $methods, array($this, $this->getClassMetadata($entityName))); }
public function deploy() { $this->init(); $this->logf('Starting Deployment [%s%s] to %s', $this->project->getName(), $this->variant ? '.' . $this->variant : NULL, $this->target); foreach ($this->tasks as $task) { try { $label = $task instanceof LabelTask ? $task->getLabel() : Code::getClassName(Code::getClass($task)); $this->logf('** Task: %s', $label); $task->run(); } catch (\Webforge\Common\Exception\MessageException $e) { $e->prependMessage('ERROR in task ' . $label . '. '); throw $e; } } $this->logf('finished Deployment [%s%s]', $this->project->getName(), $this->variant ? '.' . $this->variant : NULL); }
/** * Gibt den Namen der Componente zurück * * also TextField oder EmailPicker oder ComboBox oder ComboDropBox usw */ public function getComponentName() { return Code::getClassName(Code::getClass($this)); }
/** * Gibt für alle Methoden der Klasse eine Closure zurück * * extract($dsl->getClosures()); * * - $parameter defined * - $type defined * - ... usw * * @return array (für extract geeignet) */ public function getClosures() { if (!isset($this->closures)) { $cc = new ClosureCompiler(); list($closureCode, $methods) = $cc->compile(new GClass(\Psc\Code\Code::getClass($this))); unset($methods[array_search('getClosures', $methods)]); $that = $this; eval($closureCode); $this->closures = compact($methods); } return $this->closures; }
public function getAnnotationName() { return Code::getClass($this); }
public function walkElement(Element $element, $context = NULL) { if ($element instanceof LStatement) { return $this->walkStatement($element); } elseif ($element instanceof LExpression) { return $this->walkExpression($element, $context); } elseif ($element instanceof LProgram) { return $this->walkProgram($element); } else { throw new \RuntimeException('Element: ' . Code::getClass($element) . ' hat keinen Walk definiert in walkElement'); } }
/** * Synchronisiert eine Collection eines Entities mit Entities in der Datenbank (deprecated) * * Diese Art der Synchroniserung ist deprecated, weil es mittlerweile ausgelagerte Funktionen dafür gibt * (siehe Psc\Doctrine\*Synchro*) * * also es werden für die bestehenden Objekte in $entity->$collectionProperty die objekte gelöscht * die nicht in newCollection drin sind und die, die in $newCollection drin sind aber nicht in * $entity->$collectionProperty gelöscht * * - Achtung(!): dies führt persist() auf den Entitys der Collection (also quasi andere Seite der Association) aus, wenn $this->entity nicht die Owning-Side der CollectionAssociation ist * - Dies führt persist für items in newCollection, die neu sind * * Die Basis für eine erfolgreiche Synchronization ist eine $newCollection die wirklich die gleichen Objekte enthält, für die Updates gemacht werden sollen. Also vorsicht mit serialisierten Einträgen und clones * * @param string $associationName der Name des Properties der Collection in $entity */ public function synchronizeCollection($associationName, $newCollection) { if (!is_string($associationName)) { throw new \Psc\Exception('string erwartet: ' . Code::varInfo($associationName)); } /* $mapping = $coll->getMapping(); $targetClass = $this->_em->getClassMetadata($mapping['targetEntity']); $sourceClass = $this->_em->getClassMetadata($mapping['sourceEntity']); $id = $this->_em->getUnitOfWork()->getEntityIdentifier($coll->getOwner()); */ if ($this->entity instanceof \Psc\Doctrine\Object) { $entityClass = $this->entity->getDoctrineMetadata(); // Sound } elseif ($this->entity instanceof \Psc\Doctrine\Entity) { $entityClass = $this->em->getClassMetadata($this->entity->getEntityName()); } else { throw new \InvalidArgumentException('$this->entity ist von der Klasse: ' . Code::getClass($this->entity) . ' und diese ist unbekannt'); } $entityAssoc = $entityClass->getAssociationMapping($associationName); // speakers $owning = $entityAssoc['isOwningSide']; // true $targetClass = $this->em->getClassMetadata($entityAssoc['targetEntity']); // Metadata:Speaker if ($owning) { $entityProperty = $entityAssoc['inversedBy']; $collectionProperty = $entityAssoc['fieldName']; } else { $entityProperty = $entityAssoc['mappedBy']; $collectionProperty = $entityAssoc['fieldName']; } // entityProperty = sounds // collectionProperty = speakers $getter = Code::castGetter($collectionProperty); //getSpeakers $collection = $getter($this->entity); // $this->entity->getSpeakers() $collection = Code::castCollection($collection); $newCollection = Code::castCollection($newCollection); $this->log(sprintf("synchronizeCollection '%s'", $associationName)); $this->log('in DBCollection:'); $this->log(DoctrineHelper::debugCollection($collection)); $this->log(NULL); $this->log('in FormCollection:'); $this->log(DoctrineHelper::debugCollection($newCollection)); $this->log(NULL); $this->log('Processing:'); /* Wir synchronisieren hier auf der Owning Side oder Reverse Side jenachdem müssen wir auf der owning oder reverse side die add + remove funktionen aufrufen */ if ($owning) { $remove = 'remove' . ucfirst(Inflector::singular($collectionProperty)); // removeSpeaker $add = 'add' . ucfirst(Inflector::singular($collectionProperty)); // addSpeaker } else { $remove = 'remove' . ucfirst(Inflector::singular($entityProperty)); // removeSound $add = 'add' . ucfirst(Inflector::singular($entityProperty)); // addSound } $logThis = Code::getClassName($entityClass->getName()); // @TODO hier mit reflection prüfen //if (!->hasMethod($remove)) { // throw new \Psc\Exception('Es gibt keine '.$remove.' Methode im Entity: '.$owningEntity); //} //if (!$this->entity->hasMethod($add)) { // throw new \Psc\Exception('Es gibt keine '.$add.' Methode im Entity: '.$owningEntity); //} // foreach ($collection->deleteDiff($newCollection, ArrayCollection::COMPARE_OBJECTS) as $entity) { if ($owning) { $this->entity->{$remove}($entity); // $sound->removeSpeaker($speaker) } else { $this->em->persist($entity); // $speaker persist $entity->{$remove}($this->entity); // $speaker->removeSound($sound) } } foreach ($collection->insertDiff($newCollection, ArrayCollection::COMPARE_OBJECTS) as $entity) { if ($owning) { $this->entity->{$add}($entity); $this->em->persist($entity); } else { $entity->{$add}($this->entity); $this->em->persist($entity); } } }
/** * FEHLER: Ein Parameter oder eine Subresource einer Methode ist nicht korrekt gewesen * * die Syntax des Requests ist falsch * @param string $method * @param string $argument */ public function invalidArgument($method, $argumentName, $argumentValue, $msg = '') { return HTTPException::BadRequest('Falscher Parameter ' . Code::varInfo($argumentValue) . ' für ' . $method . '( :$' . $argumentName . " )\n" . $msg . ' in Controller: ' . Code::getClass($this->controller)); }
protected function handleException(\Exception $exception) { /* Check Exception Listeners diese können z. B. eine Doctrine\UniqueConstraintException in eine ValidatorException umwandeln */ $exceptionClass = Code::getClass($exception); if (array_key_exists($exceptionClass, $this->exceptionListeners)) { foreach ($this->exceptionListeners[$exceptionClass] as $listener) { if (($listenerException = $listener->listenException($exception)) != NULL) { $exception = $listenerException; } } } // wir geben zurück an den RequestHandler throw $exception; }