本文整理汇总了PHP中ReflectionClass::getEndLine方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getEndLine方法的具体用法?PHP ReflectionClass::getEndLine怎么用?PHP ReflectionClass::getEndLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getEndLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEndLine
/**
* Gets the line where the class definition ends
* @return Integer
*/
public function getEndLine()
{
$e = $this->reflection->getEndLine();
if (!$e || !$this->getFileName()) {
return NULL;
}
return $e;
}
示例2: getClassBody
/**
* Возвращает тело класса/интерфейса
*/
public function getClassBody()
{
$lines = $this->di->getFileLines(true, true);
$firstLine = $this->rc->getStartLine();
$endLine = $this->rc->getEndLine();
if ($endLine <= $firstLine + 1) {
return '';
}
return trim(implode('', array_slice($lines, $firstLine, $endLine - $firstLine - 1)));
}
示例3: reflect
public function reflect()
{
$this->load->library('calendar');
$reflect = new ReflectionClass('CI_Calendar');
echo $reflect->getStartLine();
$path = $reflect->getFileName();
$temp = @file($path);
echo $reflect->getEndLine();
$len = $reflect->getEndLine() - $reflect->getStartLine() + 1;
echo implode(array_slice($temp, $reflect->getStartLine() - 1, $len));
// foreach ($func->getParameters() as $param)
// {
// echo $param,'<br>';
// }
}
示例4: buildAllFile
public function buildAllFile() : array
{
$path = $this->getPath();
if (!is_file($path)) {
throw new \Exception("The file {$path} not found!");
}
if (!is_readable($path)) {
throw new \Exception("The file {$path} not readable!");
}
if (!is_writeable($path)) {
throw new \Exception("The file {$path} not writable!");
}
$endLine = $this->reflection->getEndLine();
$insertLine = $endLine - 1;
$handle = @fopen($path, 'r');
$index = 0;
$result = [];
while (($buffer = fgets($handle, 4096)) !== false) {
$index++;
$result[] = $buffer;
if ($index === $insertLine) {
$result[] = $this->buildMethodBody($this->method);
}
}
return $result;
}
示例5: generate
public function generate($withTargets = true)
{
$shortClassName = $this->reflectionClass->getShortName();
EntityCodeGenerator::process($this->twigEngine, $this->reflectionClass->getFileName(), $this->getMethodsStartLine($this->reflectionClass, $this->reflectionClass->getFileName()), $this->reflectionClass->getEndLine(), $this->reflectionClass->getNamespaceName(), $this->namespace, $this->getExistMethods($this->reflectionClass), $this->getExistProperties($this->reflectionClass), $this->properties);
if (!$withTargets) {
return;
}
foreach ($this->usedTargets as $targetName) {
$target = $this->targets[$targetName];
/* @var $target Target */
$namespace = $target->getNamespace() . ($this->localNamespace ? '\\' . $this->localNamespace : '');
$filename = $this->srcDir . '/' . str_replace('\\', '/', $namespace) . '/' . $shortClassName . '.php';
$className = $namespace . '\\' . $shortClassName;
if (is_readable($filename)) {
if (!class_exists($className)) {
throw $this->getClassException('Filename "' . $filename . '" exists but class "$s" not. Fix it or remove class file before generation.');
}
$isNew = false;
} else {
if (class_exists($className)) {
throw $this->getClassException('Filename "' . $filename . '" not exists but class "$s" is. Fix it before generating.');
}
$isNew = true;
}
$properties = $this->getPropertiesForTarget($target->getName());
if ($isNew) {
EntityCodeGenerator::processNew($this->twigEngine, $filename, $namespace, $target->getNamespace(), $shortClassName, $properties, $target->isWithAnnotations(), $target->isUseClassNotations(), $target->isWithInitFunction());
} else {
$reflectionClass = new \ReflectionClass($className);
EntityCodeGenerator::process($this->twigEngine, $reflectionClass->getFileName(), $this->getMethodsStartLine($reflectionClass, $reflectionClass->getFileName()), $reflectionClass->getEndLine(), $reflectionClass->getNamespaceName(), $target->getNamespace(), $this->getExistMethods($reflectionClass), $this->getExistProperties($reflectionClass), $properties, $target->isWithAnnotations(), $target->isUseClassNotations());
}
}
}
示例6: getClassSource
static function getClassSource(ReflectionClass $class)
{
$path = $class->getFileName();
$lines = @file($path);
$from = $class->getStartLine();
$to = $class->getEndLine();
$len = $to - $from + 1;
return implode(array_slice($lines, $from - 1, $len));
}
示例7: appendContent
public function appendContent($class, $content)
{
$reflection = new ReflectionClass($class);
$lastLine = $reflection->getEndLine() - 1;
$file = file($reflection->getFileName());
$beginning = array_slice($file, 0, $lastLine);
$end = array_slice($file, $lastLine);
unset($file);
return (bool) file_put_contents($reflection->getFileName(), implode('', $beginning) . PHP_EOL . $content . PHP_EOL . implode('', $end));
}
示例8: _createFromReflection
/**
* @param ReflectionClass $reflection
*/
protected function _createFromReflection($reflection)
{
$this->_className = $reflection->getName();
$this->_endLine = $reflection->getEndLine();
$this->_filePath = $reflection->getFileName();
foreach ($reflection->getMethods() as $method) {
//Method::create($this, $method);
$this->addMethod(Method::create($this, $method));
}
}
示例9: getCodeInClass
public function getCodeInClass($className)
{
$class = new \ReflectionClass($className);
$startLine = $class->getStartLine() - 1;
// getStartLine() seems to start after the {, we want to include the signature
$endLine = $class->getEndLine();
$numLines = $endLine - $startLine;
$namespace = $this->getNamespaceOfClass($className);
$classCode = "namespace {$namespace};\n\n" . implode("\n", array_slice(explode("\n", $this->fileContent), $startLine, $numLines)) . "\n";
return $classCode;
}
示例10: compile
/**
* method for making a single file of most used doctrine runtime components
* including the compiled file instead of multiple files (in worst
* cases dozens of files) can improve performance by an order of magnitude
*
* @throws Doctrine_Compiler_Exception if something went wrong during the compile operation
* @return void
*/
public static function compile($target = null)
{
$path = Doctrine::getPath();
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($it as $file) {
$e = explode('.', $file->getFileName());
// we don't want to require versioning files
if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) {
require_once $file->getPathName();
}
}
$classes = array_merge(get_declared_classes(), get_declared_interfaces());
$ret = array();
foreach ($classes as $class) {
$e = explode('_', $class);
if ($e[0] !== 'Doctrine') {
continue;
}
$refl = new ReflectionClass($class);
$file = $refl->getFileName();
print 'Adding ' . $file . PHP_EOL;
$lines = file($file);
$start = $refl->getStartLine() - 1;
$end = $refl->getEndLine();
$ret = array_merge($ret, array_slice($lines, $start, $end - $start));
}
if ($target == null) {
$target = $path . DIRECTORY_SEPARATOR . 'Doctrine.compiled.php';
}
// first write the 'compiled' data to a text file, so
// that we can use php_strip_whitespace (which only works on files)
$fp = @fopen($target, 'w');
if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open {$target}");
}
fwrite($fp, "<?php " . implode('', $ret));
fclose($fp);
$stripped = php_strip_whitespace($target);
$fp = @fopen($target, 'w');
if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open {$file}");
}
fwrite($fp, $stripped);
fclose($fp);
}
示例11: getConstants
var_dump($rb->getConstant('C1'));
print "\n";
print "--- getConstants() ---\n";
var_dump($rb->getConstants());
print "\n";
print "--- getConstructor() ---\n";
var_dump($rb->getConstructor());
print "\n";
print "--- getDocComment() ---\n";
var_dump($rb->getDocComment());
print "\n";
print "--- getStartLine() ---\n";
var_dump($rb->getStartLine());
print "\n";
print "--- getEndLine() ---\n";
var_dump($rb->getEndLine());
print "\n";
print "--- getFileName() ---\n";
var_dump($rb->getFileName());
print "\n";
print "--- getInterfaceNames() ---\n";
var_dump($rb->getInterfaceNames());
print "\n";
print "--- getInterfaces() ---\n";
# Very verbose.
#var_dump(
$rb->getInterfaces();
print "\n";
print "--- getMethod() ---\n";
print "\n";
print "--- getMethods() ---\n";
示例12: copyTemplateMethodToExisitingClass
/**
* Copies the given method and all needed use statements into an existing class. The target class name will be
* built based on the given $replace argument.
* @param string $sourceClassName
* @param string $methodName
* @param array $replace
*/
protected function copyTemplateMethodToExisitingClass($sourceClassName, $methodName, $replace)
{
$targetClassName = $this->replaceContent($replace, $sourceClassName);
if (Development::methodExists($targetClassName, $methodName)) {
// we do not want to add the same method twice
return;
}
Development::checkMethodExists($sourceClassName, $methodName, 'Cannot copy template method: ');
$targetClass = new \ReflectionClass($targetClassName);
$file = new \SplFileObject($targetClass->getFileName());
$methodCode = Development::getMethodSourceCode($sourceClassName, $methodName);
$methodCode = $this->replaceContent($replace, $methodCode);
$methodLine = $targetClass->getEndLine() - 1;
$sourceUses = Development::getUseStatements($sourceClassName);
$targetUses = Development::getUseStatements($targetClassName);
$usesToAdd = array_diff($sourceUses, $targetUses);
if (empty($usesToAdd)) {
$useCode = '';
} else {
$useCode = "\nuse " . implode("\nuse ", $usesToAdd) . "\n";
}
// search for namespace line before the class starts
$useLine = 0;
foreach (new \LimitIterator($file, 0, $targetClass->getStartLine()) as $index => $line) {
if (0 === strpos(trim($line), 'namespace ')) {
$useLine = $index + 1;
break;
}
}
$newClassCode = '';
foreach (new \LimitIterator($file) as $index => $line) {
if ($index == $methodLine) {
$newClassCode .= $methodCode;
}
if (0 !== $useLine && $index == $useLine) {
$newClassCode .= $useCode;
}
$newClassCode .= $line;
}
file_put_contents($targetClass->getFileName(), $newClassCode);
}
示例13: classes
/**
* Create a syntax highlighted diagram of a class, including parent dependencies, memebers and functions.
*
* @param object $obj The object to explore.
* @return string The formatted diagram of the object.
*/
public static function classes($obj)
{
echo self::$is_themed ? '' : self::$theme;
$current_class = new \ReflectionObject($obj);
$class = new \ReflectionClass($current_class->getName());
$parents = array();
while ($parent = $class->getParentClass()) {
$mod = "<h3><b class='rtn'>{$parstr}</b>" . implode(' ', \Reflection::getModifierNames($class->getModifiers()));
$nam = "Class <b class='nam'>" . $class->getName() . "</b></h3>";
$lin = self::get_func_url($class->getStartLine(), $class->getEndLine(), $class->getFileName());
$doc = self::clean_docblok($class->getdocComment(), false, "Undocumented {$parstr}" . "Class");
$parents[] = "<div class='method'>";
$parents[] = $lin;
$parents[] = Syntax::php(trim($mod . $nam), 'all');
$parents[] = "<b class='com'>{$doc}</b>";
$properties = implode($class->getProperties());
$properties = str_replace('<default>', '', $properties);
$properties = str_replace('Property [ ', '', $properties);
$properties = str_replace(' ]', '', $properties);
$properties = explode(' ', $properties);
$len = 0;
foreach ($properties as $k => $v) {
if ($k % 2 !== 0) {
$test = strlen($v);
$len = $test > $len ? $test + 1 : $len;
}
}
foreach ($properties as $k => $v) {
$properties[$k] = ltrim(sprintf("%-{$len}s", $v));
}
$properties = implode('', $properties);
$properties = explode("\n", $properties);
asort($properties);
$properties = "<h4>Properties:</h4>" . implode("\n", $properties);
$parents[] = Syntax::php($properties, 'all');
if ($parstr !== 'Parent ') {
$parents[] = self::build_func_list($obj);
}
$parents[] = "</div>";
$parstr = "Parent ";
$class = $parent;
}
$class_info = "Parents: " . implode(", ", $parents);
$class_info = Syntax::php($class_info, 'all');
$classinfo = implode($parents);
echo $classinfo;
/*
$class = new \ReflectionObject($obj);
ReflectionObject::export($obj);
$test = new \ReflectionClass($obj);
print_r($test->getProperties());
echo 'getConstants() '; print_r( $class->getConstants() ) .PHP_EOL;
echo 'getDefaultProperties()'; print_r( $class->getDefaultProperties() ) .PHP_EOL;
echo 'getInterfaceNames() '; print_r( $class->getInterfaceNames() ) .PHP_EOL;
echo 'getInterfaces() '; print_r( $class->getInterfaces() ) .PHP_EOL;
echo 'getMethods() '; print_r( $class->getMethods() ) .PHP_EOL;
echo 'getProperties() '; print_r( $class->getProperties() ) .PHP_EOL;
echo 'getStaticProperties() '; print_r( $class->getStaticProperties() ) .PHP_EOL;
echo 'getTraitAliases() '; print_r( $class->getTraitAliases() ) .PHP_EOL;
echo 'getTraitNames() '; print_r( $class->getTraitNames() ) .PHP_EOL;
echo 'getTraits() '; print_r( $class->getTraits() ) .PHP_EOL;
echo 'hasConstant() '. AT::boolstr( $class->hasConstant($class->getName())) .PHP_EOL;
echo 'inNamespace() '. AT::boolstr( $class->inNamespace() ) .PHP_EOL;
echo 'isAbstract() '. AT::boolstr( $class->isAbstract() ) .PHP_EOL;
echo 'isCloneable() '. AT::boolstr( $class->isCloneable() ) .PHP_EOL;
echo 'isFinal() '. AT::boolstr( $class->isFinal() ) .PHP_EOL;
echo 'isInstantiable() '. AT::boolstr( $class->isInstantiable() ) .PHP_EOL;
echo 'isInterface() '. AT::boolstr( $class->isInterface() ) .PHP_EOL;
echo 'isInternal() '. AT::boolstr( $class->isInternal() ) .PHP_EOL;
echo 'isIterateable() '. AT::boolstr( $class->isIterateable() ) .PHP_EOL;
echo 'isTrait() '. AT::boolstr( $class->isTrait() ) .PHP_EOL;
echo 'isUserDefined() '. AT::boolstr( $class->isUserDefined() ) .PHP_EOL;
echo 'getEndLine() '. $class->getEndLine() .PHP_EOL;
echo 'getModifiers() '. $class->getModifiers() .PHP_EOL;
echo 'getStartLine() '. $class->getStartLine() .PHP_EOL;
echo 'getDocComment() '. $class->getDocComment() .PHP_EOL;
echo 'getExtensionName() '. $class->getExtensionName() .PHP_EOL;
echo 'getFileName() '. $class->getFileName() .PHP_EOL;
echo 'getName() '. $class->getName() .PHP_EOL;
echo 'getNamespaceName() '. $class->getNamespaceName() .PHP_EOL;
echo 'getShortName() '. $class->getShortName() .PHP_EOL;
*/
}
示例14: addOverride
/**
* Add all methods in a module override to the override class
*
* @param string $classname
* @return bool
*/
public function addOverride($classname)
{
$path = Autoload::getInstance()->getClassPath($classname . 'Core');
// Check if there is already an override file, if not, we just need to copy the file
if (Autoload::getInstance()->getClassPath($classname)) {
// Check if override file is writable
$override_path = _PS_ROOT_DIR_ . '/' . Autoload::getInstance()->getClassPath($classname);
if (!file_exists($override_path) && !is_writable(dirname($override_path)) || file_exists($override_path) && !is_writable($override_path)) {
throw new Exception(sprintf(Tools::displayError('file (%s) not writable'), $override_path));
}
// Get a uniq id for the class, because you can override a class (or remove the override) twice in the same session and we need to avoid redeclaration
do {
$uniq = uniqid();
} while (class_exists($classname . 'OverrideOriginal_remove', false));
// Make a reflection of the override class and the module override class
$override_file = file($override_path);
eval(preg_replace(array('#^\\s*<\\?(?:php)?#', '#class\\s+' . $classname . '\\s+extends\\s+([a-z0-9_]+)(\\s+implements\\s+([a-z0-9_]+))?#i'), array(' ', 'class ' . $classname . 'OverrideOriginal' . $uniq), implode('', $override_file)));
$override_class = new ReflectionClass($classname . 'OverrideOriginal' . $uniq);
$module_file = file($this->getLocalPath() . 'override' . DIRECTORY_SEPARATOR . $path);
eval(preg_replace(array('#^\\s*<\\?(?:php)?#', '#class\\s+' . $classname . '(\\s+extends\\s+([a-z0-9_]+)(\\s+implements\\s+([a-z0-9_]+))?)?#i'), array(' ', 'class ' . $classname . 'Override' . $uniq), implode('', $module_file)));
$module_class = new ReflectionClass($classname . 'Override' . $uniq);
// Check if none of the methods already exists in the override class
foreach ($module_class->getMethods() as $method) {
if ($override_class->hasMethod($method->getName())) {
throw new Exception(sprintf(Tools::displayError('The method %1$s in the class %2$s is already overriden.'), $method->getName(), $classname));
}
}
// Check if none of the properties already exists in the override class
foreach ($module_class->getProperties() as $property) {
if ($override_class->hasProperty($property->getName())) {
throw new Exception(sprintf(Tools::displayError('The property %1$s in the class %2$s is already defined.'), $property->getName(), $classname));
}
}
// Insert the methods from module override in override
$copy_from = array_slice($module_file, $module_class->getStartLine() + 1, $module_class->getEndLine() - $module_class->getStartLine() - 2);
array_splice($override_file, $override_class->getEndLine() - 1, 0, $copy_from);
$code = implode('', $override_file);
file_put_contents($override_path, $code);
} else {
$override_src = $this->getLocalPath() . 'override' . DIRECTORY_SEPARATOR . $path;
$override_dest = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'override' . DIRECTORY_SEPARATOR . $path;
if (!is_writable(dirname($override_dest))) {
throw new Exception(sprintf(Tools::displayError('directory (%s) not writable'), dirname($override_dest)));
}
copy($override_src, $override_dest);
// Re-generate the class index
Autoload::getInstance()->generateIndex();
}
return true;
}
示例15: weaveMock
protected static function weaveMock($classNameMock_, \ReflectionClass $mock_, \ReflectionClass $type_)
{
$mock = @file_get_contents($mock_->getFileName());
$type = @file_get_contents($type_->getFileName());
$typeMTime = @filemtime($type_->getFileName());
$method = [];
$methods = [];
foreach (token_get_all($type) as $token) {
if (count($method) && ('{' == $token || ';' == $token)) {
$methods[] = $method;
$method = [];
} else {
if (count($method)) {
$method[] = $token;
}
}
if (T_FUNCTION == $token[0]) {
$method[] = $token;
}
}
$signatures = [];
foreach ($methods as $tokens) {
$tokens = array_slice($tokens, 2);
$nameToken = array_shift($tokens);
$name = $nameToken[1];
$signature = '';
foreach ($tokens as $token) {
if (false === is_array($token)) {
$signature .= $token;
continue;
}
if (T_WHITESPACE == $token[0]) {
continue;
}
if (in_array($token[0], self::$m_tokensMethodSignature)) {
$signature .= $token[1];
if (T_STRING == $token[0]) {
$signature .= ' ';
}
}
}
$signatures[$name] = $signature;
}
$source = explode(Io::LINE_SEPARATOR_DEFAULT, $mock);
$source = array_slice($source, 0, $mock_->getEndLine() - 1);
foreach ($signatures as $methodName => $signature) {
$method = $type_->getMethod($methodName);
if ($method->isStatic() || $method->isFinal()) {
continue;
}
$parameters = [];
foreach ($method->getParameters() as $parameter) {
$parameters[] = '$' . $parameter->name;
}
if ($method->isConstructor()) {
$source[] = "public function {$methodName}{$signature} {parent::{$methodName}(" . implode(', ', $parameters) . ");}";
continue;
}
$visibility = 'public';
if ($method->isPrivate()) {
$visibility = 'private';
} else {
if ($method->isProtected()) {
$visibility = 'protected';
}
}
$sourceMethod = "{$visibility} function {$methodName}{$signature} {if(\$this->mocked('{$methodName}')) return \$this->__call('{$methodName}', func_get_args());";
if (false === $type_->isInterface() && false === $method->isAbstract()) {
$sourceMethod .= " return parent::{$methodName}(" . implode(', ', $parameters) . ");";
}
$source[] = $sourceMethod . "}";
}
$source = implode(Io::LINE_SEPARATOR_DEFAULT, $source) . Io::LINE_SEPARATOR_DEFAULT . ' }' . Io::LINE_SEPARATOR_DEFAULT . '?>';
$inheritance = $type_->isInterface() ? 'implements' : 'extends';
return str_replace('class Mock', "class {$classNameMock_} {$inheritance} \\{$type_->name}", $source);
}