当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionMethod::getFileName方法代码示例

本文整理汇总了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;
 }
开发者ID:ribozz,项目名称:PhpSpock,代码行数:10,代码来源:SpecificationParser.php

示例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;
    }
开发者ID:kostapc,项目名称:php-lang-correct,代码行数:53,代码来源:ReflectionTypeHint.php

示例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;
 }
开发者ID:phpspec,项目名称:phpspec,代码行数:14,代码来源:MethodAnalyser.php

示例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));
 }
开发者ID:Vrian7ipx,项目名称:cascadadev,代码行数:8,代码来源:Cest.php

示例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();
     }
 }
开发者ID:naderman,项目名称:ezc-reflection,代码行数:13,代码来源:method.php

示例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());
 }
开发者ID:cal127,项目名称:phpcrud,代码行数:8,代码来源:Helpers.php

示例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));
 }
开发者ID:jabouzi,项目名称:projet,代码行数:9,代码来源:listing5.29.php

示例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)));
 }
开发者ID:fortifi,项目名称:ui,代码行数:16,代码来源:AbstractUiExampleView.php

示例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);
     }
 }
开发者ID:kokareff,项目名称:hr-test-2,代码行数:13,代码来源:Test_Checker_S.php

示例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;
 }
开发者ID:larakit,项目名称:lk,代码行数:11,代码来源:AdminCodegenModelController.php

示例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);
 }
开发者ID:ehough,项目名称:finder,代码行数:11,代码来源:PhpFinderTest.php

示例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;
 }
开发者ID:focuslife,项目名称:v0.1,代码行数:18,代码来源:MethodAnalyser.php

示例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']);
 }
开发者ID:robwilde,项目名称:query-monitor,代码行数:11,代码来源:test-stack-traces.php

示例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];
         }
     }
 }
开发者ID:jeyram,项目名称:camp-gdl,代码行数:55,代码来源:MigrateFullDrupalTestBase.php

示例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);
 }
开发者ID:minhlaoleu,项目名称:phalcon-debugbar,代码行数:43,代码来源:RouteCollector.php


注:本文中的ReflectionMethod::getFileName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。