/**
  * @throws WrongArgumentException
  * @return IdentifiablePrimitive
  **/
 public function setValue($value)
 {
     $className = $this->className;
     Assert::isNotNull($this->className);
     Assert::isTrue($value instanceof $className);
     return parent::setValue($value);
 }
Example #2
0
 public function rebind($name, $object)
 {
     Assert::isNotNull($object);
     $this->map[$name] = $object;
     $this->reverseMap[spl_object_hash($object)] = $name;
     return $this;
 }
Example #3
0
 /**
  * @return FileInputStream
  **/
 private function getStream()
 {
     if (!$this->stream) {
         Assert::isNotNull($this->queue->getFileName());
         $this->stream = FileInputStream::create($this->queue->getFileName())->seek($this->queue->getOffset());
     }
     return $this->stream;
 }
Example #4
0
 private function getStream()
 {
     if (!$this->stream) {
         Assert::isNotNull($this->queue->getFileName());
         $this->stream = FileOutputStream::create($this->queue->getFileName(), true);
     }
     return $this->stream;
 }
Example #5
0
 public function getRequestGetter()
 {
     Assert::isNotNull($this->requestType);
     if (!$this->requestGetter) {
         $this->requestGetter = self::$requestGetterMap[$this->requestType->getId()];
     }
     return $this->requestGetter;
 }
Example #6
0
 /**
  * @return ArgumentParser
  **/
 public function validate()
 {
     Assert::isNotNull($this->result);
     $this->form->import($this->result);
     if ($errors = $this->form->getErrors()) {
         throw new WrongArgumentException("\nArguments wrong:\n" . print_r($errors, true));
     }
     return $this;
 }
 /**
  * @return MultiPrefixPhpViewResolver
  **/
 public function disablePrefix($alias = null, $disabled = true)
 {
     if (!$alias) {
         $alias = $this->lastAlias;
     }
     Assert::isNotNull($alias, 'nothing to disable');
     Assert::isIndexExists($this->prefixes, $alias, 'no such alias: ' . $alias);
     $this->disabled[$alias] = $disabled;
     return $this;
 }
Example #8
0
 public static function makeTag(SgmlToken $tag)
 {
     if ($tag instanceof Cdata) {
         $result = $tag->getData();
     } elseif ($tag instanceof SgmlIgnoredTag) {
         Assert::isNotNull($tag->getId());
         $result = '<' . $tag->getId() . $tag->getCdata()->getData() . $tag->getEndMark() . '>';
     } elseif ($tag instanceof SgmlOpenTag) {
         Assert::isNotNull($tag->getId());
         $attributes = self::getAttributes($tag);
         $result = '<' . $tag->getId() . ($attributes ? ' ' . $attributes : null) . ($tag->isEmpty() ? '/' : null) . '>';
     } elseif ($tag instanceof SgmlEndTag) {
         $result = '</' . $tag->getId() . '>';
     } else {
         throw new WrongArgumentException("don't know how to assemble tag class '" . get_class($tag) . "'");
     }
     return $result;
 }
Example #9
0
 public function merge(Identifiable $object, $cacheOnly = true)
 {
     Assert::isNotNull($object->getId());
     $this->checkObjectType($object);
     $old = Cache::worker($this)->getCachedById($object->getId());
     if (!$old) {
         // unlikely
         if ($cacheOnly) {
             return $this->save($object);
         } else {
             $old = Cache::worker($this)->getById($object->getId());
         }
     }
     if ($object === $old) {
         return $this->save($object);
     }
     return $this->unite($object, $old);
 }
 public function __construct()
 {
     $wsdlUrl = $this->getWsdlUrl();
     Assert::isNotNull($wsdlUrl);
     $this->soapClient = new \SoapClient($wsdlUrl, ['soap_version' => SOAP_1_1, 'classmap' => $this->classMap(), 'trace' => true, 'exceptions' => true]);
 }
Example #11
0
 /**
  * @return CurlHttpClient
  **/
 protected function makeResponse($handle, CurlHttpResponse $response)
 {
     Assert::isNotNull($handle);
     $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
     try {
         $response->setStatus(new HttpStatus($httpCode));
     } catch (MissingElementException $e) {
         throw new NetworkException('curl error, strange http code: ' . $httpCode);
     }
     return $this;
 }
