/** * Import a PHP file * @param string $path Path to the PHP file * @param mixed $classpath String or object supporting __toString() * @throws BuildException - if cannot find the specified file */ public static function __import($path, $classpath = null) { if ($classpath) { // Apparently casting to (string) no longer invokes __toString() automatically. if (is_object($classpath)) { $classpath = $classpath->__toString(); } // classpaths are currently additive, but we also don't want to just // indiscriminantly prepand/append stuff to the include_path. This means // we need to parse current incldue_path, and prepend any // specified classpath locations that are not already in the include_path. // // NOTE: the reason why we do it this way instead of just changing include_path // and then changing it back, is that in many cases applications (e.g. Propel) will // include/require class files from within method calls. This means that not all // necessary files will be included in this import() call, and hence we can't // change the include_path back without breaking those apps. While this method could // be more expensive than switching & switching back (not sure, but maybe), it makes it // possible to write far less expensive run-time applications (e.g. using Propel), which is // really where speed matters more. $curr_parts = explode(PATH_SEPARATOR, ini_get('include_path')); $add_parts = explode(PATH_SEPARATOR, $classpath); $new_parts = array_diff($add_parts, $curr_parts); if ($new_parts) { if (self::getMsgOutputLevel() === PROJECT_MSG_DEBUG) { print "Phing::import() prepending new include_path components: " . implode(PATH_SEPARATOR, $new_parts) . "\n"; } ini_set('include_path', implode(PATH_SEPARATOR, array_merge($new_parts, $curr_parts))); } } $ret = (include_once $path); if ($ret === false) { $e = new BuildException("Error importing {$path}"); if (self::getMsgOutputLevel() === PROJECT_MSG_DEBUG) { // We can't log this because listeners belong // to projects. We'll just print it -- of course // that isn't very compatible w/ other frontends (but // there aren't any right now, so I'm not stressing) print "Error importing {$path}\n"; print $e->getTraceAsString() . "\n"; } throw $e; } return; }