/** * @return Autoloader */ function setSlotId($slotId) { Assert::isScalar($slotId); Assert::isFalse($this->isInitialized, 'too late to set slotId: already initialized'); $this->slotId = $slotId; return $this; }
/** * @throws WrongArgumentException * @return Form **/ public function add(BasePrimitive $prm) { $name = $prm->getName(); Assert::isFalse(isset($this->primitives[$name]), 'i am already exists!'); $this->primitives[$name] = $prm; return $this; }
function __construct($key) { //TODO ClientRequest Assert::isFalse(headers_sent() || Response::isFinished(), 'Yup! Headers are already sent so the storage cannot work properly.'); ob_start(); $this->basekey = $key . Session::userSupertag(true); $this->key = $this->sign($key); }
/** * @throws WrongArgumentException * @return LogicalChain **/ public static function getOpenPoint($left, $right, $point) { Assert::isFalse($point === null, 'how can i build logic from emptyness?'); $point = new DBValue($point); $chain = new LogicalChain(); $chain->expOr(Expression::orBlock(Expression::andBlock(Expression::notNull($left), Expression::notNull($right), Expression::between($point, $left, $right)), Expression::andBlock(Expression::isNull($left), Expression::ltEq($point, $right)), Expression::andBlock(Expression::isNull($right), Expression::ltEq($left, $point)), Expression::andBlock(Expression::isNull($left), Expression::isNull($right)))); return $chain; }
function toHtml(array $htmlAttributes = array()) { Assert::isFalse(isset($htmlAttributes['name'])); Assert::isFalse(isset($htmlAttributes['multiple'])); $htmlAttributes['name'] = $this->getName() . '[]'; $htmlAttributes['multiple'] = 'multiple'; return HtmlUtil::getContainer('select', $htmlAttributes, join("", $this->getOptions())); }
/** * @throws WrongArgumentException * @return DBSchema **/ public function addTable(DBTable $table) { $name = $table->getName(); Assert::isFalse(isset($this->tables[$name]), "table '{$name}' already exist"); $this->tables[$table->getName()] = $table; $this->order[] = $name; return $this; }
/** * @throws WrongArgumentException * @return DBTable **/ public function addColumn(DBColumn $column) { $name = $column->getName(); Assert::isFalse(isset($this->columns[$name]), "column '{$name}' already exist"); $this->order[] = $this->columns[$name] = $column; $column->setTable($this); return $this; }
function finish() { Assert::isFalse($this->isFinished, 'already finished'); $this->isFinished = true; // http://php-fpm.anight.org/extra_features.html // TODO: cut out this functionality to the outer class descendant (e.g., PhpFpmResponse) if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } }
/** * @return ProjectionChain **/ public function add(ObjectProjection $projection, $name = null) { if ($name) { Assert::isFalse(isset($this->list[$name])); $this->list[$name] = $projection; } else { $this->list[] = $projection; } return $this; }
function toHtml(array $htmlAttributes = array()) { Assert::isFalse(isset($htmlAttributes['name'])); Assert::isFalse(isset($htmlAttributes['type'])); Assert::isFalse(isset($htmlAttributes['value'])); $htmlAttributes['name'] = $this->getName(); $htmlAttributes['type'] = $this->getType(); $htmlAttributes['value'] = $this->getValue(); return HtmlUtil::getNode('input', $htmlAttributes); }
/** * @throws BaseException * @return ModelAndView **/ public function run(Prototyped $subject, Form $form, HttpRequest $request) { Assert::isFalse($this->running, 'command already running'); Assert::isTrue($subject instanceof DAOConnected); $this->transaction = InnerTransaction::begin($subject->dao()); try { $mav = $this->command->run($subject, $form, $request); $this->running = true; return $mav; } catch (BaseException $e) { $this->transaction->rollback(); throw $e; } Assert::isUnreachable(); }
/** * Gets the inner controls * @return IFormControl[] */ function getControls() { $yield = array(); if ($this->isImported()) { foreach ($this->getImportedValue() as $value) { $control = $this->spawnControl(); $control->importValue($value); Assert::isFalse($control->hasError(), 'cannot import value `%s` into %s: caused error `%s` %s', $value, get_class($control), (string) $control->getError(), $control->getErrorMessage()); $yield[] = $control; } } else { foreach ($this->getDefaultValue() as $value) { $control = $this->spawnControl(); $control->setDefaultValue($value); $yield[] = $control; } } return $yield; }
function setEncoding($encoding) { parent::setEncoding($encoding); if ($this->isConnected()) { $result = pg_set_client_encoding($this->link, $encoding); Assert::isFalse($result == -1, 'invalid encoding `%s` is specified', $encoding); } return $this; }
/** * Prepends the Route to the chain * * @param string $name name of the Route to append * @param Route $route route object to append * * @return ChainedRouter itself */ function prependRoute($name, Route $route) { Assert::isScalar($name); Assert::isFalse(isset($this->routes[$name]), 'route `%s` already defined', $name); $this->routes[$name] = $route; array_unshift($this->chain, $route); return $this; }
function dropAll() { Assert::isFalse($this->isReadonly(), 'cannot drop readonly collections'); $query = EntityQuery::create($this->mtm->getProxy())->where(Expression::eq($this->mtm->getContainerProxyProperty(), $this->getParentObject())); $count = $query->delete(); $this->clean(); return $count; }
function toHtml(array $htmlAttributes = array()) { Assert::isFalse(isset($htmlAttributes['name'])); $htmlAttributes['name'] = $this->getName(); return HtmlUtil::getContainer('textarea', $htmlAttributes, htmlspecialchars($this->getValue())); }
/** * Signs the form. This method may be overridden to import fields to be signed, just call Form::setHiddenValue() * @return Form */ function sign(WebRequest $request) { Assert::isFalse($this->isSigned(), 'form already signed'); $this->privateValues['referrer'] = (string) $request->getHttpUrl(); $this->addControl(FormControl::hidden($this->getSignatureFieldName(), $this->exportSignature())); $this->signed = true; return $this; }
protected final function start() { Assert::isFalse($this->isStarted, 'response already started'); if ($this->status) { $protocol = $this->request ? $this->request->getProtocol() : 'HTTP/1.0'; header($protocol . ' ' . $this->status->getValue() . ' ' . $this->status->getStatusMessage(), true); } foreach ($this->headers as $name => $value) { header($name . ': ' . $value, true); } foreach ($this->cookies as $cookie) { setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpire(), $cookie->getPath()); } $this->isStarted = true; }
/** * @return MetaConfiguration **/ private function processClasses(SimpleXMLElement $xml, $metafile, $generate) { foreach ($xml->classes[0] as $xmlClass) { $name = (string) $xmlClass['name']; Assert::isFalse(isset($this->classes[$name]), 'class name collision found for ' . $name); $class = new MetaClass($name); if (isset($xmlClass['source'])) { $class->setSourceLink((string) $xmlClass['source']); } if (isset($xmlClass['table'])) { $class->setTableName((string) $xmlClass['table']); } if (isset($xmlClass['type'])) { $type = (string) $xmlClass['type']; if ($type == 'spooked') { $this->getOutput()->warning($class->getName(), true)->warningLine(': uses obsoleted "spooked" type.')->newLine(); } $class->setType(new MetaClassType((string) $xmlClass['type'])); } // lazy existence checking if (isset($xmlClass['extends'])) { $this->liaisons[$class->getName()] = (string) $xmlClass['extends']; } // populate implemented interfaces foreach ($xmlClass->implement as $xmlImplement) { $class->addInterface((string) $xmlImplement['interface']); } if (isset($xmlClass->properties[0]->identifier)) { $id = $xmlClass->properties[0]->identifier; if (!isset($id['name'])) { $name = 'id'; } else { $name = (string) $id['name']; } if (!isset($id['type'])) { $type = 'BigInteger'; } else { $type = (string) $id['type']; } $property = $this->makeProperty($name, $type, $class, (string) $id['size']); if (isset($id['column'])) { $property->setColumnName((string) $id['column']); } elseif ($property->getType() instanceof ObjectType && !$property->getType()->isGeneric()) { $property->setColumnName($property->getConvertedName() . '_id'); } else { $property->setColumnName($property->getConvertedName()); } $property->setIdentifier(true)->required(); $class->addProperty($property); unset($xmlClass->properties[0]->identifier); } $class->setPattern($this->guessPattern((string) $xmlClass->pattern['name'])); if ((string) $xmlClass->pattern['fetch'] == 'cascade') { $class->setFetchStrategy(FetchStrategy::cascade()); } if ($class->getPattern() instanceof InternalClassPattern) { Assert::isTrue($metafile === ONPHP_META_PATH . 'internal.xml', 'internal classes can be defined only in onPHP, sorry'); } elseif ($class->getPattern() instanceof SpookedClassPattern || $class->getPattern() instanceof SpookedEnumerationPattern) { $class->setType(new MetaClassType(MetaClassType::CLASS_SPOOKED)); } // populate properties foreach ($xmlClass->properties[0] as $xmlProperty) { $property = $this->makeProperty((string) $xmlProperty['name'], (string) $xmlProperty['type'], $class, (string) $xmlProperty['size']); if (isset($xmlProperty['column'])) { $property->setColumnName((string) $xmlProperty['column']); } elseif ($property->getType() instanceof ObjectType && !$property->getType()->isGeneric()) { if (isset($this->classes[$property->getType()->getClassName()]) && $property->getType()->getClass()->getPattern() instanceof InternalClassPattern) { throw new UnimplementedFeatureException('you can not use internal classes directly atm'); } $property->setColumnName($property->getConvertedName() . '_id'); } else { $property->setColumnName($property->getConvertedName()); } if ((string) $xmlProperty['required'] == 'true') { $property->required(); } if (isset($xmlProperty['identifier'])) { throw new WrongArgumentException('obsoleted identifier description found in ' . "{$class->getName()} class;\n" . 'you must use <identifier /> instead.'); } if (!$property->getType()->isGeneric()) { if (!isset($xmlProperty['relation'])) { throw new MissingElementException('relation should be set for non-generic ' . "property '{$property->getName()}' type '" . get_class($property->getType()) . "'" . " of '{$class->getName()}' class"); } else { $property->setRelation(MetaRelation::makeFromName((string) $xmlProperty['relation'])); if ($fetch = (string) $xmlProperty['fetch']) { Assert::isTrue($property->getRelationId() == MetaRelation::ONE_TO_ONE, 'fetch mode can be specified only for OneToOne relations'); if ($fetch == 'lazy') { $property->setFetchStrategy(FetchStrategy::lazy()); } elseif ($fetch == 'cascade') { $property->setFetchStrategy(FetchStrategy::cascade()); } else { throw new WrongArgumentException('strange fetch mode found - ' . $fetch); } } if ($property->getRelationId() == MetaRelation::ONE_TO_ONE && $property->getFetchStrategyId() != FetchStrategy::LAZY && $property->getType()->getClassName() != $class->getName()) { $this->references[$property->getType()->getClassName()][] = $class->getName(); } } } if (isset($xmlProperty['default'])) { // will be correctly autocasted further down the code $property->getType()->setDefault((string) $xmlProperty['default']); } $class->addProperty($property); } $class->setBuild($generate); $this->classes[$class->getName()] = $class; } return $this; }
/** * Signs the form and returns <form> cap and hidden fields * @return string */ function getHeadHtml(array $htmlAttributes = array()) { Assert::isFalse(isset($htmlAttributes['action'])); Assert::isFalse(isset($htmlAttributes['method'])); Assert::isFalse(isset($htmlAttributes['enctype'])); $htmlAttributes['action'] = $this->action; $htmlAttributes['method'] = $this->method; $htmlAttributes['enctype'] = $this->enctype->getValue(); return HtmlUtil::getTagCap('form', $htmlAttributes) . $this->dumpHidden(); }
public function split() { Assert::isFalse($this->isOpen(), "open range can't be splitted"); $dates = array(); $start = new Date($this->start->getDayStartStamp()); $endStamp = $this->end->getDayEndStamp(); for ($current = $start; $current->toStamp() < $endStamp; $current->modify('+1 day')) { $dates[] = new Date($current->getDayStartStamp()); } return $dates; }
/** * @return SimplePhpView **/ public function resolveViewName($viewName) { Assert::isFalse($this->prefixes === array(), 'specify at least one prefix'); if ($prefix = $this->findPrefix($viewName)) { return $this->makeView($prefix, $viewName); } if (!$this->findPrefix($viewName, false)) { throw new WrongArgumentException('can not resolve view: ' . $viewName); } return EmptyView::create(); }
private function move() { Assert::isFalse($this->isEmpty(), 'property path %s reached its tail', $this->path); $this->passed[] = array_shift($this->left); }
/** * @return MySqlBackup */ private function addComment($string) { Assert::isFalse(strpos("\r")); Assert::isFalse(strpos("\n")); $this->add('-- ')->addLine()->add('-- ')->add($string)->addLine()->add('-- ')->addLine(); return $this; }
/** * Makes a connection to the database to be NOT persistent * @return DB itself */ function makeNotPersistent() { Assert::isFalse($this->isConnected(), 'already connected - cannot switch to non-persistent conn'); $this->isPersistent = false; return $this; }
function backup($filename, $storeStructure = true, $storeData = false) { Assert::isFalse(!$storeStructure && !$storeData); $this->driver->setTarget($filename)->make($storeStructure, $storeData); }
/** * Appends the join clause to the last-added source for selection * * @return SelectQuery itself */ function join(SqlJoin $join) { Assert::isFalse($this->sources->isEmpty(), 'set any source before joining'); $this->sources->getLast()->join($join); return $this; }
function setError(FormControlError $error) { Assert::isFalse($error->is(FormControlError::MISSING), '%s cannot be missing', get_class($this)); return parent::setError($error); }
/** * Save multiple records using a single transaction. */ public static function saveAll(array $records, $cascade = false, $transactional = true) { if ($transactional) { $transactional = self::startTransaction(); } try { foreach ($records as $record) { // Save each individual record without starting a new transaction. $saveGraph = array(); // Ignored temp value for pass-by-reference. Work-around for PHP limitations. $record->save($cascade, $saveGraph, false); } Assert::isFalse($transactional && !DB::dbh()->commit(), 'Failed to commit transaction.'); } catch (Exception $ex) { if ($transactional) { DB::dbh()->rollBack(); } $code = (int) $ex->getCode() == 0 ? 115 : $ex->getCode(); throw new FrameEx("Error saving multiple records - " . $ex->getMessage(), $code, FrameEx::HIGH, $ex); } }
function dropAll() { Assert::isFalse($this->isReadonly(), 'cannot drop readonly collections'); $query = new EntityQuery($this->getChildren()); $this->fillQuery($query); $count = $query->delete(); $this->clean(); return $count; }