public function pushBindings(BlazeContext $context)
 {
     $requestUri = $context->getRequest()->getRequestURI()->getPath();
     // remove the prefix of the url e.g. BlazeFrameworkServer/
     if (!$requestUri->endsWith('/')) {
         $requestUri = $requestUri->concat('/');
     }
     $requestUri = $requestUri->substring($context->getApplication()->getUrlPrefix()->replace('*', '')->length());
     // Requesturl has always to start with a '/'
     if ($requestUri->length() == 0 || $requestUri->charAt(0) != '/') {
         $requestUri = new String('/' . $requestUri->toNative());
     }
     foreach ($this->mapping as $navigationRule) {
         $regex = '/^' . str_replace(array('/', '*'), array('\\/', '.*'), $navigationRule->getMapping()) . '$/';
         if ($requestUri->matches($regex)) {
             $bindingParts = $requestUri->substring(strlen($navigationRule->getMapping()) - 1)->split('/');
             $count = count($bindingParts);
             $newValue = null;
             // Look for the bindings
             $binds = $navigationRule->getBindings();
             for ($i = 0; $i < $binds->count(); $i++) {
                 if ($i < $count && $bindingParts[$i] != '') {
                     $newValue = $bindingParts[$i];
                 } else {
                     $newValue = $binds->get($i)->getDefault();
                 }
                 if ($newValue !== null) {
                     $binds->get($i)->getReference()->setValue($context, $newValue);
                     $newValue = null;
                 }
             }
         }
     }
 }
 /**
  *
  * @param blaze\lang\String|string $name The name of the cookie
  * @param blaze\lang\String|string $value The value of the cookie
  */
 public function __construct($name, $value)
 {
     $name = new String($name);
     if ($name->startsWith('$') || $name->contains(',') || $name->contains(';') || $name->contains(' ')) {
         throw new IllegalArgumentException('The name of a cookie can only contain alphanumeric characters but not commas, semicolons, whitespaces or begin with $ character.');
     }
     $this->name = $name;
     $this->value = String::asWrapper($value);
 }
 /**
  * Returns the login timeout in seconds.
  *
  * @return int The timeout in seconds.
  */
 public function unregisterDriver($protocol)
 {
     $protocol = String::asNative($protocol);
     if (array_key_exists($protocol, $this->drivers)) {
         unset($this->drivers[$protocol]);
     }
 }
Exemple #4
0
 /**
  * Generate a new BigDecimal Object.
  * @param <int|string|float|blaze\lang\Number> $value Is a native String, with scale and algebric sign
  * @param <type> $scale If value has no scale you can define the scale
  */
 public function __construct($value, $scale = null)
 {
     if (($class = Number::getNumberClass($value)) !== null) {
         $className = $class->getName()->toNative();
         $value = $className::asNative($value);
     } else {
         if (!self::isNativeType($value)) {
             throw new \blaze\lang\NumberFormatException('Not a valid representation of BigDecimal!');
         }
     }
     $this->value = String::asNative($value);
     if ($scale != null) {
         $this->scale = $scale;
     } else {
         $ar = explode('.', $this->value);
         $count = count($ar);
         if ($count > 2) {
             throw new \blaze\lang\NumberFormatException('Not a valid representation of BigDecimal!');
         }
         if ($count == 2) {
             $this->scale = strlen($ar[1]);
         } else {
             $this->scale = 0;
         }
     }
 }
 public function next()
 {
     if ($this->hasNext()) {
         $this->returnObj = $this->rsd->getResultClassInstance();
         foreach ($this->rsd->getFieldMappings() as $column => $propertyPath) {
             $classesPath = $propertyPath->getClassesPath();
             $namesPath = $propertyPath->getNamesPath();
             for ($i = 0; $i < count($namesPath); $i++) {
                 switch (\blaze\lang\String::asNative($classesPath[$i])) {
                     case 'int':
                         $this->setObjectValue($this->returnObj, $namesPath, $this->rs->getInt($column));
                         break;
                     case 'blaze\\lang\\String':
                         $this->setObjectValue($this->returnObj, $namesPath, $this->rs->getString($column));
                         break;
                     case 'blaze\\util\\Date':
                         $this->setObjectValue($this->returnObj, $namesPath, $this->rs->getDate($column));
                         break;
                     default:
                         $this->setObjectValue($this->returnObj, $namesPath, null);
                         break;
                 }
             }
         }
     } else {
         $this->returnObj = null;
     }
     $this->hasNext = null;
     return $this->returnObj;
 }
 /**
  * Returns an instance of TypeChecker for the specified type.
  *
  * @param string|blaze\lang\String|blaze\lang\ClassWrapper $type
  * @return blaze\collections\TypeChecker
  */
 public static function getInstance($type)
 {
     if ($type === null) {
         throw new blaze\lang\NullPointerException();
     }
     $class = null;
     $type = null;
     $typeName = null;
     if ($type instanceof \blaze\lang\ClassWrapper) {
         $class = $type;
         $typeName = $type->getName();
     } else {
         $type = \blaze\lang\String::asNative($type);
         if (in_array($type, self::$basicTypes)) {
             $type = $type;
             $typeName = new \blaze\lang\String($type);
         } else {
             $class = \blaze\lang\ClassWrapper::forName($type);
             $typeName = $class->getName();
         }
     }
     if (!array_key_exists($typeName, self::$typeCheckers)) {
         self::$typeCheckers[$typeName] = new TypeChecker($type, $class, $typeName);
     }
     return self::$typeCheckers[$typeName];
 }
