Skip to content

Commit 538d2b0

Browse files
committed
Initial Commit
Signed-off-by: Adam Engebretson <[email protected]>
0 parents  commit 538d2b0

37 files changed

+1700
-0
lines changed

.gitattributes

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/tests export-ignore
2+
.gitattributes export-ignore
3+
.gitignore export-ignore
4+
.scrutinizer.yml export-ignore
5+
.travis.yml export-ignore
6+
phpunit.php export-ignore
7+
phpunit.xml export-ignore

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store
5+
Thumbs.db
6+
.idea

.scrutinizer.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
checks:
5+
php:
6+
code_rating: true
7+
duplication: true
8+
variable_existence: true
9+
useless_calls: true
10+
use_statement_alias_conflict: true
11+
unused_variables: true
12+
unused_properties: true
13+
unused_parameters: true
14+
unused_methods: true
15+
unreachable_code: true
16+
sql_injection_vulnerabilities: true
17+
security_vulnerabilities: true
18+
precedence_mistakes: true
19+
precedence_in_conditions: true
20+
parameter_non_unique: true
21+
no_property_on_interface: true
22+
no_non_implemented_abstract_methods: true
23+
deprecated_code_usage: true
24+
closure_use_not_conflicting: true
25+
closure_use_modifiable: true
26+
avoid_useless_overridden_methods: true
27+
avoid_conflicting_incrementers: true
28+
assignment_of_null_return: true
29+
avoid_usage_of_logical_operators: true
30+
ensure_lower_case_builtin_functions: true
31+
foreach_traversable: true
32+
function_in_camel_caps: true
33+
instanceof_class_exists: true
34+
lowercase_basic_constants: true
35+
lowercase_php_keywords: true
36+
missing_arguments: true
37+
no_commented_out_code: true
38+
no_duplicate_arguments: true
39+
no_else_if_statements: true
40+
no_space_between_concatenation_operator: true
41+
no_space_inside_cast_operator: true
42+
no_trailing_whitespace: true
43+
no_underscore_prefix_in_properties: true
44+
no_unnecessary_if: true
45+
no_unnecessary_function_call_in_for_loop: true
46+
non_commented_empty_catch_block: true
47+
php5_style_constructor: true
48+
parameters_in_camelcaps: true
49+
prefer_while_loop_over_for_loop: true
50+
properties_in_camelcaps: true
51+
require_scope_for_methods: true
52+
require_scope_for_properties: true
53+
spacing_around_conditional_operators: true
54+
spacing_around_non_conditional_operators: true
55+
spacing_of_function_arguments: true

.travis.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: php
2+
3+
php:
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- hhvm
8+
9+
sudo: false
10+
11+
install: travis_retry composer install --no-interaction --prefer-source
12+
13+
script: vendor/bin/phpunit

CONTRIBUTING.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Laravel Contribution Guide
2+
3+
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions). Please review the entire guide before sending a pull request.

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) <Adam Engebretson>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

composer.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "adamgoose/laravel-annotations",
3+
"description": "Route Annotations for The Laravel Framework.",
4+
"keywords": ["framework", "laravel", "annotations"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Adam Engebretson",
9+
"email": "[email protected]"
10+
},
11+
{
12+
"name": "Taylor Otwell",
13+
"email": "[email protected]"
14+
}
15+
],
16+
"require": {
17+
"php": ">=5.4.0",
18+
"illuminate/support": "~5.0",
19+
"doctrine/annotations": "~1.0",
20+
"symfony/finder": "2.6.*"
21+
},
22+
"require-dev": {
23+
"mockery/mockery": "~0.9",
24+
"phpunit/phpunit": "~4.0"
25+
},
26+
"autoload": {
27+
"psr-0": {
28+
"Adamgoose": "src/"
29+
}
30+
},
31+
"extra": {
32+
"branch-alias": {
33+
"dev-master": "5.0-dev"
34+
}
35+
},
36+
"minimum-stability": "dev"
37+
}

phpunit.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Register The Composer Auto Loader
6+
|--------------------------------------------------------------------------
7+
|
8+
| Composer provides a convenient, automatically generated class loader
9+
| for our application. We just need to utilize it! We'll require it
10+
| into the script here so that we do not have to worry about the
11+
| loading of any our classes "manually". Feels great to relax.
12+
|
13+
*/
14+
15+
require __DIR__.'/vendor/autoload.php';
16+
17+
/*
18+
|--------------------------------------------------------------------------
19+
| Set The Default Timezone
20+
|--------------------------------------------------------------------------
21+
|
22+
| Here we will set the default timezone for PHP. PHP is notoriously mean
23+
| if the timezone is not explicitly set. This will be used by each of
24+
| the PHP date and date-time functions throughout the application.
25+
|
26+
*/
27+
28+
date_default_timezone_set('UTC');

