Esempio n. 1
0
File: marg.php Progetto: naozone/phx
 public static function run($routes)
 {
     if (isset(self::$setUp)) {
         call_user_func(self::$setUp);
     }
     global $request;
     $controller_name = '';
     $matches = array();
     foreach ($routes as $pattern => $controller) {
         if (preg_match('#^/?' . $pattern . '/?$#', $request->uri, $match)) {
             $controller_name = $controller;
             $matches = array_slice($match, 1);
             break;
         }
     }
     if (is_array($controller_name)) {
         // By default GET
         $methods = array('GET');
         if (isset($controller_name['controller'])) {
             if (isset($controller_name['methods'])) {
                 $methods = $controller_name['methods'];
             }
             $controller_name = $controller_name['controller'];
         } else {
             if (isset($controller_name[1]) && is_array($controller_name[1])) {
                 $methods = $controller_name[1];
             }
             $controller_name = $controller_name[0];
         }
         if (in_array(strtoupper($request->verb), $methods)) {
             call_user_func_array($controller_name, $matches);
         } else {
             raise('405');
         }
     } elseif (class_exists($controller_name)) {
         $controller = new $controller_name($matches);
         call_user_func_if_exists(array($controller, 'setUp'));
         $method = strtolower($request->verb);
         if ($request->is_ajax && method_exists($controller, $method . '_ajax')) {
             // Headers inspired by and taken from ToroPHP's code.
             // ToroPHP on Github: https://github.com/anandkunal/ToroPHP/
             header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
             header('Cache-Control: no-store, no-cache, must-revalidate');
             header('Cache-Control: post-check=0, pre-check=0', false);
             header('Pragma: no-cache');
             call_user_func_array(array($controller, $method . '_ajax'), $matches);
         } elseif (method_exists($controller, $method)) {
             call_user_func_array(array($controller, $method), $matches);
         }
         call_user_func_if_exists(array($controller, 'tearDown'));
     } elseif (function_exists($controller_name)) {
         call_user_func_array($controller_name, $matches);
     } else {
         raise('404');
     }
     if (isset(self::$tearDown)) {
         call_user_func(self::$tearDown);
     }
 }
 /**
  * Fetches a resource
  *
  * @param   string name
  * @return  string
  */
 protected function getResource($name)
 {
     foreach ($this->cl as $loader) {
         if ($loader->providesResource($name)) {
             return $loader->getResource($name);
         }
     }
     raise('lang.ElementNotFoundException', $name);
 }
 /**
  * Returns a method for a class by a given name
  *
  * @param   text.doclet.ClassDoc self
  * @param   string name
  * @return  text.doclet.MethodDoc
  * @throws  lang.ElementNotFoundException
  */
 public static function methodNamed(ClassDoc $self, $name)
 {
     foreach ($self->methods as $method) {
         if ($name === $method->name()) {
             return $method;
         }
     }
     raise('lang.ElementNotFoundException', 'No such method ' . $name . ' in ' . $self->name());
 }
 /**
  * Invoke method on a registered instance.
  *
  * @param   string instancename
  * @param   string methodname
  * @param   var* method arguments
  * @return  var
  * @throws  lang.IllegalArgumentException if the instance is not known
  * @throws  lang.ElementNotFoundException if the given method does not exist or is not xsl-accessible
  */
 public static function invoke($name, $method)
 {
     if (!isset(self::$instance->instances[$name])) {
         throw new IllegalArgumentException('No such registered XSL callback instance: "' . $name . '"');
     }
     $instance = self::$instance->instances[$name];
     if (!$instance->getClass()->getMethod($method)->hasAnnotation('xslmethod')) {
         raise('lang.ElementNotFoundException', 'Instance "' . $name . '" does not have method "' . $method . '"');
     }
     $va = func_get_args();
     // Decode arguments [2..*]
     for ($i = 2, $args = array(), $s = sizeof($va); $i < $s; $i++) {
         $args[] = is_string($va[$i]) ? iconv('utf-8', xp::ENCODING, $va[$i]) : $va[$i];
     }
     // Call callback method
     $r = call_user_func_array(array($instance, $method), $args);
     // Encode result if necessary
     return is_string($r) ? iconv(xp::ENCODING, 'utf-8', $r) : $r;
 }
