public function toString()
 {
     Assert::isNotNull($this->encoding, 'Data encdoing Required.');
     $boundString = null;
     $dataStrings = $bounds = array();
     if ($this->dataScaling) {
         $boundString = '&' . GoogleChartDataScaling::getParamName() . '=';
     }
     if ($this->normalize) {
         $this->normalize();
     }
     foreach ($this->sets as $set) {
         $this->encoding->setMaxValue($set->getMax() + 1);
         $dataStrings[] = $this->encoding->encode($set);
         if ($this->dataScaling) {
             $bounds[] = $set->getMin() . ',' . $set->getMax();
         }
     }
     if ($this->dataScaling) {
         $boundString .= implode(',', $bounds);
     }
     $dataString = implode('|', $dataStrings);
     $encodingString = $this->encoding->toString();
     return $this->name . '=' . $encodingString . $dataString . $boundString;
 }
 /**
  * @throws WrongArgumentException
  * @return IdentifiablePrimitive
  **/
 public function setValue($value)
 {
     $className = $this->className;
     Assert::isNotNull($this->className);
     Assert::isTrue($value instanceof $className);
     return parent::setValue($value);
 }
 public function rebind($name, $object)
 {
     Assert::isNotNull($object);
     $this->map[$name] = $object;
     $this->reverseMap[spl_object_hash($object)] = $name;
     return $this;
 }
 public function unite(Identifiable $object, Identifiable $old)
 {
     Assert::isNotNull($object->getId());
     Assert::isTypelessEqual($object->getId(), $old->getId(), 'cannot merge different objects');
     $query = OSQL::update($this->getTable());
     foreach ($this->getProtoClass()->getPropertyList() as $property) {
         $getter = $property->getGetter();
         if ($property->getClassName() === null) {
             $changed = $old->{$getter}() !== $object->{$getter}();
         } else {
             /**
              * way to skip pointless update and hack for recursive
              * comparsion.
              **/
             $changed = $old->{$getter}() !== $object->{$getter}() || $old->{$getter}() != $object->{$getter}();
         }
         if ($changed) {
             $property->fillQuery($query, $object);
         }
     }
     if (!$query->getFieldsCount()) {
         return $object;
     }
     $this->targetizeUpdateQuery($query, $object);
     return $this->doInject($query, $object);
 }
 private function getStream()
 {
     if (!$this->stream) {
         Assert::isNotNull($this->queue->getFileName());
         $this->stream = FileOutputStream::create($this->queue->getFileName(), true);
     }
     return $this->stream;
 }
 public function getRequestGetter()
 {
     Assert::isNotNull($this->requestType);
     if (!$this->requestGetter) {
         $this->requestGetter = self::$requestGetterMap[$this->requestType->getId()];
     }
     return $this->requestGetter;
 }
 /**
  * @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;
 }
 /**
  * @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;
 }
 /**
  * @return OqlQueryClause
  **/
 public function parse($string = null)
 {
     if ($string === null) {
         Assert::isNotNull($this->tokenizer);
     } else {
         Assert::isString($string);
         $this->tokenizer = new OqlTokenizer($string);
     }
     $this->state = self::INITIAL_STATE;
     $this->oqlObject = $this->makeOqlObject();
     $this->parentheses = 0;
     while ($this->state != self::FINAL_STATE) {
         $this->state = $this->handleState();
     }
     $this->checkParentheses();
     return $this->oqlObject;
 }
 public function render($forceQuotes = false)
 {
     Assert::isNotNull($this->separator);
     $csvString = null;
     foreach ($this->data as $row) {
         Assert::isArray($row);
         $rowString = null;
         foreach ($row as $value) {
             if ($forceQuotes || preg_match(self::QUOTE_REQUIRED_PATTERN, $value)) {
                 $value = self::QUOTE . mb_ereg_replace(self::QUOTE, self::QUOTE . self::QUOTE, $value) . self::QUOTE;
             }
             $rowString .= ($rowString ? $this->separator : null) . $value;
         }
         $csvString .= $rowString . self::CRLF;
     }
     return $csvString;
 }
 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;
 }
 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 toString()
 {
     $url = self::BASE_URL;
     Assert::isNotNull($this->type);
     $parameters[] = $this->type->toString();
     Assert::isNotNull($this->size);
     $parameters[] = $this->size->toString();
     Assert::isNotNull($this->color);
     $parameters[] = $this->color->toString();
     Assert::isNotNull($this->data);
     $parameters[] = $this->data->toString();
     if ($this->legend) {
         $parameters[] = $this->legend->toString();
     }
     if ($this->label) {
         $parameters[] = $this->label->toString();
     }
     if ($this->title) {
         $parameters[] = $this->title->toString();
     }
     if ($this->fillers->hasFillers()) {
         $parameters[] = $this->fillers->toString();
     }
     $url .= implode('&', $parameters);
     return $url;
 }
 /**
  * @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());
 }
 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;
 }
 /**
  * @return Locker
  */
 function getLocker()
 {
     Assert::isNotNull($this->locker, 'locker is not set');
     return $this->locker;
 }
 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;
     }
 }
 public function toString()
 {
     Assert::isNotNull($this->dataSetIndex);
     Assert::isNotNull($this->size);
     return $this->type->toString() . ',' . $this->color->toString() . ',' . $this->dataSetIndex . ',' . $this->dataPoint . ',' . $this->size;
 }
 /**
  * @return JoinCapableQuery
  **/
 public function process(Criteria $criteria, JoinCapableQuery $query)
 {
     Assert::isNotNull($this->property);
     return $query->get($criteria->getDao()->guessAtom($this->property, $query), $this->alias);
 }
 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(array($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(array($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
 }
Esempio n. 22
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;
 }
 /**
  * @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;
 }
Esempio n. 24
0
 /**
  * Sets the new enumeration value. Value is one the constants defined inside enumeration
  * @param scalar $value one of the final class constants specified
  * @return Enumeration itself
  */
 protected function setValue($value)
 {
     $id = $this->getIdByValue($value);
     if (!$id) {
         Assert::isNotNull($id, 'unknown value given for %s: `%s`', get_class($this), $value);
     }
     $this->id = $id;
     $this->value = $value;
     return $this;
 }
 public function __construct()
 {
     $wsdlUrl = $this->getWsdlUrl();
     Assert::isNotNull($wsdlUrl);
     $this->soapClient = new SoapClient($wsdlUrl, array('soap_version' => SOAP_1_1, 'classmap' => $this->classMap(), 'trace' => true, 'exceptions' => true));
 }
 public function toString()
 {
     Assert::isNotNull($this->color, 'Color parameter required!');
     return $this->type->toString() . ',s' . ',' . $this->color->toString();
 }
 /**
  * @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));
 }
 public function toLogic()
 {
     Assert::isNotNull($this->expression);
     return $this->expression->evaluate($this->parameters);
 }
 /**
  * @return GenericDAO
  **/
 public function dao()
 {
     Assert::isNotNull($this->className, 'specify class name first of all');
     return call_user_func(array($this->className, 'dao'));
 }
 public function poorReference($url)
 {
     Assert::isNotNull($this->base, 'set base url first');
     $parsedUrl = HttpUrl::create()->parse($url);
     return $this->base->transform($parsedUrl);
 }