本文整理汇总了PHP中ReflectionMethod::getFileName方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionMethod::getFileName方法的具体用法?PHP ReflectionMethod::getFileName怎么用?PHP ReflectionMethod::getFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionMethod
的用法示例。
在下文中一共展示了ReflectionMethod::getFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseMethod
private function parseMethod($class, $method)
{
$refl = new \ReflectionMethod($class, $method);
// var_dump($refl->getFileName());
// var_dump($refl->getStartLine());
// var_dump($refl->getEndLine());
$body = trim(implode(array_slice(file($refl->getFileName()), $refl->getStartLine(), $refl->getEndLine() - $refl->getStartLine() - 1)));
$spec = $this->createSpecification($body, $refl->getFileName(), $refl->getStartLine(), $refl->getEndLine());
return $spec;
}
示例2: isValid
public static function isValid()
{
if (!assert_options(ASSERT_ACTIVE)) {
return true;
}
$bt = self::debugBacktrace(null, 1);
extract($bt);
//to $file, $line, $function, $class, $object, $type, $args
if (!$args) {
return true;
}
#speed improve
$r = new ReflectionMethod($class, $function);
$doc = $r->getDocComment();
$cache_id = $class . $type . $function;
preg_match_all('~ [\\r\\n]++ [\\x20\\t]++ \\* [\\x20\\t]++
@param
[\\x20\\t]++
\\K #memory reduce
( [_a-z]++[_a-z\\d]*+
(?>[|/,][_a-z]+[_a-z\\d]*)*+
) #1 types
[\\x20\\t]++
&?+\\$([_a-z]++[_a-z\\d]*+) #2 name
~sixSX', $doc, $params, PREG_SET_ORDER);
$parameters = $r->getParameters();
//d($args, $params, $parameters);
if (count($parameters) > count($params)) {
$message = 'phpDoc %d piece(s) @param description expected in %s%s%s(), %s given, ' . PHP_EOL . 'called in %s on line %d ' . PHP_EOL . 'and defined in %s on line %d';
$message = sprintf($message, count($parameters), $class, $type, $function, count($params), $file, $line, $r->getFileName(), $r->getStartLine());
trigger_error($message, E_USER_NOTICE);
}
foreach ($args as $i => $value) {
if (!isset($params[$i])) {
return true;
}
if ($parameters[$i]->name !== $params[$i][2]) {
$param_num = $i + 1;
$message = 'phpDoc @param %d in %s%s%s() must be named as $%s, $%s given, ' . PHP_EOL . 'called in %s on line %d ' . PHP_EOL . 'and defined in %s on line %d';
$message = sprintf($message, $param_num, $class, $type, $function, $parameters[$i]->name, $params[$i][2], $file, $line, $r->getFileName(), $r->getStartLine());
trigger_error($message, E_USER_NOTICE);
}
$hints = preg_split('~[|/,]~sSX', $params[$i][1]);
if (!self::checkValueTypes($hints, $value)) {
$param_num = $i + 1;
$message = 'Argument %d passed to %s%s%s() must be an %s, %s given, ' . PHP_EOL . 'called in %s on line %d ' . PHP_EOL . 'and defined in %s on line %d';
$message = sprintf($message, $param_num, $class, $type, $function, implode('|', $hints), (is_object($value) ? get_class($value) . ' ' : '') . gettype($value), $file, $line, $r->getFileName(), $r->getStartLine());
trigger_error($message, E_USER_WARNING);
return false;
}
}
return true;
}
示例3: getMethodOwner
/**
* @param \ReflectionMethod $reflectionMethod
* @param int $methodStartLine
* @param int $methodEndLine
*
* @return \ReflectionClass
*/
private function getMethodOwner(\ReflectionMethod $reflectionMethod, $methodStartLine, $methodEndLine)
{
$reflectionClass = $reflectionMethod->getDeclaringClass();
$fileName = $reflectionMethod->getFileName();
$trait = $this->getDeclaringTrait($reflectionClass->getTraits(), $fileName, $methodStartLine, $methodEndLine);
return $trait === null ? $reflectionClass : $trait;
}
示例4: getRawBody
public function getRawBody()
{
$method = new \ReflectionMethod($this->testClassInstance, $this->testMethod);
$start_line = $method->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
$end_line = $method->getEndLine();
$source = file($method->getFileName());
return implode("", array_slice($source, $start_line, $end_line - $start_line));
}
示例5: getFileName
/**
* Returns the filename of the file this function was declared in
*
* @return string Filename of the file this function was declared in
*/
public function getFileName()
{
if ($this->reflectionSource instanceof ReflectionMethod) {
return $this->reflectionSource->getFileName();
} else {
return parent::getFileName();
}
}
示例6: getMethodBodyAndDocComment
public static function getMethodBodyAndDocComment($cls, $mtd)
{
$func = new \ReflectionMethod($cls, $mtd);
$start_line = $func->getStartLine() + 1;
$length = $func->getEndLine() - $start_line - 1;
$lines = array_slice(file($func->getFileName()), $start_line, $length);
return array(implode('', $lines), $func->getDocComment());
}
示例7: getMethodSource
static function getMethodSource(ReflectionMethod $method)
{
$path = $method->getFileName();
$lines = @file($path);
$from = $method->getStartLine();
$to = $method->getEndLine();
$len = $to - $from + 1;
return implode(array_slice($lines, $from - 1, $len));
}
示例8: _getCode
/**
* Get the source code for the method
*
* @param \ReflectionMethod $method
*
* @return string
*/
protected function _getCode(\ReflectionMethod $method)
{
$filename = $method->getFileName();
$start_line = $method->getStartLine() + 1;
$end_line = $method->getEndLine() - 1;
$length = $end_line - $start_line;
$source = file($filename);
return preg_replace('/^\\s{4}/m', '', implode("", array_slice($source, $start_line, $length)));
}
示例9: checkMethodsInNewClasses
/**
* @param ReflectionMethod[] $methods
*/
private function checkMethodsInNewClasses($methods)
{
foreach ($methods as $method) {
list($expectedMethod, $class) = $this->explodeCamel($method->getName());
$this->assertTrue(method_exists($class, $expectedMethod), 'Method ' . $expectedMethod . ' is not found in class ' . $class);
$newMethod = new ReflectionMethod($class, $expectedMethod);
$this->assertEquals($method->getModifiers(), $newMethod->getModifiers(), 'Incorrect modifier for ' . $class . '::' . $expectedMethod);
$this->assertEquals(substr_count(file_get_contents($method->getFileName()), $method->getName()), substr_count(file_get_contents($newMethod->getFileName()), $newMethod->getName()), 'Incorrect usage for ' . $class . '::' . $expectedMethod);
}
}
示例10: sourceMethod
function sourceMethod(\ReflectionMethod $method)
{
$filename = $method->getFileName();
$start_line = $method->getStartLine() - 1;
// it's actually - 1, otherwise you wont get the function() block
$end_line = $method->getEndLine();
$length = $end_line - $start_line;
$source = file($filename);
$body = implode("", array_slice($source, $start_line, $length));
return $method->getDocComment() . PHP_EOL . $body;
}
示例11: testImplementationsAreSynchronized
public function testImplementationsAreSynchronized()
{
$adapterReflector = new ReflectionMethod('ehough_finder_adapter_PhpAdapter', 'searchInDirectory');
$finderReflector = new ReflectionMethod('ehough_finder_Finder', 'searchInDirectory');
$adapterSource = array_slice(file($adapterReflector->getFileName()), $adapterReflector->getStartLine() + 1, $adapterReflector->getEndLine() - $adapterReflector->getStartLine() - 1);
$adapterSource = implode('', $adapterSource);
$adapterSource = str_replace(array('$this->minDepth', '$this->maxDepth'), array('$minDepth', '$maxDepth'), $adapterSource);
$finderSource = array_slice(file($finderReflector->getFileName()), $finderReflector->getStartLine() + 1, $finderReflector->getEndLine() - $finderReflector->getStartLine() - 1);
$finderSource = implode('', $finderSource);
$this->assertStringEndsWith($adapterSource, $finderSource);
}
示例12: getMethodOwner
/**
* @param \ReflectionMethod $reflectionMethod
* @param int $methodStartLine
* @param int $methodEndLine
*
* @return \ReflectionClass
*/
private function getMethodOwner(\ReflectionMethod $reflectionMethod, $methodStartLine, $methodEndLine)
{
$reflectionClass = $reflectionMethod->getDeclaringClass();
// PHP <=5.3 does not handle traits
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
return $reflectionClass;
}
$fileName = $reflectionMethod->getFileName();
$trait = $this->getDeclaringTrait($reflectionClass->getTraits(), $fileName, $methodStartLine, $methodEndLine);
return $trait === null ? $reflectionClass : $trait;
}
示例13: test_populate_callback_static_method_string
public function test_populate_callback_static_method_string()
{
$function = 'QM_Test_Object::hello';
$callback = self::get_callback($function);
$ref = new ReflectionMethod('QM_Test_Object', 'hello');
$actual = QM_Util::populate_callback($callback);
$this->assertEquals(array('QM_Test_Object', 'hello'), $actual['function']);
$this->assertEquals('QM_Test_Object::hello()', $actual['name']);
$this->assertEquals($ref->getFileName(), $actual['file']);
$this->assertEquals($ref->getStartLine(), $actual['line']);
}
示例14: testDrupal
/**
* Test the complete Drupal migration.
*/
public function testDrupal()
{
$dumps = $this->getDumps();
$this->loadDumps($dumps);
$classes = $this->getTestClassesList();
$extension_install_storage = new ExtensionInstallStorage(\Drupal::service('config.storage'), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE);
foreach ($classes as $class) {
if (is_subclass_of($class, '\\Drupal\\migrate\\Tests\\MigrateDumpAlterInterface')) {
$class::migrateDumpAlter($this);
}
}
// Run every migration in the order specified by the storage controller.
foreach (entity_load_multiple('migration', static::$migrations) as $migration) {
(new MigrateExecutable($migration, $this))->import();
// Ensure that the default migration has the correct dependencies.
list($base_name, ) = explode(':', $migration->id(), 2);
$default_configuration = $extension_install_storage->read('migrate.migration.' . $base_name);
$default_dependencies = isset($default_configuration['dependencies']) ? $default_configuration['dependencies'] : [];
$this->assertEqual($default_dependencies, $migration->getDependencies(), SafeMarkup::format('Dependencies in @id match after installing. Default configuration @first is equal to active configuration @second.', array('@id' => $migration->id(), '@first' => var_export($default_dependencies, TRUE), '@second' => var_export($migration->getDependencies(), TRUE))));
}
foreach ($classes as $class) {
$test_object = new $class($this->testId);
$test_object->databasePrefix = $this->databasePrefix;
$test_object->container = $this->container;
// run() does a lot of setup and tear down work which we don't need:
// it would setup a new database connection and wouldn't find the
// Drupal dump. Also by skipping the setUp() methods there are no id
// mappings or entities prepared. The tests run against solely migrated
// data.
foreach (get_class_methods($test_object) as $method) {
if (strtolower(substr($method, 0, 4)) == 'test') {
// Insert a fail record. This will be deleted on completion to ensure
// that testing completed.
$method_info = new \ReflectionMethod($class, $method);
$caller = array('file' => $method_info->getFileName(), 'line' => $method_info->getStartLine(), 'function' => $class . '->' . $method . '()');
$completion_check_id = TestBase::insertAssert($this->testId, $class, FALSE, 'The test did not complete due to a fatal error.', 'Completion check', $caller);
// Run the test method.
try {
$test_object->{$method}();
} catch (\Exception $e) {
$this->exceptionHandler($e);
}
// Remove the completion check record.
TestBase::deleteAssert($completion_check_id);
}
}
// Add the pass/fail/exception/debug results.
foreach ($this->results as $key => &$value) {
$value += $test_object->results[$key];
}
}
}
示例15: collect
/**
* Called by the DebugBar when data needs to be collected
* @return array Collected data
*/
function collect()
{
$dispatcher = $this->di['dispatcher'];
$router = $this->di['router'];
$route = $router->getMatchedRoute();
if (!$route) {
return array();
}
$uri = $route->getPattern();
$paths = $route->getPaths();
$result['uri'] = $uri ?: '-';
$result['paths'] = $this->formatVar($paths);
if ($params = $router->getParams()) {
$result['params'] = $this->formatVar($params);
}
$result['HttpMethods'] = $route->getHttpMethods();
$result['RouteName'] = $route->getName();
$result['hostname'] = $route->getHostname();
if ($this->di->has('app') && ($app = $this->di['app']) instanceof Micro) {
if (($handler = $app->getActiveHandler()) instanceof \Closure || is_string($handler)) {
$reflector = new \ReflectionFunction($handler);
} elseif (is_array($handler)) {
$reflector = new \ReflectionMethod($handler[0], $handler[1]);
}
} else {
$result['Moudle'] = $router->getModuleName();
$result['Controller'] = get_class($controller_instance = $dispatcher->getActiveController());
$result['Action'] = $dispatcher->getActiveMethod();
$reflector = new \ReflectionMethod($controller_instance, $result['Action']);
}
if (isset($reflector)) {
$start = $reflector->getStartLine() - 1;
$stop = $reflector->getEndLine();
$filename = substr($reflector->getFileName(), mb_strlen(realpath(dirname($_SERVER['DOCUMENT_ROOT']))));
$code = array_slice(file($reflector->getFileName()), $start, $stop - $start);
$result['file'] = $filename . ':' . $reflector->getStartLine() . '-' . $reflector->getEndLine() . " [CODE]: \n" . implode("", $code);
}
return array_filter($result);
}