-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from LaravelCollective/analysis-8br9A8
Applied fixes from StyleCI
- Loading branch information
Showing
41 changed files
with
1,577 additions
and
1,547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,132 @@ | ||
<?php namespace Collective\Annotations; | ||
<?php | ||
|
||
namespace Collective\Annotations; | ||
|
||
use Collective\Annotations\NamespaceToPathConverterTrait; | ||
use Doctrine\Common\Annotations\AnnotationRegistry; | ||
use Doctrine\Common\Annotations\SimpleAnnotationReader; | ||
use Exception; | ||
use ReflectionClass; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
abstract class AnnotationScanner { | ||
|
||
abstract class AnnotationScanner | ||
{ | ||
use NamespaceToPathConverterTrait; | ||
|
||
/** | ||
* Namespaces to check for annotation reader annotation classes. | ||
* | ||
* @var string | ||
*/ | ||
protected $namespaces = []; | ||
|
||
/** | ||
* The paths to scan for annotations. | ||
* | ||
* @var array | ||
*/ | ||
protected $scan = []; | ||
|
||
/** | ||
* Create a new scanner instance. | ||
* | ||
* @param array $scan | ||
* @return void | ||
*/ | ||
public function __construct(array $scan) | ||
{ | ||
$this->scan = $scan; | ||
} | ||
|
||
/** | ||
* Create a new scanner instance. | ||
* | ||
* @param array $scan | ||
* @return static | ||
*/ | ||
public static function create(array $scan) | ||
{ | ||
return new static($scan); | ||
} | ||
|
||
/** | ||
* Get all of the ReflectionClass instances in the scan array. | ||
* | ||
* @return array | ||
*/ | ||
protected function getClassesToScan() | ||
{ | ||
$classes = []; | ||
|
||
foreach ($this->scan as $class) | ||
{ | ||
try | ||
{ | ||
$classes[] = new ReflectionClass($class); | ||
} | ||
catch (Exception $e) | ||
{ | ||
// | ||
} | ||
} | ||
|
||
return $classes; | ||
} | ||
|
||
/** | ||
* Set the classes to scan | ||
* | ||
* @param array $scans | ||
*/ | ||
public function setClassesToScan( array $scans ) | ||
{ | ||
$this->scan = $scans; | ||
} | ||
|
||
/** | ||
* Add an annotation namespace for the SimpleAnnotationReader instance. | ||
* | ||
* If the second parameter is null, it will assume the namespace is PSR-4'd | ||
* inside your app folder. | ||
* | ||
* @param string $namespace | ||
* @param string $path | ||
*/ | ||
public function addAnnotationNamespace($namespace, $path = null) | ||
{ | ||
$this->namespaces[] = $namespace; | ||
|
||
return $this->registerAnnotationsPathWithRegistry( | ||
$path ?: $this->getPathFromNamespace( $namespace ) | ||
); | ||
} | ||
|
||
/** | ||
* Register the annotator files with the annotation registry | ||
* | ||
* @param string $path | ||
* @return $this | ||
*/ | ||
public function registerAnnotationsPathWithRegistry( $path ) | ||
{ | ||
foreach (Finder::create()->files()->in( $path ) as $file) | ||
{ | ||
/** | ||
* Namespaces to check for annotation reader annotation classes. | ||
* | ||
* @var string | ||
*/ | ||
protected $namespaces = []; | ||
|
||
/** | ||
* The paths to scan for annotations. | ||
* | ||
* @var array | ||
*/ | ||
protected $scan = []; | ||
|
||
/** | ||
* Create a new scanner instance. | ||
* | ||
* @param array $scan | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(array $scan) | ||
{ | ||
$this->scan = $scan; | ||
} | ||
|
||
/** | ||
* Create a new scanner instance. | ||
* | ||
* @param array $scan | ||
* | ||
* @return static | ||
*/ | ||
public static function create(array $scan) | ||
{ | ||
return new static($scan); | ||
} | ||
|
||
/** | ||
* Get all of the ReflectionClass instances in the scan array. | ||
* | ||
* @return array | ||
*/ | ||
protected function getClassesToScan() | ||
{ | ||
$classes = []; | ||
|
||
foreach ($this->scan as $class) { | ||
try { | ||
$classes[] = new ReflectionClass($class); | ||
} catch (Exception $e) { | ||
// | ||
} | ||
} | ||
|
||
return $classes; | ||
} | ||
|
||
/** | ||
* Set the classes to scan. | ||
* | ||
* @param array $scans | ||
*/ | ||
public function setClassesToScan(array $scans) | ||
{ | ||
$this->scan = $scans; | ||
} | ||
|
||
/** | ||
* Add an annotation namespace for the SimpleAnnotationReader instance. | ||
* | ||
* If the second parameter is null, it will assume the namespace is PSR-4'd | ||
* inside your app folder. | ||
* | ||
* @param string $namespace | ||
* @param string $path | ||
*/ | ||
public function addAnnotationNamespace($namespace, $path = null) | ||
{ | ||
$this->namespaces[] = $namespace; | ||
|
||
return $this->registerAnnotationsPathWithRegistry( | ||
$path ?: $this->getPathFromNamespace($namespace) | ||
); | ||
} | ||
|
||
/** | ||
* Register the annotator files with the annotation registry. | ||
* | ||
* @param string $path | ||
* | ||
* @return $this | ||
*/ | ||
public function registerAnnotationsPathWithRegistry($path) | ||
{ | ||
foreach (Finder::create()->files()->in($path) as $file) { | ||
AnnotationRegistry::registerFile($file->getRealPath()); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get an annotation reader instance. | ||
* | ||
* @return \Doctrine\Common\Annotations\SimpleAnnotationReader | ||
*/ | ||
protected function getReader() | ||
{ | ||
$reader = new SimpleAnnotationReader; | ||
|
||
foreach ($this->namespaces as $namespace) | ||
$reader->addNamespace($namespace); | ||
|
||
return $reader; | ||
} | ||
} | ||
|
||
/** | ||
* Get an annotation reader instance. | ||
* | ||
* @return \Doctrine\Common\Annotations\SimpleAnnotationReader | ||
*/ | ||
protected function getReader() | ||
{ | ||
$reader = new SimpleAnnotationReader(); | ||
|
||
foreach ($this->namespaces as $namespace) { | ||
$reader->addNamespace($namespace); | ||
} | ||
|
||
return $reader; | ||
} | ||
} |
Oops, something went wrong.