Chris@0: isRequireNode($origNode)) { Chris@0: return; Chris@0: } Chris@0: Chris@0: $node = clone $origNode; Chris@0: Chris@0: /* Chris@0: * rewrite Chris@0: * Chris@0: * $foo = require $bar Chris@0: * Chris@0: * to Chris@0: * Chris@0: * $foo = require \Psy\CodeCleaner\RequirePass::resolve($bar) Chris@0: */ Chris@0: $node->expr = new StaticCall( Chris@0: new FullyQualifiedName('Psy\CodeCleaner\RequirePass'), Chris@0: 'resolve', Chris@0: array(new Arg($origNode->expr), new Arg(new LNumber($origNode->getLine()))), Chris@0: $origNode->getAttributes() Chris@0: ); Chris@0: Chris@0: return $node; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Runtime validation that $file can be resolved as an include path. Chris@0: * Chris@0: * If $file can be resolved, return $file. Otherwise throw a fatal error exception. Chris@0: * Chris@0: * @throws FatalErrorException when unable to resolve include path for $file Chris@0: * @throws ErrorException if $file is empty and E_WARNING is included in error_reporting level Chris@0: * Chris@0: * @param string $file Chris@0: * @param int $lineNumber Line number of the original require expression Chris@0: * Chris@0: * @return string Exactly the same as $file Chris@0: */ Chris@0: public static function resolve($file, $lineNumber = null) Chris@0: { Chris@0: $file = (string) $file; Chris@0: Chris@0: if ($file === '') { Chris@0: // @todo Shell::handleError would be better here, because we could Chris@0: // fake the file and line number, but we can't call it statically. Chris@0: // So we're duplicating some of the logics here. Chris@0: if (E_WARNING & error_reporting()) { Chris@0: ErrorException::throwException(E_WARNING, 'Filename cannot be empty', null, $lineNumber); Chris@0: } else { Chris@0: // @todo trigger an error as fallback? this is pretty ugly… Chris@0: // trigger_error('Filename cannot be empty', E_USER_WARNING); Chris@0: } Chris@0: } Chris@0: Chris@0: if ($file === '' || !stream_resolve_include_path($file)) { Chris@0: $msg = sprintf("Failed opening required '%s'", $file); Chris@0: throw new FatalErrorException($msg, 0, E_ERROR, null, $lineNumber); Chris@0: } Chris@0: Chris@0: return $file; Chris@0: } Chris@0: Chris@0: private function isRequireNode(Node $node) Chris@0: { Chris@0: return $node instanceof Include_ && in_array($node->type, self::$requireTypes); Chris@0: } Chris@0: }