Example #12
0
 private function processPath(AbstractProtoClass $proto, $probablyPath, JoinCapableQuery $query, $table, $parentRequired = true, $prefix = null)
 {
     $path = explode('.', $probablyPath);
     try {
         $property = $proto->getPropertyByName($path[0]);
     } catch (MissingElementException $e) {
         // oh, it's a value, not a property
         return new DBValue($probablyPath);
     }
     unset($path[0]);
     Assert::isTrue($property->getRelationId() != null && !$property->isGenericType());
     Assert::classExists($property->getClassName());
     // checking whether we're playing with value object
     if (!method_exists($property->getClassName(), 'dao')) {
         if (method_exists($property->getClassName(), 'proto') && count($path) > 1) {
             return $this->processPath($property->getProto(), implode('.', $path), $query, $table);
         } else {
             return $this->guessAtom(implode('.', $path), $query, $table, $prefix);
         }
     } else {
         $propertyDao = call_user_func([$property->getClassName(), 'dao']);
         Assert::isNotNull($propertyDao, 'can not find target dao for "' . $property->getName() . '" property at "' . get_class($proto) . '"');
     }
     $alias = $propertyDao->getJoinName($property->getColumnName(), $prefix);
     if ($property->getRelationId() == MetaRelation::ONE_TO_MANY || $property->getRelationId() == MetaRelation::MANY_TO_MANY) {
         $remoteName = $property->getClassName();
         $selfName = $this->getObjectName();
         $self = new $selfName();
         $getter = $property->getGetter();
         $dao = call_user_func([$remoteName, 'dao']);
         if ($property->getRelationId() == MetaRelation::MANY_TO_MANY) {
             $helperTable = $self->{$getter}()->getHelperTable();
             $helperAlias = $helperTable;
             if (!$query->hasJoinedTable($helperAlias)) {
                 $logic = Expression::eq(DBField::create($this->getIdName(), $table), DBField::create($self->{$getter}()->getParentIdField(), $helperAlias));
                 if ($property->isRequired()) {
                     $query->join($helperTable, $logic, $helperAlias);
                 } else {
                     $query->leftJoin($helperTable, $logic, $helperAlias);
                 }
             }
             $logic = Expression::eq(DBField::create($propertyDao->getIdName(), $alias), DBField::create($self->{$getter}()->getChildIdField(), $helperAlias));
         } else {
             $logic = Expression::eq(DBField::create($self->{$getter}()->getParentIdField(), $alias), DBField::create($this->getIdName(), $table));
         }
         if (!$query->hasJoinedTable($alias)) {
             if ($property->isRequired() && $parentRequired) {
                 $query->join($dao->getTable(), $logic, $alias);
             } else {
                 $query->leftJoin($dao->getTable(), $logic, $alias);
             }
         }
     } else {
         // OneToOne, lazy OneToOne
         // prevents useless joins
         if (isset($path[1]) && count($path) == 1 && $path[1] == $propertyDao->getIdName()) {
             return new DBField($property->getColumnName(), $table);
         }
         if (!$query->hasJoinedTable($alias)) {
             $logic = Expression::eq(DBField::create($property->getColumnName(), $table), DBField::create($propertyDao->getIdName(), $alias));
             if ($property->isRequired() && $parentRequired) {
                 $query->join($propertyDao->getTable(), $logic, $alias);
             } else {
                 $query->leftJoin($propertyDao->getTable(), $logic, $alias);
             }
         }
     }
     if ($path) {
         return $propertyDao->guessAtom(implode('.', $path), $query, $alias, $property->isRequired() && $parentRequired, $propertyDao->getJoinPrefix($property->getColumnName(), $prefix));
     }
     // ok, we're done
 }
 /**
  * @return JoinCapableQuery
  **/
 public function process(Criteria $criteria, JoinCapableQuery $query)
 {
     Assert::isNotNull($this->property);
     return $query->get(SQLFunction::create($this->getFunctionName(), $criteria->getDao()->guessAtom($this->property, $query))->setAlias($this->alias));
 }
Example #14
0
 /**
  * @return InsertOrUpdateQuery
  **/
 public function fillQuery(InsertOrUpdateQuery $query, Prototyped $object, Prototyped $old = null)
 {
     if ($old) {
         if ($object instanceof Identifiable) {
             Assert::isNotNull($object->getId());
             Assert::isTypelessEqual($object->getId(), $old->getId(), 'cannot merge different objects');
         }
     }
     foreach ($this->getPropertyList() as $property) {
         $property->fillQuery($query, $object, $old);
     }
     return $query;
 }