Esempio n. 5
0
 static function acquire($archive)
 {
     static $archives = array();
     static $unpack = array(1 => 'a80id/a80*filename/a80*path/V1size/V1offset/a*reserved', 2 => 'a240id/V1size/V1offset/a*reserved');
     if ('/' === $archive[0] && ':' === $archive[2]) {
         $archive = substr($archive, 1);
         // Handle xar:///f:/archive.xar => f:/archive.xar
     }
     if (!isset($archives[$archive])) {
         $current = array('handle' => fopen($archive, 'rb'), 'dev' => crc32($archive));
         $header = unpack('a3id/c1version/V1indexsize/a*reserved', fread($current['handle'], 0x100));
         if ('CCA' != $header['id']) {
             \raise('lang.FormatException', 'Malformed archive ' . $archive);
         }
         for ($current['index'] = array(), $i = 0; $i < $header['indexsize']; $i++) {
             $entry = unpack($unpack[$header['version']], fread($current['handle'], 0x100));
             $current['index'][rtrim($entry['id'], "")] = array($entry['size'], $entry['offset'], $i);
         }
         $current['offset'] = 0x100 + $i * 0x100;
         $archives[$archive] = $current;
     }
     return $archives[$archive];
 }
 /**
  * Returns a header specified by its name
  *
  * @param   string name
  * @return  string value
  * @throws  lang.ElementNotFoundException
  */
 public function getHeader($name)
 {
     if ('Content-Type' === $name) {
         return $this->contentType;
     } else {
         if ('Accept' === $name) {
             return $this->accept;
         } else {
             foreach ($this->headers as $header) {
                 if ($name === $header->getName()) {
                     return $header->getValue();
                 }
             }
         }
     }
     raise('lang.ElementNotFoundException', 'No such header "' . $name . '"');
 }
earthli Projects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with earthli Projects; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

For more information about the earthli Projects, visit:

http://www.earthli.com/software/webcore/projects