Exemple #7
0
 public function getImmediate()
 {
     if ($this->immediate == null) {
         return false;
     }
     $imm = $this->getResolvedExpression($this->immediate);
     return \blaze\lang\Boolean::isType($imm) ? $imm : \blaze\lang\String::asWrapper($imm)->trim()->compareToIgnoreCase('true') == 0;
 }
 public function save(\blaze\persistence\cfg\Configuration $config, $file)
 {
     $f = null;
     if ($file instanceof \blaze\io\File) {
         $f = $file;
     } else {
         $f = new \blaze\io\File(\blaze\lang\String::asNative($file));
     }
 }
 /**
  *
  * @param blaze\lang\String|string|int $identifier
  * @param mixed $value
  * @return blaze\lang\PreparedStatement
  */
 protected function set($identifier, $value, $type = \PDO::PARAM_STR)
 {
     if (\blaze\lang\String::isType($identifier)) {
         $this->stmt->bindValue(':' . $identifier, $value, $type);
     } else {
         $this->stmt->bindValue($identifier + 1, $value, $type);
     }
     //|\PDO::PARAM_INPUT_OUTPUT);
 }
 public function getValue(\blaze\web\application\BlazeContext $context, $subExpressions, $subBrackets)
 {
     $left = $this->getLeftOperation()->getValue($context, $subExpressions, $subBrackets);
     $right = $this->getRightOperation()->getValue($context, $subExpressions, $subBrackets);
     if (\blaze\lang\String::isType($left) || \blaze\lang\String::isType($right)) {
         return $left . $right;
     } else {
         return $left + $right;
     }
 }
 /**
  * Construct a new FileInputStream.
  * @param string|blaze\lang\String|blaze\io\File $file
  * @throws blaze\lang\IllegalArgumentException If invalid argument specified.
  * @throws blaze\io\IOException If any IO error occurs
  */
 public function __construct($file, $append = false, $binary = true)
 {
     if ($file instanceof \blaze\io\File) {
         $this->file = $file;
     } elseif (\blaze\lang\String::isType($file)) {
         $this->file = new \blaze\io\File($file);
     } else {
         throw new \blaze\lang\IllegalArgumentException('Invalid argument type for $file.');
     }
     parent::__construct($this->file->getAbsolutePath()->toNative(), $append, $binary);
 }
 /**
  * @param \blaze\lang\String|string $protocol
  * @return blaze\net\URLStreamHandler
  */
 public function createURLStreamHandler($protocol)
 {
     switch (\blaze\lang\String::asWrapper($protocol)->toLowerCase()->toNative()) {
         case 'http':
             break;
         case 'https':
             break;
         case 'ftp':
             break;
     }
 }
 public function forwardEngineerXmlFile(\blaze\io\File $file)
 {
     $buf = new \blaze\lang\StringBuffer();
     $t = new \blaze\persistence\meta\driver\XmlMetaDriver();
     $cd = $t->parseFile($file);
     $cd->generate($buf);
     $fileName = \blaze\lang\String::asWrapper($cd->getName());
     $fileName = $fileName->substring($fileName->lastIndexOf('\\') + 1);
     $writer = new \blaze\io\output\FileWriter(new \blaze\io\File($this->dir, $fileName . '.php'));
     $writer->write($buf->toString());
     $writer->close();
 }