phpunit.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="phpunit.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnError="false"
11+
stopOnFailure="false"
12+
syntaxCheck="true"
13+
strict="false"
14+
verbose="true"
15+
>
16+
<testsuites>
17+
<testsuite name="Laravel Annotations Test Suite">
18+
<directory suffix="Test.php">./tests</directory>
19+
</testsuite>
20+
</testsuites>
21+
<filter>
22+
<whitelist processUncoveredFilesFromWhitelist="true">
23+
<directory suffix=".php">./src</directory>
24+
</whitelist>
25+
</filter>
26+
</phpunit>

readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Annotations for The Laravel Framework
2+
3+
[![Build Status](https://travis-ci.org/adamgoose/laravel-annotations.svg)](https://travis-ci.org/adamgoose/laravel-annotations)
4+
[![Total Downloads](https://poser.pugx.org/adamgoose/laravel-annotations/downloads.svg)](https://packagist.org/packages/adamgoose/laravel-annotations)
5+
[![Latest Stable Version](https://poser.pugx.org/adamgoose/laravel-annotations/v/stable.svg)](https://packagist.org/packages/adamgoose/laravel-annotations)
6+
[![Latest Unstable Version](https://poser.pugx.org/adamgoose/laravel-annotations/v/unstable.svg)](https://packagist.org/packages/adamgoose/laravel-annotations)
7+
[![License](https://poser.pugx.org/adamgoose/laravel-annotations/license.svg)](https://packagist.org/packages/adamgoose/laravel-annotations)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php namespace Adamgoose\Events\Annotations\Annotations;
2+
3+
/**
4+
* @Annotation
5+
*/
6+
class Hears {
7+
8+
/**
9+
* The events the annotation hears.
10+
*
11+
* @var array
12+
*/
13+
public $events;
14+
15+
/**
16+
* Create a new annotation instance.
17+
*
18+
* @param array $values
19+
* @return void
20+
*/
21+
public function __construct(array $values = array())
22+
{
23+
$this->events = (array) $values['value'];
24+
}
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php namespace Adamgoose\Events\Annotations;
2+
3+
use Exception;
4+
use ReflectionClass;
5+
use Symfony\Component\Finder\Finder;
6+
use Doctrine\Common\Annotations\AnnotationRegistry;
7+
use Doctrine\Common\Annotations\SimpleAnnotationReader;
8+
9+
class Scanner {
10+
11+
/**
12+
* The classes to scan for annotations.
13+
*
14+
* @var array
15+
*/
16+
protected $scan;
17+
18+
/**
19+
* Create a new event scanner instance.
20+
*
21+
* @param array $scan
22+
* @return void
23+
*/
24+
public function __construct(array $scan)
25+
{
26+
$this->scan = $scan;
27+
28+
foreach (Finder::create()->files()->in(__DIR__.'/Annotations') as $file)
29+
{
30+
AnnotationRegistry::registerFile($file->getRealPath());
31+
}
32+
}
33+
34+
/**
35+
* Create a new scanner instance.
36+
*
37+
* @param array $scan
38+
* @return static
39+
*/
40+
public static function create(array $scan)
41+
{
42+
return new static($scan);
43+
}
44+
45+
/**
46+
* Convert the scanned annotations into route definitions.
47+
*
48+
* @return string
49+
*/
50+
public function getEventDefinitions()
51+
{
52+
$output = '';
53+
54+
$reader = $this->getReader();
55+
56+
foreach ($this->getClassesToScan() as $class)
57+
{
58+
foreach ($class->getMethods() as $method)
59+
{
60+
foreach ($reader->getMethodAnnotations($method) as $annotation)
61+
{
62+
$output .= $this->buildListener($class->name, $method->name, $annotation->events);
63+
}
64+
}
65+
}
66+
67+
return trim($output);
68+
}
69+
70+
/**
71+
* Build the event listener for the class and method.
72+
*
73+
* @param string $class
74+
* @param string $method
75+
* @param array $events
76+
* @return string
77+
*/
78+
protected function buildListener($class, $method, $events)
79+
{
80+
return sprintf('$events->listen(%s, \''.$class.'@'.$method.'\');', var_export($events, true)).PHP_EOL;
81+
}
82+
83+
/**
84+
* Get all of the ReflectionClass instances in the scan path.
85+
*
86+
* @return array
87+
*/
88+
protected function getClassesToScan()
89+
{
90+
$classes = [];
91+
92+
foreach ($this->scan as $class)
93+
{
94+
try
95+
{
96+
$classes[] = new ReflectionClass($class);
97+
}
98+
catch (Exception $e)
99+
{
100+
//
101+
}
102+
}
103+
104+
return $classes;
105+
}
106+
107+
/**
108+
* Get an annotation reader instance.
109+
*
110+
* @return \Doctrine\Common\Annotations\SimpleAnnotationReader
111+
*/
112+
protected function getReader()
113+
{
114+
with($reader = new SimpleAnnotationReader)
115+
->addNamespace('Adamgoose\Events\Annotations\Annotations');
116+
117+
return $reader;
118+
}
119+
120+
}

0 commit comments

Comments
 (0)