****************************************************************************/
require_once 'projects/init.php';
// retrieve the tree of folders to guarantee that each folder
// is written before its children
$fn = $App->export_options->kind_file_name;
$fhandle = fopen($fn, 'w+');
if (!$fhandle) {
    raise("Could not open file [{$fn}] for kind export.");
}
fwrite($fhandle, "<?xml version=\"1.0\"?>\n");
fwrite($fhandle, "<OpusVCS>\n");
$indexed_kinds = $App->entry_kinds();
foreach ($indexed_kinds as $kind) {
    fwrite($fhandle, "<kind name=\"{$kind->title}\">\n");
    echo "Exported [{$kind->title}]<br>";
}
fwrite($fhandle, "</OpusVCS>\n");
 /**
  * Retrieve a stream to the resource
  *
  * @param   string filename name of resource
  * @return  io.File
  * @throws  lang.ElementNotFoundException in case the resource cannot be found
  */
 public function getResourceAsStream($filename)
 {
     if (!is_file($fn = $this->path . strtr($filename, '/', DIRECTORY_SEPARATOR))) {
         return raise('lang.ElementNotFoundException', 'Could not load resource ' . $filename);
     }
     return new File($fn);
 }
 /**
  * Creates underlying base for class loader, e.g. a directory or a .XAR file
  *
  * @return  net.xp_framework.unittest.reflection.ClassFromUriBase
  */
 protected static function baseImpl()
 {
     raise('lang.MethodNotImplementedException', 'Implement in subclass!', __FUNCTION__);
 }
 /**
  * Return properties by name
  *
  * @param   string name
  * @return  util.PropertyAccess
  * throws   lang.ElementNotFoundException
  */
 public function getProperties($name)
 {
     $found = array();
     foreach ($this->provider as $source) {
         if ($source->provides($name)) {
             $found[] = $source->fetch($name);
         }
     }
     switch (sizeof($found)) {
         case 1:
             return $found[0];
         case 0:
             raise('lang.ElementNotFoundException', sprintf('Cannot find properties "%s" in any of %s', $name, xp::stringOf(array_values($this->provider))));
         default:
             return new CompositeProperties($found);
     }
 }
 /**
  * Initialize this parser.
  */
 protected function initialize()
 {
     // Sections
     $this->withHandler('#', true, function ($tag, $state, $parse) {
         $parsed = $parse->options(trim(substr($tag, 1)));
         $state->parents[] = $state->target;
         $block = $state->target->add(BlockHelpers::newInstance(array_shift($parsed), $parsed, null, null, $state->start, $state->end));
         $state->target = $block->fn();
         $state->parents[] = $block;
     });
     $this->withHandler('/', true, function ($tag, $state) {
         $name = trim(substr($tag, 1));
         $block = array_pop($state->parents);
         if ($name !== $block->name()) {
             throw new TemplateFormatException('Illegal nesting, expected {{/' . $block->name() . '}}, have {{/' . $name . '}}');
         }
         $state->target = array_pop($state->parents);
     });
     // > partial
     $this->withHandler('>', true, function ($tag, $state, $parse) {
         $options = $parse->options(trim($tag));
         array_shift($options);
         $template = array_shift($options);
         if ($template instanceof Lookup) {
             $template = new Constant((string) $template);
         }
         $state->target->add(new PartialNode($template, $options, $state->padding));
     });
     // ! ... for comments
     $this->withHandler('!', true, function ($tag, $state) {
         $state->target->add(new CommentNode(trim(substr($tag, 1), ' ')));
     });
     // Change start and end
     $this->withHandler('=', true, function ($tag, $state) {
         list($state->start, $state->end) = explode(' ', trim(substr($tag, 1, -1)));
     });
     // & for unescaped
     $this->withHandler('&', false, function ($tag, $state, $parse) {
         $parsed = $parse->options(trim(substr($tag, 1)));
         $state->target->add('.' === $parsed[0] ? new IteratorNode(false) : new VariableNode($parsed[0], false, array_slice($parsed, 1)));
     });
     // triple mustache for unescaped
     $this->withHandler('{', false, function ($tag, $state, $parse) {
         $parsed = $parse->options(trim(substr($tag, 1)));
         $state->target->add('.' === $parsed[0] ? new IteratorNode(false) : new VariableNode($parsed[0], false, array_slice($parsed, 1)));
         return +1;
         // Skip "}"
     });
     // ^ is either an else by its own, or a negated block
     $this->withHandler('^', true, function ($tag, $state) {
         if ('^' === trim($tag)) {
             $block = cast($state->parents[sizeof($state->parents) - 1], 'com.handlebarsjs.BlockNode');
             $state->target = $block->inverse();
             return;
         }
         raise('lang.MethodNotImplementedException', '^blocks not yet implemented');
     });
     // Default
     $this->withHandler(null, false, function ($tag, $state, $parse) {
         $parsed = $parse->options(trim($tag));
         if ('.' === $parsed[0]) {
             $state->target->add(new IteratorNode(true));
             return;
         } else {
             if ('else' === $parsed[0] && $state->parents) {
                 $context = $state->parents[sizeof($state->parents) - 1];
                 if ($context instanceof BlockNode) {
                     $state->target = $context->inverse();
                     return;
                 }
                 // Fall through, "else" has no special meaning here.
             }
         }
         $state->target->add(new VariableNode($parsed[0], true, array_slice($parsed, 1)));
     });
 }