Exemple #14
0
 public static function asNative($value)
 {
     if (static::isWrapperType($value)) {
         return $value->toNative();
     } else {
         if (static::isNativeType($value)) {
             return $value;
         } else {
             return String::asNative($value);
         }
     }
 }
 public function write($str, $off = 0, $len = -1)
 {
     $str = \blaze\lang\String::asNative($str);
     if ($off > 0) {
         if ($len > 0) {
             $str = substr($str, $off, $len);
         } else {
             $str = substr($str, $off);
         }
     }
     return $this->out->write(serialize($str));
 }
 public function addFieldMapping(SingleFieldDescriptor $fieldDescriptor, $columnAlias = null)
 {
     if ($columnAlias === null) {
         $columnAlias = $fieldDescriptor->getColumnDescriptor()->getName();
     }
     if ($columnAlias === null) {
         throw new \blaze\lang\Exception('No column name available');
     }
     $columnAlias = \blaze\lang\String::asNative($columnAlias);
     $propPath = new PropertyPath();
     $propPath->addPathStep($fieldDescriptor->getType(), $fieldDescriptor->getName());
     $this->columnAliasToPropertyPathMapping[$columnAlias] = $propPath;
 }
Exemple #17
0
 private function getCondition($left, $right, $operator, $leftNegation = false, $rightNegation = false, $negation = false)
 {
     if (\blaze\lang\String::isType($left)) {
         $left = new \blaze\persistence\ooql\Value($left, \blaze\persistence\ooql\Value::TYPE_STRING, $leftNegation);
     } else {
         $left = new \blaze\persistence\ooql\Value($left, \blaze\persistence\ooql\Value::TYPE_SCALAR, $leftNegation);
     }
     if (\blaze\lang\String::isType($right)) {
         $right = new \blaze\persistence\ooql\Value($right, \blaze\persistence\ooql\Value::TYPE_STRING, $rightNegation);
     } else {
         $right = new \blaze\persistence\ooql\Value($right, \blaze\persistence\ooql\Value::TYPE_SCALAR, $rightNegation);
     }
     return new \blaze\persistence\ooql\Condition($left, $right, $operator, $negation);
 }
Exemple #18
0
 /**
  *
  * @param string|blaze\lang\String|blaze\io\File|blaze\io\output\FileOutputStream $fileOrStream
  */
 public function __construct($fileOrStream, $append = false)
 {
     $stream = null;
     if ($fileOrStream instanceof FileOutputStream) {
         $stream = $fileOrStream;
     } else {
         if ($fileOrStream instanceof \blaze\io\File || \blaze\lang\String::isType($fileOrStream)) {
             $stream = new FileOutputStream($fileOrStream, $append, false);
         } else {
             throw new \blaze\lang\IllegalArgumentException('Invalid argument type for $fileOrStream.');
         }
     }
     parent::__construct($stream);
 }
 protected function resolveSubParts(\blaze\web\application\BlazeContext $context, $subExpressions, $subBrackets, $expressionString)
 {
     if (\blaze\lang\String::isNativeType($expressionString)) {
         while (preg_match('/\\{([0-9]*)\\}/', $expressionString, $matches) != 0) {
             $val = $subExpressions[\blaze\lang\Integer::asNative($matches[1])]->getValue($context);
             $expressionString = str_replace($matches[0], $val, $expressionString);
         }
         while (preg_match('/\\(([0-9]*)\\)/', $expressionString, $matches) != 0) {
             $val = $subBrackets[\blaze\lang\Integer::asNative($matches[1])]->getValue($context);
             $expressionString = str_replace($matches[0], $val, $expressionString);
         }
     }
     return $expressionString;
 }
 public function write($str, $off = 0, $len = -1)
 {
     $str = \blaze\lang\String::asNative($str);
     if ($off > 0) {
         if ($len > 0) {
             $str = substr($str, $off, $len);
         } else {
             $str = substr($str, $off);
         }
     }
     if (fwrite($this->stream, $str) === false) {
         throw new \blaze\io\IOException('Error writing to stream.');
     }
 }
 /**
  * Checks the key and returns it as native string when wrapper is false, otherwise as blaze\lang\String.
  * @return string|blaze\lang\String
  */
 private static function getCheckedKey($key, $wrapper = false)
 {
     if ($wrapper) {
         $key = \blaze\lang\String::asWrapper($key);
         if ($key->length() < 1) {
             throw new CacheException('The length of the key must be at least one char!');
         }
     } else {
         $key = \blaze\lang\String::asNative($key);
         if (strlen($key) < 1) {
             throw new CacheException('The length of the key must be at least one char!');
         }
     }
     return $key;
 }