Example #15
0
 public function poorReference($url)
 {
     Assert::isNotNull($this->base, 'set base url first');
     $parsedUrl = HttpUrl::create()->parse($url);
     return $this->base->transform($parsedUrl);
 }
 public function run()
 {
     Assert::isTrue(!is_null($this->dao) || !is_null($this->db), 'set first dao or db');
     Assert::isNotNull($this->function, 'set first function');
     $transaction = InnerTransaction::begin($this->dao ?: $this->db, $this->level, $this->mode);
     try {
         $result = call_user_func_array($this->function, func_get_args());
         $transaction->commit();
         return $result;
     } catch (\Exception $e) {
         $transaction->rollback();
         if ($this->exceptionFunction) {
             $args = func_get_args();
             array_unshift($args, $e);
             return call_user_func_array($this->exceptionFunction, $args);
         }
         throw $e;
     }
 }
Example #17
0
 private function attrValueState()
 {
     Assert::isNull($this->tagId);
     Assert::isNotNull($this->tag);
     Assert::isTrue($this->tag instanceof SgmlOpenTag);
     while ($this->char !== null) {
         if (!$this->insideQuote && self::isSpacerChar($this->char)) {
             $this->getNextChar();
             if ($this->attrValue !== null && $this->attrValue !== '') {
                 // NOTE: "0" is accepted value
                 // <tag id=unquottedValue[space]
                 $this->dumpAttribute();
                 return self::INSIDE_TAG_STATE;
             }
             // <tag id=[space*]
             continue;
         } elseif (!$this->insideQuote && $this->char == '>') {
             // <tag id=value>, <a href=catalog/>
             $this->dumpAttribute();
             $this->makeTag();
             $this->getNextChar();
             return self::INITIAL_STATE;
         } else {
             if ($this->char == '"' || $this->char == "'" || $this->char == $this->insideQuote) {
                 if (!$this->insideQuote) {
                     $this->insideQuote = $this->char;
                     $this->getNextChar();
                     // a place to rollback if second quote will not be
                     // found.
                     $this->mark();
                     continue;
                 } elseif ($this->char == $this->insideQuote) {
                     // attr = "value", attr='value', attr='value>([^']*)
                     $this->dumpAttribute();
                     $this->getNextChar();
                     if ($this->insideQuote == '>') {
                         $this->insideQuote = null;
                         $this->makeTag();
                         return self::INITIAL_STATE;
                     } else {
                         $this->insideQuote = null;
                         return self::INSIDE_TAG_STATE;
                     }
                 }
             }
             $this->attrValue .= $this->char;
             if ($this->insideQuote && $this->char == '\\') {
                 $this->attrValue .= $this->getNextChar();
             }
             $this->getNextChar();
         }
     }
     if ($this->insideQuote) {
         // <tag id="...[eof]
         //
         // NOTE: firefox rolls back to the first > after quote.
         // Opera consideres incomplete tag as cdata.
         // we act as ff does.
         $this->reset();
         $this->warning("unclosed quoted value for attr == '{$this->attrName}'," . " rolling back and searching '>'");
         $this->attrValue = null;
         $this->insideQuote = '>';
         // call?
         // TODO: possible infinite loop?
         return self::ATTR_VALUE_STATE;
     }
     // <tag id=[space*][eof], <tag id=val[eof]
     $this->dumpAttribute();
     $this->error('unexpected end of file, incomplete tag stored');
     $this->makeTag();
     return self::FINAL_STATE;
 }
Example #18
0
 /**
  * @return JoinCapableQuery
  **/
 public function process(Criteria $criteria, JoinCapableQuery $query)
 {
     Assert::isNotNull($this->property);
     return $query->get($criteria->getDao()->guessAtom($this->property, $query), $this->alias);
 }
 /**
  * @return GenericDAO
  **/
 public function dao()
 {
     Assert::isNotNull($this->className, 'specify class name first of all');
     return call_user_func([$this->className, 'dao']);
 }
Example #20
0
 /**
  * @return SQLFunction
  **/
 protected function getFunction(Criteria $criteria, JoinCapableQuery $query)
 {
     Assert::isNotNull($this->property);
     return SQLFunction::create('count', $this->property ? $criteria->getDao()->guessAtom($this->property, $query) : $criteria->getDao()->getIdName());
 }
Example #21
0
 private function loadNextChunk($id)
 {
     Assert::isNotNull($this->dao);
     $this->offset = 0;
     $criteria = Criteria::create($this->dao);
     if ($this->projection) {
         $criteria->setProjection($this->projection);
     }
     $criteria->addOrder($this->keyProperty)->setLimit($this->chunkSize);
     if ($id !== null) {
         $criteria->add(Expression::gt($this->keyProperty, $id));
     }
     // preserving memory bloat
     $this->dao->dropIdentityMap();
     $this->chunk = $criteria->getList();
     return $this->chunk;
 }