Esempio n. 12
0
 /**
  * Parses annotation string
  *
  * @param   string input
  * @param   string context the class name
  * @return  [:string] imports
  * @param   int line 
  * @return  [:var]
  * @throws  lang.ClassFormatException
  */
 public static function parseAnnotations($input, $context, $imports = array(), $line = -1)
 {
     static $states = array('annotation', 'annotation name', 'annotation value', 'annotation map key', 'annotation map value', 'multi-value');
     $tokens = token_get_all('<?php ' . trim($input, "[# \t\n\r"));
     $annotations = array(0 => array(), 1 => array());
     $place = $context . (-1 === $line ? '' : ', line ' . $line);
     // Resolve classes
     $resolve = function ($type, $context, $imports) {
         if ('self' === $type) {
             return XPClass::forName($context);
         } else {
             if ('parent' === $type) {
                 return XPClass::forName($context)->getParentclass();
             } else {
                 if (FALSE !== strpos($type, '.')) {
                     return XPClass::forName($type);
                 } else {
                     if (isset($imports[$type])) {
                         return XPClass::forName($imports[$type]);
                     } else {
                         if (isset(xp::$cn[$type])) {
                             return XPClass::forName(xp::$cn[$type]);
                         } else {
                             if (FALSE !== ($p = strrpos($context, '.'))) {
                                 return XPClass::forName(substr($context, 0, $p + 1) . $type);
                             } else {
                                 return XPClass::forName($type);
                             }
                         }
                     }
                 }
             }
         }
     };
     // Class::CONSTANT vs. Class::$MEMBER
     $memberOf = function ($tokens, &$i, $class) use($context) {
         if (T_VARIABLE === $tokens[$i][0]) {
             $field = $class->getField(substr($tokens[$i][1], 1));
             $m = $field->getModifiers();
             if ($m & MODIFIER_PUBLIC) {
                 return $field->get(NULL);
             } else {
                 if ($m & MODIFIER_PROTECTED && $class->isAssignableFrom($context)) {
                     return $field->setAccessible(TRUE)->get(NULL);
                 } else {
                     if ($m & MODIFIER_PRIVATE && $class->getName() === $context) {
                         return $field->setAccessible(TRUE)->get(NULL);
                     } else {
                         throw new IllegalAccessException(sprintf('Cannot access %s field %s::$%s', implode(' ', Modifiers::namesOf($m)), $class->getName(), $field->getName()));
                     }
                 }
             }
         } else {
             return $class->getConstant($tokens[$i][1]);
         }
     };
     // Parse a single value (recursively, if necessary)
     $valueOf = function ($tokens, &$i) use(&$valueOf, &$memberOf, &$resolve, $context, $imports) {
         if ('-' === $tokens[$i][0]) {
             $i++;
             return -1 * $valueOf($tokens, $i);
         } else {
             if ('+' === $tokens[$i][0]) {
                 $i++;
                 return +1 * $valueOf($tokens, $i);
             } else {
                 if (T_CONSTANT_ENCAPSED_STRING === $tokens[$i][0]) {
                     return eval('return ' . $tokens[$i][1] . ';');
                 } else {
                     if (T_LNUMBER === $tokens[$i][0]) {
                         return (int) $tokens[$i][1];
                     } else {
                         if (T_DNUMBER === $tokens[$i][0]) {
                             return (double) $tokens[$i][1];
                         } else {
                             if ('[' === $tokens[$i] || T_ARRAY === $tokens[$i][0]) {
                                 $value = array();
                                 $element = NULL;
                                 $key = 0;
                                 $end = '[' === $tokens[$i] ? ']' : ')';
                                 for ($i++, $s = sizeof($tokens);; $i++) {
                                     if ($i >= $s) {
                                         throw new IllegalStateException('Parse error: Unterminated array');
                                     } else {
                                         if ($end === $tokens[$i]) {
                                             $element && ($value[$key] = $element[0]);
                                             break;
                                         } else {
                                             if ('(' === $tokens[$i]) {
                                                 // Skip
                                             } else {
                                                 if (',' === $tokens[$i]) {
                                                     $element || raise('lang.IllegalStateException', 'Parse error: Malformed array - no value before comma');
                                                     $value[$key] = $element[0];
                                                     $element = NULL;
                                                     $key = sizeof($value);
                                                 } else {
                                                     if (T_DOUBLE_ARROW === $tokens[$i][0]) {
                                                         $key = $element[0];
                                                         $element = NULL;
                                                     } else {
                                                         if (T_WHITESPACE === $tokens[$i][0]) {
                                                             continue;
                                                         } else {
                                                             $element && raise('lang.IllegalStateException', 'Parse error: Malformed array - missing comma');
                                                             $element = array($valueOf($tokens, $i));
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 return $value;
                             } else {
                                 if ('"' === $tokens[$i] || T_ENCAPSED_AND_WHITESPACE === $tokens[$i][0]) {
                                     throw new IllegalStateException('Parse error: Unterminated string');
                                 } else {
                                     if (T_NS_SEPARATOR === $tokens[$i][0]) {
                                         $type = '';
                                         while (T_NS_SEPARATOR === $tokens[$i++][0]) {
                                             $type .= '.' . $tokens[$i++][1];
                                         }
                                         return $memberOf($tokens, $i, XPClass::forName(substr($type, 1)));
                                     } else {
                                         if (T_STRING === $tokens[$i][0]) {
                                             // constant vs. class::constant
                                             if (T_DOUBLE_COLON === $tokens[$i + 1][0]) {
                                                 $i += 2;
                                                 return $memberOf($tokens, $i, $resolve($tokens[$i - 2][1], $context, $imports));
                                             } else {
                                                 if (defined($tokens[$i][1])) {
                                                     return constant($tokens[$i][1]);
                                                 } else {
                                                     raise('lang.ElementNotFoundException', 'Undefined constant "' . $tokens[$i][1] . '"');
                                                 }
                                             }
                                         } else {
                                             if (T_NEW === $tokens[$i][0]) {
                                                 $type = '';
                                                 while ('(' !== $tokens[$i++]) {
                                                     if (T_STRING === $tokens[$i][0]) {
                                                         $type .= '.' . $tokens[$i][1];
                                                     }
                                                 }
                                                 $class = $resolve(substr($type, 1), $context, $imports);
                                                 for ($args = array(), $arg = NULL, $s = sizeof($tokens);; $i++) {
                                                     if (')' === $tokens[$i]) {
                                                         $arg && ($args[] = $arg[0]);
                                                         break;
                                                     } else {
                                                         if (',' === $tokens[$i]) {
                                                             $args[] = $arg[0];
                                                             $arg = NULL;
                                                         } else {
                                                             if (T_WHITESPACE !== $tokens[$i][0]) {
                                                                 $arg = array($valueOf($tokens, $i));
                                                             }
                                                         }
                                                     }
                                                 }
                                                 return $class->hasConstructor() ? $class->getConstructor()->newInstance($args) : $class->newInstance();
                                             } else {
                                                 throw new IllegalStateException(sprintf('Parse error: Unexpected %s', is_array($tokens[$i]) ? token_name($tokens[$i][0]) : '"' . $tokens[$i] . '"'));
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     };
     // Parse tokens
     try {
         for ($state = 0, $i = 1, $s = sizeof($tokens); $i < $s; $i++) {
             if (T_WHITESPACE === $tokens[$i][0]) {
                 continue;
             } else {
                 if (0 === $state) {
                     // Initial state, expecting @attr or @$param: attr
                     if ('@' === $tokens[$i]) {
                         $annotation = $tokens[$i + 1][1];
                         $param = NULL;
                         $value = NULL;
                         $i++;
                         $state = 1;
                     } else {
                         throw new IllegalStateException('Parse error: Expecting "@"');
                     }
                 } else {
                     if (1 === $state) {
                         // Inside attribute, check for values
                         if ('(' === $tokens[$i]) {
                             $state = 2;
                         } else {
                             if (',' === $tokens[$i]) {
                                 if ($param) {
                                     $annotations[1][$param][$annotation] = $value;
                                 } else {
                                     $annotations[0][$annotation] = $value;
                                 }
                                 $state = 0;
                             } else {
                                 if (']' === $tokens[$i]) {
                                     if ($param) {
                                         $annotations[1][$param][$annotation] = $value;
                                     } else {
                                         $annotations[0][$annotation] = $value;
                                     }
                                     return $annotations;
                                 } else {
                                     if (':' === $tokens[$i]) {
                                         $param = $annotation;
                                         $annotation = NULL;
                                     } else {
                                         if (T_STRING === $tokens[$i][0]) {
                                             $annotation = $tokens[$i][1];
                                         } else {
                                             throw new IllegalStateException('Parse error: Expecting either "(", "," or "]"');
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         if (2 === $state) {
                             // Inside braces of @attr(...)
                             if (')' === $tokens[$i]) {
                                 $state = 1;
                             } else {
                                 if (',' === $tokens[$i]) {
                                     trigger_error('Deprecated usage of multi-value annotations in ' . $place, E_USER_DEPRECATED);
                                     $value = (array) $value;
                                     $state = 5;
                                 } else {
                                     if ($i + 2 < $s && ('=' === $tokens[$i + 1] || '=' === $tokens[$i + 2])) {
                                         $key = $tokens[$i][1];
                                         $value = array();
                                         $state = 3;
                                     } else {
                                         $value = $valueOf($tokens, $i);
                                     }
                                 }
                             }
                         } else {
                             if (3 === $state) {
                                 // Parsing key inside @attr(a= b, c= d)
                                 if (')' === $tokens[$i]) {
                                     $state = 1;
                                 } else {
                                     if (',' === $tokens[$i]) {
                                         $key = null;
                                     } else {
                                         if ('=' === $tokens[$i]) {
                                             $state = 4;
                                         } else {
                                             if (is_array($tokens[$i])) {
                                                 $key = $tokens[$i][1];
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if (4 === $state) {
                                     // Parsing value inside @attr(a= b, c= d)
                                     $value[$key] = $valueOf($tokens, $i);
                                     $state = 3;
                                 } else {
                                     if (5 === $state) {
                                         if (')' === $tokens[$i]) {
                                             // BC: Deprecated multi-value annotations
                                             $value[] = $element;
                                             $state = 1;
                                         } else {
                                             if (',' === $tokens[$i]) {
                                                 $value[] = $element;
                                             } else {
                                                 $element = $valueOf($tokens, $i);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } catch (XPException $e) {
         raise('lang.ClassFormatException', $e->getMessage() . ' in ' . $place, $e);
     }
     raise('lang.ClassFormatException', 'Parse error: Unterminated ' . $states[$state] . ' in ' . $place);
 }
Esempio n. 13
0
 /**
  * Derive package from a given file
  *
  * @param  io.Folder folder
  * @return string
  * @throws lang.ElementNotFoundException
  */
 protected static function findPackageBy($folder)
 {
     $q = $folder->getURI();
     foreach (\lang\ClassLoader::getLoaders() as $loader) {
         if (0 === strncmp($q, $loader->path, $l = strlen($loader->path)) && $loader->providesPackage($package = strtr(substr($q, $l), DIRECTORY_SEPARATOR, '.'))) {
             return $package;
         }
     }
     raise('lang.ElementNotFoundException', 'Cannot derive package name from ' . $q);
 }
 /**
  * Read central directory; not supported in this abstract
  * implementation.
  *
  * @return  void
  */
 protected function readCentralDirectory()
 {
     raise('lang.MethodNotImplementedException', 'Seeking central directory is only supported by RandomAccessZipReaderImpl.');
 }
Esempio n. 15
0
 /**
  * Retrieve annotation by name
  *
  * @param   string name
  * @param   string key default NULL
  * @return  var
  * @throws  lang.ElementNotFoundException
  */
 public function getAnnotation($name, $key = NULL)
 {
     $n = '$' . $this->_reflect->getName();
     if (!($details = XPClass::detailsForMethod($this->_details[0], $this->_details[1])) || !isset($details[DETAIL_TARGET_ANNO][$n]) || !($key ? array_key_exists($key, (array) @$details[DETAIL_TARGET_ANNO][$n][$name]) : array_key_exists($name, (array) @$details[DETAIL_TARGET_ANNO][$n]))) {
         return raise('lang.ElementNotFoundException', 'Annotation "' . $name . ($key ? '.' . $key : '') . '" does not exist');
     }
     return $key ? $details[DETAIL_TARGET_ANNO][$n][$name][$key] : $details[DETAIL_TARGET_ANNO][$n][$name];
 }
Esempio n. 16
0
 /**
  * Clone interceptor - ensures enums cannot be cloned
  *
  * @throws  lang.CloneNotSupportedException
  */
 public final function __clone()
 {
     raise('lang.CloneNotSupportedException', 'Enums cannot be cloned');
 }
 /**
  * Load the class by the specified name
  *
  * @param   string class fully qualified class name io.File
  * @return  string class name
  * @throws  lang.ClassNotFoundException in case the class can not be found
  * @throws  lang.ClassFormatException in case the class format is invalud
  */
 public function loadClass0($class)
 {
     if (isset(xp::$cl[$class])) {
         return xp::reflect($class);
     }
     // Load class
     $package = NULL;
     xp::$cl[$class] = $this->getClassName() . '://' . $this->path;
     xp::$cll++;
     try {
         $r = (include $this->classUri($class));
     } catch (ClassLoadingException $e) {
         xp::$cll--;
         $decl = NULL;
         if (NULL === $package) {
             $decl = substr($class, FALSE === ($p = strrpos($class, '.')) ? 0 : $p + 1);
         } else {
             $decl = strtr($class, '.', '·');
         }
         // If class was declared, but loading threw an exception it means
         // a "soft" dependency, one that is only required at runtime, was
         // not loaded, the class itself has been declared.
         if (class_exists($decl, FALSE) || interface_exists($decl, FALSE)) {
             raise('lang.ClassDependencyException', $class, array($this), $e);
         }
         // If otherwise, a "hard" dependency could not be loaded, eg. the
         // base class or a required interface and thus the class could not
         // be declared.
         raise('lang.ClassLinkageException', $class, array($this), $e);
     }
     xp::$cll--;
     if (FALSE === $r) {
         unset(xp::$cl[$class]);
         throw new ClassNotFoundException($class, array($this));
     }
     // Register it
     if (NULL === $package) {
         if (FALSE === ($p = strrpos($class, '.'))) {
             $name = $class;
         } else {
             $name = substr($class, $p + 1);
             if (!class_exists($name, FALSE) && !interface_exists($name, FALSE)) {
                 $name = strtr($class, '.', '\\');
                 if (!class_exists($name, FALSE) && !interface_exists($name, FALSE)) {
                     unset(xp::$cl[$class]);
                     raise('lang.ClassFormatException', 'Class "' . $name . '" not declared in loaded file');
                 }
             } else {
                 class_alias($name, strtr($class, '.', '\\'));
             }
         }
     } else {
         $name = strtr($class, '.', '·');
         class_alias($name, strtr($class, '.', '\\'));
     }
     xp::$cn[$name] = $class;
     method_exists($name, '__static') && (xp::$cli[] = array($name, '__static'));
     if (0 === xp::$cll) {
         $invocations = xp::$cli;
         xp::$cli = array();
         foreach ($invocations as $inv) {
             call_user_func($inv);
         }
     }
     return $name;
 }
Esempio n. 18
0
 /**
  * Internal error-handling.
  * @param string $msg
  * @access private
  */
 public function halt($msg)
 {
     DB_Sql::halt($msg);
     include_once 'webcore/obj/webcore_object.php';
     raise("{$msg} (MySQL Error = {$this->Errno}, {$this->Error})", 'halt', 'DATABASE', $this);
 }
Esempio n. 19
0
 /**
  * Sends a raw command directly to the FTP-Server.
  *
  * Please note, that the function does not parse whether the 
  * command was successful or not.
  *
  * @deprecated Use sendCommand() instead!
  * @param   string command
  * @return  array ServerResponse
  */
 public function quote($command)
 {
     raise('lang.MethodNotImplementedException', 'Deprecated', 'FtpConnection::quote');
 }
Esempio n. 20
0
 /**
  * Retrieve annotation by name
  *
  * @param   string name
  * @param   string key default NULL
  * @return  var
  * @throws  lang.ElementNotFoundException
  */
 public function getAnnotation($name, $key = NULL)
 {
     $details = XPClass::detailsForMethod($this->_reflect->getDeclaringClass()->getName(), $this->_reflect->getName());
     if (!$details || !($key ? array_key_exists($key, @$details[DETAIL_ANNOTATIONS][$name]) : array_key_exists($name, @$details[DETAIL_ANNOTATIONS]))) {
         return raise('lang.ElementNotFoundException', 'Annotation "' . $name . ($key ? '.' . $key : '') . '" does not exist');
     }
     return $key ? $details[DETAIL_ANNOTATIONS][$name][$key] : $details[DETAIL_ANNOTATIONS][$name];
 }
 /**
  * Retrieve transaction state
  *
  * @param   string name
  * @return  var state
  */
 public function transtate($name)
 {
     raise('lang.MethodNotImplementedException', __FUNCTION__ . ' is not supported.');
 }
 /**
  * Stream wrapper method stream_open
  *
  * @param   string path
  * @param   int mode
  * @param   int options
  * @param   string opened_path
  * @return  bool
  */
 public function stream_open($path, $mode, $options, $opened_path)
 {
     sscanf($path, 'dyn://%[^$]', $this->current);
     if (!isset(self::$bytes[$this->current])) {
         raise('lang.ElementNotFoundException', 'Could not load ' . $this->current);
     }
     return TRUE;
 }
 /**
  * Create transactions table
  *
  * @param   string name
  */
 protected function createTransactionsTable($name)
 {
     raise('lang.MethodNotImplementedException', __FUNCTION__);
 }
Esempio n. 24
0
 /**
  * Stops execution by raising a SystemExit
  *
  * @see     xp://lang.SystemExit
  * @param   int code default 0
  * @param   string message default NULL
  */
 public static function halt($code = 0, $message = NULL)
 {
     raise('lang.SystemExit', $code, $message);
 }
Esempio n. 25
0
 /**
  * Stop execution with a message.
  * Similar to {@link PHP_MANUAL#die}, but allows logging and exception
  * handling to function properly.
  * @param string $msg
  */
 public function halt($msg = 'Process halted.')
 {
     raise($msg, '[unknown]', get_class($this), $this, $this->_exception_handler());
 }
Esempio n. 26
0
            echo "Exported [" . $folder->title_as_plain_text() . "]<br>";
            // export sub folders
            process_folders($folder->sub_folders(), $depth);
        }
    }
    $depth -= 1;
}
require_once 'projects/init.php';
$deployment = $_REQUEST['deployment'];
if (!$deployment) {
    $deployment = 'opus';
}
$fn = $App->xml_options->export_file_name;
$fhandle = fopen($fn, 'w+');
if (!$fhandle) {
    raise("Could not open file [{$fn}] for folder export.");
}
fwrite($fhandle, "<?xml version=\"1.0\"?>\n");
fwrite($fhandle, "<OpusVCS>\n");
$Page->start_display();
$folder_query = $App->login->folder_query();
if ($deployment == 'opus') {
    $App->database->set_database('opus_internal');
    // retrieve the tree of folders to guarantee that each folder
    // is written before its children
    $folder_query->set_order("fldr.title, perm.type DESC");
}
$folders = $folder_query->tree();
fwrite($fhandle, "  <earthliProjects>\n");
fwrite($fhandle, "    <folderList>\n");
echo "<h3>Exporting folders...</h3>";
 public static function fromChallenge($header, $user, $pass)
 {
     raise('lang.MethodNotImplementedException', __METHOD__, 'Should be abstract');
 }
 /**
  * Write to stream. Unsupported
  *
  * @param   string data
  * @return  int
  */
 public function stream_write($data)
 {
     raise('lang.MethodNotImplementedException', 'Not writeable.', __METHOD__);
 }
$fhandle = @fopen($fn, 'r');
if (!$fhandle) {
    log_message("File [{$fn}] was not found. No objects imported.", Msg_type_warning, Msg_channel_xml);
    $Logger->close();
} else {
    $indexed_kinds = $App->entry_kinds();
    foreach ($indexed_kinds as $kind) {
        $kinds[strtolower($kind->title)] = $kind;
    }
    $App->impersonate($App->mail_options->publisher_user_name, $App->mail_options->publisher_user_password);
    $folder_query = $App->login->folder_query();
    $folders = $folder_query->indexed_objects();
    $App->display_options->show_local_times = false;
    while ($data = fread($fhandle, 4096)) {
        if (!xml_parse($xml_parser, $data, feof($fhandle))) {
            raise(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
        }
    }
    xml_parser_free($xml_parser);
    $commit = !read_var('testing');
    if (isset($errors_occurred)) {
        log_message("[{$errors_occurred}] errors detected. Objects not imported.", Msg_type_warning, Msg_channel_xml);
    } else {
        if ($commit) {
            $action = 'Imported';
        } else {
            $action = 'Found';
        }
        $count = sizeof($objs);
        log_message("[{$count}] changes found. Importing...", Msg_type_info, Msg_channel_xml);
        $index = 0;
 /**
  * @param ENVIRONMENT $env Global environment.
  * @param string $handler_url Redirect exceptions to this url.
  */
 public function __construct($env)
 {
     if (!$env->exception_handler_page) {
         raise('Exception handler URL cannot be empty.', 'REDIRECT_EXCEPTION_HANDLER', 'REDIRECT_EXCEPTION_HANDLER');
     }
     $this->env = $env;
 }