public function navigate(BlazeContext $context, $action) { $actionString = String::asWrapper($action); $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)) { if ($actionString != null) { // Look for the action in the navigationMap foreach ($navigationRule->getActions() as $action => $view) { if ($actionString->compareTo($action) == 0) { // \blaze\util\Logger::get()->log('Navigated from '.$context->getViewRoot()->getViewId().' to '. $context->getViewHandler()->getView($context, $action['view'])->getViewId()); $context->setViewRoot($context->getViewHandler()->getView($context, $view)); $context->setNavigated(); return; } } } } } $view = $context->getViewHandler()->getView($context, $actionString); if ($view != null) { $context->setViewRoot($view); $context->setNavigated(); } }
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; }
/** * * @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); }
/** * @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(); }
/** * 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; }
/** * Description * * @param blaze\lang\String|string $uri Description of the parameter $var * @return blaze\net\URI Description of what the method returns * @throws blaze\lang\Exception */ public static function parseURI($uri) { $uri = \blaze\lang\String::asWrapper($uri); $idx = $uri->indexOf(':'); if ($idx == -1 || $idx === $uri->length()) { throw new \blaze\lang\Exception('Invalid URI'); } $scheme = $uri->substring(0, $idx); $ssp = $uri->substring($idx + 1); $idx = $ssp->lastIndexOf('#'); $fragment = null; if ($idx !== -1) { $fragment = $ssp->substring($idx + 1); $ssp = $ssp->substring(0, $idx); } return new URI($scheme, $ssp, $fragment); }
public function toString() { return String::asWrapper($this->value); }
public static function toOctal($i) { return String::asWrapper(decoct($i)); }
/** * * @param string|blaze\lang\String $package */ public function setPackage($package) { $this->package = \blaze\lang\String::asWrapper($package); }
public function getCursorName() { $this->checkClosed(); return \blaze\lang\String::asWrapper($this->stmt->getAttribute(\PDO::ATTR_CURSOR_NAME)); }
public function getString($identifier) { $this->checkClosed(); $val = $this->get($identifier); if ($val == null) { return null; } return String::asWrapper($val); }
/** * Retrieve the group of this file. * @return int User ID of the owner of this file. */ public function getGroup() { return String::asWrapper(@filegroup($this->getPath()->toNative())); }
/** * 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); }
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; } }
public function getSequenceName() { return \blaze\lang\String::asWrapper($this->table->getTableName() . '_' . $this->column->getName() . '_seq'); }
public function dropSequence($sequenceName) { $this->checkClosed(); $parts = \blaze\lang\String::asWrapper($sequenceName)->split('_'); if (count($parts) !== 3) { throw new \blaze\ds\DataSourceException('Sequencenames in this driver must have the following structure: tablename_columnname_seq'); } $tbl = $this->getTable($parts[0]); $col = $tbl->getColumn($parts[1]); $this->databaseMetaData->getConnection()->createStatement()->executeUpdate('ALTER TABLE ' . $parts[0] . ' MODIFY COLUMN ' . ColumnMetaDataImpl::getColumnDefinition($col, null, true, true, false)); }
/** * * @param string|\blaze\lang\String|\blaze\persistence\ooql\Statement $query * @return \blaze\persistence\meta\ResultSetDescriptor */ private function buildResultSetDescriptor($query) { $rsd = null; //if($query instanceof \blaze\persistence\ooql\Statement) if ($query instanceof \blaze\persistence\ooql\FromStatement) { $fromables = $query->getFromClause()->getFromables(); $aliasMapping = array(); // Fields which will occur in the ResultSet $fields = array(); $collectionFields = array(); // Just to check for name duplicates $fieldsGlobal = array(); if (count($fromables) < 1) { throw new \Exception('Invalid Query, nothing set in the from-clause!'); } // This loop is to check if there are any name duplicates // and to set up a alias to field mapping foreach ($fromables as $fromable) { if ($fromable instanceof \blaze\persistence\ooql\Entity) { $classMeta = $this->em->getEntityManagerFactory()->getClassDescriptor($fromable->getName()); if ($classMeta === null) { throw new \blaze\lang\Exception('Entity "' . $fromable->getName() . '" does not exist!'); } if ($fromable->getAlias() !== null) { $alias = \blaze\lang\String::asNative($fromable->getAlias()); if (array_search($alias, $aliasMapping) !== false) { throw new \blaze\lang\Exception('The alias ' . $alias . ' already exists!'); } $aliasMapping[$alias] = $classMeta; foreach ($classMeta->getIdentifiers() as $field) { $fields[$alias][] = $field->getFieldDescriptor(); } foreach ($classMeta->getSingleFields() as $field) { $fields[$alias][] = $field; } foreach ($classMeta->getCollectionFields() as $field) { $collectionFields[$alias][] = $field; } } else { $alias = \blaze\lang\String::asNative($fromable->getName()); if (array_search($alias, $aliasMapping) !== false) { throw new \blaze\lang\Exception('The alias ' . $alias . ' already exists!'); } $aliasMapping[$alias] = $classMeta; foreach ($classMeta->getIdentifiers() as $field) { $val = $field->getFieldDescriptor(); if (array_search($val->getName(), $fieldsGlobal) !== false) { throw new \blaze\lang\Exception('The attribute ' . $val->getName() . ' of ' . $classMeta->getName() . ' is already in the global scope, you need to use a alias!'); } $fieldsGlobal[] = $val->getName(); $fields[$alias][] = $val; } foreach ($classMeta->getSingleFields() as $field) { $val = $field; if (array_search($val->getName(), $fieldsGlobal) !== false) { throw new \blaze\lang\Exception('The attribute ' . $val->getName() . ' of ' . $classMeta->getName() . ' is already in the global scope, you need to use a alias!'); } $fieldsGlobal[] = $val->getName(); $fields[$alias][] = $val; } foreach ($classMeta->getCollectionFields() as $field) { $val = $field->getFieldDescriptor(); if (array_search($val->getName(), $fieldsGlobal) !== false) { throw new \blaze\lang\Exception('The attribute ' . $val->getName() . ' of ' . $classMeta->getName() . ' is already in the global scope, you need to use a alias!'); } $fieldsGlobal[] = $val->getName(); $collectionFields[$alias][] = $field; } } } else { if ($fromable instanceof \blaze\persistence\ooql\Join) { // Not supported at the moment } else { if ($fromable instanceof \blaze\persistence\ooql\Subselect) { // Not supported at the moment } } } } if ($query instanceof \blaze\persistence\ooql\SelectStatement) { $clause = $query->getSelectClause(); $selectables = $clause->getSelectables(); $selectFields = array(); if (count($selectables) < 1) { throw new \blaze\lang\Exception('Nothing to select given!'); } foreach ($selectables as $selectable) { } if (count($selectables) == 1) { // Check the selectable to be able to set the return class if ($selectables[0] instanceof \blaze\persistence\ooql\Formula) { $rsd = new \blaze\persistence\meta\ResultSetDescriptor($selectables[0]->getReturnType()); } else { $propNameParts = \blaze\lang\String::asWrapper($selectables[0]->getPropertyName())->split('.'); $alias = $propNameParts[count($propNameParts) - 1]; if ($selectables[0]->getPropertyAlias() !== null) { $alias = $selectables[0]->getPropertyAlias(); } $propPath = new \blaze\persistence\meta\PropertyPath(); // Check every field if the name is equal to the selectable foreach ($fields as $fieldGroup) { foreach ($fieldGroup as $field) { if ($field instanceof \blaze\persistence\meta\SingleFieldDescriptor) { if ($field->getName()->compareTo($propNameParts[0]) == 0) { $rsd = new \blaze\persistence\meta\ResultSetDescriptor($field->getType()); break; } } else { if ($field->getFieldDescriptor()->getName()->compareTo($propNameParts[0]) == 0) { // Collection //$rsd = new \blaze\persistence\meta\ResultSetDescriptor($field->getType()); break; } } } if ($rsd !== null) { break; } } } } else { // Return class is an Object[] $rsd = new \blaze\persistence\meta\ResultSetDescriptor('blaze\\lang\\Object', true); } } else { if (count($fromables) > 1) { throw new \blaze\lang\Exception('You need to specify what to select!'); } else { // Assume that the only object in fromables has to be selected $classDesc = $aliasMapping[\blaze\lang\String::asNative($fromables[0]->getAlias())]; $rsd = new \blaze\persistence\meta\ResultSetDescriptor($classDesc->getFullName()); foreach ($fields[\blaze\lang\String::asNative($fromables[0]->getAlias())] as $field) { $rsd->addFieldMapping($field); } foreach ($collectionFields[\blaze\lang\String::asNative($fromables[0]->getAlias())] as $field) { $rsd->addCollectionMapping($field); } } } } return $rsd; }
/** * * @param string|blaze\lang\String $comment */ public function setComment($comment) { $this->comment = \blaze\lang\String::asWrapper($comment); }
/** * * @param string|blaze\lang\String $schema */ public function setSchema($schema) { $this->schema = \blaze\lang\String::asWrapper($schema); }
public function getDisabled() { if ($this->disabled === null) { return false; } $disabled = $this->getResolvedExpression($this->disabled); return \blaze\lang\Boolean::isType($disabled) ? $disabled : \blaze\lang\String::asWrapper($disabled)->trim()->compareToIgnoreCase('true') == 0; }
/** * * @param blaze\lang\String|string $userAgent The user agent string */ public function __construct($userAgent) { $this->userAgentString = String::asWrapper($userAgent); }
public function getClassDescriptor($className) { foreach ($this->mapping as $cName => $classMeta) { if ($cName === $className || \blaze\lang\String::asWrapper($cName)->endsWith($className)) { return $classMeta; } } return null; }
/** * * @param Expression $expr * @param array $values */ public function invoke($expr, $values) { $parts = \blaze\lang\String::asWrapper($expr)->split('.', null, true); $partsCount = count($parts); if ($partsCount < 1) { throw new ELException('No valid expression'); } $obj = $this->getValueFromContext($parts[0]); if ($obj == null) { throw new ELException($parts[0] . ' is not a valid expression object'); } for ($i = 1; $i < $partsCount - 1; $i++) { $method = $obj->getClass()->getMethod('get' . $parts[$i]->toUpperCase(true)); $obj = $method->invoke($obj, null); } $method = $obj->getClass()->getMethod($parts[$partsCount - 1]->toUpperCase(true)); return $method->invokeArgs($obj, $values); }
/** * * @param string|blaze\lang\String $package * @param string|blaze\lang\String $name * @param blaze\io\File $dir * @param boolean $running */ private function __construct($package, $name, $urlPrefix, $running) { $this->package = String::asWrapper($package); $this->name = String::asWrapper($name); $prefix = trim(str_replace('*', '', $urlPrefix), '/'); if (strlen($prefix) !== 0) { $prefix .= '/'; } $this->urlPrefix = String::asWrapper(self::$serverConfig->get('serverHome') . $prefix); $this->running = $running; $this->applicationPath = new File(ClassLoader::getSystemClassLoader()->getClassPath(), $package); }
public function toString(\blaze\web\application\BlazeContext $context, $obj) { return String::asWrapper($obj); }
/** * Given the name of a host, returns an array of its IP addresses, * based on the configured name service on the system. * * <p> The host name can either be a machine name, such as * '<code>java.sun.com</code>', or a textual representation of its IP * address. If a literal IP address is supplied, only the * validity of the address format is checked. * * <p> For <code>host</code> specified in <i>literal IPv6 address</i>, * either the form defined in RFC 2732 or the literal IPv6 address * format defined in RFC 2373 is accepted. A literal IPv6 address may * also be qualified by appending a scoped zone identifier or scope_id. * The syntax and usage of scope_ids is described * <a href='Inet6Address.html#scoped'>here</a>. * <p> If the host is <tt>null</tt> then an <tt>InetAddress</tt> * representing an address of the loopback interface is returned. * See <a href='http://www.ietf.org/rfc/rfc3330.txt'>RFC 3330</a> * section 2 and <a href='http://www.ietf.org/rfc/rfc2373.txt'>RFC 2373</a> * section 2.5.3. </p> * * <p> If there is a security manager and <code>host</code> is not * null and <code>host.length() </code> is not equal to zero, the * security manager's * <code>checkConnect</code> method is called * with the hostname and <code>-1</code> * as its arguments to see if the operation is allowed. * * @param host the name of the host, or <code>null</code>. * @return array[InetAddress] an array of all the IP addresses for a given host name. * * @exception UnknownHostException if no IP address for the * <code>host</code> could be found, or if a scope_id was specified * for a global IPv6 address. * @exception SecurityException if a security manager exists and its * <code>checkConnect</code> method doesn't allow the operation. * * @see SecurityManager#checkConnect */ public static function getAllByName($host, InetAddress $reqAddr = null) { $host = \blaze\lang\String::asWrapper($host); if ($host->length() == 0) { $ret = new \blaze\collections\arrays\ArrayObject(1); $ret[0] = $impl->loopbackAddress(); return $ret; } $ipv6Expected = false; if ($host->charAt(0) == '[') { // This is supposed to be an IPv6 litteral if ($host->length() > 2 && $host->charAt($host->length() - 1) == ']') { $host = $host->substring(1, $host->length() - 1); $ipv6Expected = true; } else { // This was supposed to be a IPv6 address, but it's not! // throw new UnknownHostException(4host); } } // if host is an IP address, we won't do further lookup if (\blaze\lang\Character::digit($host->charAt(0), 16) != -1 || $host->charAt(0) == ':') { $addr = null; $numericZone = -1; $ifname = null; // see if it is IPv4 address $addr = self::textToNumericFormatV4($host); if ($addr == null) { // see if it is IPv6 address // Check if a numeric or string zone id is present if (($pos = $host->indexOf('%')) != -1) { $numericZone = $self::checkNumericZone($host); if ($numericZone == -1) { /* remainder of string must be an ifname */ $ifname = $host->substring($pos + 1); } } $addr = IPAddressUtil::textToNumericFormatV6($host); } else { if ($ipv6Expected) { // Means an IPv4 litteral between brackets! // throw new UnknownHostException('['+host+']'); } } $ret = new ArrayObject(1); if ($addr != null) { if ($addr->length == Inet4Address::INADDRSZ) { $ret[0] = new Inet4Address(null, $addr); } else { if ($ifname != null) { $ret[0] = new Inet6Address(null, $addr, $ifname); } else { $ret[0] = new Inet6Address(null, $addr, $numericZone); } } return $ret; } } else { if ($ipv6Expected) { // We were expecting an IPv6 Litteral, but got something else // throw new UnknownHostException('['+host+']'); } } return self::getAllByName0($host, $reqAddr, true); }
public function getComposedNativeType() { $type = $this->getNativeType(); switch (\blaze\lang\String::asNative($type)) { case 'bigint': case 'tinyint': case 'smallint': case 'mediumint': case 'int': $type .= '(' . $this->getLength() . ')' . $this->isSigned() ? '' : 'UNSIGNED'; break; case 'char': case 'varchar': case 'binary': $type .= '(' . $this->getLength() . ')'; break; case 'real': case 'double': case 'float': case 'numeric': case 'decimal': $type .= '(' . $this->getLength() . ',' . $this->getPrecision() . ')'; break; } return \blaze\lang\String::asWrapper($type); }
/** * * @param blaze\lang\String|string $scheme * @param blaze\lang\String|string $user * @param blaze\lang\String|string $password * @param blaze\lang\String|string $host * @param int $port * @param blaze\lang\String|string $path * @param blaze\lang\String|string $query * @param blaze\lang\String|string $fragment */ public function __construct($scheme, $user = null, $password = null, $host = null, $port = null, $path = null, $query = null, $fragment = null) { $this->scheme = $scheme !== null ? \blaze\lang\String::asWrapper($scheme) : null; $this->user = $user !== null ? \blaze\lang\String::asWrapper($user) : null; $this->password = $password !== null ? \blaze\lang\String::asWrapper($password) : null; $this->host = $host !== null ? \blaze\lang\String::asWrapper($host) : null; $this->port = $port !== null ? \blaze\lang\Integer::asNative($port) : -1; $this->path = $path !== null ? \blaze\lang\String::asWrapper($path) : null; $this->query = $query !== null ? \blaze\lang\String::asWrapper($query) : null; $this->fragment = $fragment !== null ? \blaze\lang\String::asWrapper($fragment) : null; $this->buildUrl(); }
private function getMemberName($columnName) { $parts = \blaze\lang\String::asWrapper($columnName)->split('_', null, true); $memberName = array_shift($parts)->toLowerCase(true)->toNative(); foreach ($parts as $part) { $memberName .= $part->toUpperCase(true)->toNative(); } return $memberName; }