Exemple #22
0
 public function on($left, $right, $operator, $leftNegation = false, $rightNegation = false, $negation = false)
 {
     if ($this->onClause === null) {
         $this->onClause = new \blaze\persistence\ooql\OnClause();
     }
     if (\blaze\lang\String::isType($left)) {
         $left = new \blaze\persistence\ooql\Value($left, \blaze\persistence\ooql\Value::TYPE_STRING);
     } else {
         $left = new \blaze\persistence\ooql\Value($left, \blaze\persistence\ooql\Value::TYPE_SCALAR);
     }
     if (\blaze\lang\String::isType($right)) {
         $right = new \blaze\persistence\ooql\Value($right, \blaze\persistence\ooql\Value::TYPE_STRING);
     } else {
         $right = new \blaze\persistence\ooql\Value($right, \blaze\persistence\ooql\Value::TYPE_SCALAR);
     }
     $this->onClause->setCondition(new \blaze\persistence\ooql\Condition($left, $right, $operator, $negation));
 }
Exemple #23
0
 /**
  *
  * @return FileSystem
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         switch (String::asNative(\blaze\lang\System::getProperty('host.fs'))) {
             case 'UNIX':
                 self::$instance = new UnixFileSystem();
                 break;
             case 'WIN32':
                 self::$instance = new Win32FileSystem();
                 break;
             case 'WINNT':
                 self::$instance = new WinNTFileSystem();
                 break;
             default:
                 throw new \blaze\lang\Exception('Host uses unsupported filesystem, unable to proceed');
         }
     }
     return self::$instance;
 }
 public function condition($left, $right, $operator, $leftNegation = false, $rightNegation = false, $negation = false)
 {
     if ($left instanceof \blaze\persistence\ooql\Condition || $left instanceof \blaze\persistence\ooql\Value) {
         $this->left = $left;
     } else {
         if (\blaze\lang\String::isType($left)) {
             $this->left = new \blaze\persistence\ooql\Value($left, \blaze\persistence\ooql\Value::TYPE_STRING, $leftNegation);
         } else {
             $this->left = new \blaze\persistence\ooql\Value($left, \blaze\persistence\ooql\Value::TYPE_SCALAR, $leftNegation);
         }
     }
     if ($right instanceof \blaze\persistence\ooql\Condition || $right instanceof \blaze\persistence\ooql\Value) {
         $this->rightConditionable = $right;
     } else {
         if (\blaze\lang\String::isType($right)) {
             $this->rightConditionable = new \blaze\persistence\ooql\Value($right, \blaze\persistence\ooql\Value::TYPE_STRING, $rightNegation);
         } else {
             $this->rightConditionable = new \blaze\persistence\ooql\Value($right, \blaze\persistence\ooql\Value::TYPE_SCALAR, $rightNegation);
         }
     }
     $this->operator = $operator;
     $this->negation = $negation;
     return $this;
 }
 /**
  *
  * @param \blaze\persistence\meta\ClassDescriptor $config
  * @param File $file
  */
 public function save(\blaze\persistence\meta\ClassDescriptor $config, $file)
 {
     $f = null;
     if ($file instanceof \blaze\io\File) {
         $f = $file;
     } else {
         $f = new \blaze\io\File(\blaze\lang\String::asNative($file));
     }
     $doc = new \DOMDocument();
     $root = $doc->createElement('persistence-mapping');
     $doc->appendChild($root);
     $node = $doc->createElement('class');
     $root->appendChild($node);
     AttributeUtil::set($node, 'package', $config->getPackage());
     AttributeUtil::set($node, 'name', $config->getName());
     AttributeUtil::set($node, 'schema', $config->getTableDescriptor()->getSchema());
     AttributeUtil::set($node, 'table', $config->getTableDescriptor()->getName());
     foreach ($config->getIdentifiers() as $member) {
         $this->saveId($node, $doc, $member);
     }
     foreach ($config->getSingleFields() as $member) {
         $this->saveField($node, $doc, $member);
     }
     foreach ($config->getCollectionFields() as $member) {
         $this->saveCollection($node, $doc, $member);
     }
     $doc->save($f->getAbsolutePath());
 }
