Skip to content

Commit

Permalink
Simplify the package path guessing.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 29, 2013
1 parent 4f7d5d0 commit 6089525
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions src/Illuminate/Support/ServiceProvider.php
Expand Up @@ -105,41 +105,11 @@ public function package($package, $namespace = null, $path = null)
*/ */
public function guessPackagePath() public function guessPackagePath()
{ {
$reflect = new ReflectionClass($this); $path = with(new ReflectionClass($this))->getFileName();

// We want to get the class that is closest to this base class in the chain of
// classes extending it. That should be the original service provider given
// by the package and should allow us to guess the location of resources.
$chain = $this->getClassChain($reflect);

$path = $chain[count($chain) - 2]->getFileName();


return realpath(dirname($path).'/../../'); return realpath(dirname($path).'/../../');
} }


/**
* Get a class from the ReflectionClass inheritance chain.
*
* @param ReflectionClass $reflection
* @return array
*/
protected function getClassChain(ReflectionClass $reflect)
{
$classes = array();

// This loop essentially walks the inheritance chain of the classes starting
// at the most "childish" class and walks back up to this class. Once we
// get to the end of the chain we will bail out and return the offset.
while ($reflect !== false)
{
$classes[] = $reflect;

$reflect = $reflect->getParentClass();
}

return $classes;
}

/** /**
* Determine the namespace for a package. * Determine the namespace for a package.
* *
Expand Down

0 comments on commit 6089525

Please sign in to comment.