Exemple #26
0
 /**
  * Description
  *
  * @param 	blaze\lang\String|string $url Description of the parameter $var
  * @return 	blaze\net\URL Description of what the method returns
  * @throws	blaze\lang\Exception
  */
 public static function parseURL(\blaze\lang\String $url)
 {
     $idx = $url->indexOf('://');
     if ($idx == -1) {
         throw new \blaze\lang\Exception('Invalid URL');
     }
     $parts = parse_url($url);
     if ($parts === false) {
         throw new \blaze\lang\Exception('Invalid URL');
     }
     $scheme = isset($parts['scheme']) ? $parts['scheme'] : null;
     $host = isset($parts['host']) ? $parts['host'] : null;
     $port = isset($parts['port']) ? $parts['port'] : null;
     $user = isset($parts['user']) ? $parts['user'] : null;
     $password = isset($parts['pass']) ? $parts['pass'] : null;
     $path = isset($parts['path']) ? $parts['path'] : null;
     $query = isset($parts['query']) ? $parts['query'] : null;
     $fragment = isset($parts['fragment']) ? $parts['fragment'] : null;
     return new URL($scheme, $user, $password, $host, $port, $path, $query, $fragment);
 }
 private function getWhereColumn($string, $classMetas, \blaze\persistence\EntityManager $em)
 {
     $str = \blaze\lang\String::asWrapper($string);
     if ($str->startsWith(':') && !$str->contains(' ')) {
         return $string;
     } else {
         if ($str->equalsIgnoreCase('?')) {
             return $string;
         } else {
             if ($str->startsWith('"') && $str->endsWith('"')) {
                 return $string;
             } else {
                 if (\blaze\lang\Number::getNumberClass($string) !== null) {
                     return $string;
                 }
             }
         }
     }
     $parts = explode('.', $string);
     $alias = null;
     foreach ($classMetas as $classAlias => $meta) {
         if ($parts[0] === $classAlias) {
             $alias = array_shift($parts);
             break;
         }
     }
     if (count($classMetas) == 1) {
         $meta = array_shift($classMetas);
         $column = $this->recursiveColumnLookup($meta, $parts);
     } else {
         foreach ($classMetas as $classAlias => $meta) {
             if ($alias === null || $alias === $classAlias) {
                 $column = $this->recursiveColumnLookup($meta, $parts);
             }
         }
     }
     if ($alias !== null) {
         return $alias . '.' . $column;
     } else {
         return $column;
     }
 }
Exemple #28
0
 /**
  * check if the literal address string has %nn appended
  * returns -1 if not, or the numeric value otherwise.
  *
  * %nn may also be a string that represents the displayName of
  * a currently available NetworkInterface.
  * @return int
  */
 private static function checkNumericZone(\blaze\lang\String $s)
 {
     $percent = $s->indexOf('%');
     $slen = $s->length();
     $digit = null;
     $zone = 0;
     if ($percent == -1) {
         return -1;
     }
     for ($i = $percent + 1; $i < $slen; $i++) {
         $c = $s->charAt($i);
         if ($c == ']') {
             if ($i == $percent + 1) {
                 /* empty per-cent field */
                 return -1;
             }
             break;
         }
         if (($digit = \baze\lang\Character::digit($c, 10)) < 0) {
             return -1;
         }
         $zone = $zone * 10 + $digit;
     }
     return $zone;
 }
 public function getConstant($name)
 {
     try {
         return new Method($this->reflectionClass->getConstant(String::asNative($name)));
     } catch (\ReflectionException $e) {
         throw new NoSuchFieldException($e->getMessage(), $e->getCode());
     }
 }
Exemple #30
0
 /**
  * Appends a value to a property if it already exists with a delimiter
  *
  * If the property does not, it just adds it.
  * 
  * @param string $key
  * @param mixed $value
  * @param string $delimiter
  */
 public function append(\blaze\lang\String $key, \blaze\lang\String $value, \blaze\lang\String $delimiter = null)
 {
     if ($delimiter === null) {
         $delimiter = new \blaze\lang\String(',');
     }
     $newValue = $value;
     if (isset($this->properties[$key]) && !empty($this->properties[$key])) {
         $newValue = $this->properties[$key] . $delimiter . $value;
     }
     $this->properties[$key->toNative()] = \blaze\lang\String::asWrapper($newValue);
 }