Skip to content

Commit d9b4c9f

Browse files
committed
init
0 parents  commit d9b4c9f

File tree

10 files changed

+248
-0
lines changed

10 files changed

+248
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- hhvm
9+
10+
before_script:
11+
- composer self-update
12+
- composer install --prefer-source --no-interaction --dev
13+
14+
script: phpunit

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "sourcescript/laravel-dependency-injector",
3+
"description": "",
4+
"authors": [
5+
{
6+
"name": "Gian Crescini Santillan",
7+
"email": "[email protected]"
8+
}
9+
],
10+
"require": {
11+
"php": ">=5.4.0",
12+
"illuminate/support": "4.2.*"
13+
},
14+
"autoload": {
15+
"psr-0": {
16+
"Sourcescript\\LaravelDependencyInjector": "src/"
17+
}
18+
},
19+
"minimum-stability": "stable"
20+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

readme.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#Laravel Dependency Injector For Laravel4
2+
3+
4+
###Why? The Effort
5+
The hardet part of developing applications which should be scalable in Laravel4 is Dependency Injection. Usually, we always have that nuisance of using `Use \Config` or `Use \Response` on our applications. The big Problem there would be scalability.
6+
7+
Assuming Laravel 4 just ported and overhauled to a new framework, or imagine you, as a developer switched from using `sentry` to basic `auth`. What do you do? Scalability and Dependency is always the issue.
8+
9+
###Version 0.0001
10+
Thanks to the other library, SocialConnect, and two big API-Centric applicaitons that I'm building, There's a big problem w/ dependencies. Now, It would be no issue.
11+
12+
###Installation
13+
14+
####Composer
15+
####Facades
16+
```php
17+
<?php
18+
...
19+
'DependencyInterface' => 'Sourcescript\LaravelDependencyInjector\Facades\DependencyFacade'
20+
...
21+
22+
23+
```
24+
25+
Insert that into the facades array.
26+
27+
**disclosure**: some applications and libraries you may be doing or using would or cannot directly use the Facade due to psr issues. Therefore, they may inser the following:
28+
29+
```php
30+
<?php
31+
use Sourcescript\LaravelDependencyInjector\Interfaces\DependencyInterface;
32+
33+
```
34+
35+
Rather than `importing` alot of libraries or extensions to your library (from Laravel's Library) you may just need to import the dpependency injector and he'll do the rest
36+
37+
38+
####Providers
39+
```php
40+
<?php
41+
...
42+
'Sourcescript\LaravelDependencyInjector\LaravelDependencyInjectorServiceProvider'
43+
...
44+
```
45+
46+
Insert the following into the providers array
47+
48+
49+
###How to use?
50+
Here's an example of an API-centric controller which uses a better dependency injection w/ our library
51+
52+
```php
53+
<?php namespace Pupilr\System\Controllers\User;
54+
55+
use Sourcescript\LaravelDependencyInjector\Interfaces\DependencyInterface;
56+
57+
class UserController extends APIController
58+
{
59+
protected $dependencies;
60+
61+
public function __construct(DependencyInterface $dependencies)
62+
{
63+
$this->dependencies = $dependencies;
64+
}
65+
66+
public function getIndex()
67+
{
68+
$result = [
69+
'code' => 200,
70+
'message' => 'hello world'
71+
];
72+
73+
return $this->dependencies->response->json($result)->setCallback($this->dependencies->input->get('callback'));
74+
}
75+
}
76+
```
77+
78+
as you can see, even tho its a bit wee long, its cleaner and easier to recode and revamp, you won't have the hassle of editing all one by one.
79+
80+
###Future Fixes
81+
1. Artisan Task: For Creating New Dependencies
82+
83+
###Credits
84+
Credits go to Kier & Jeff (both are which my friends) on pointing out an err, and helping me generate a better plugin
85+
86+
Also, to SourceScript Innovations, this will and always be made w/ love.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php namespace Sourcescript\LaravelDependencyInejctor\Facade;
2+
3+
use Illuminate\Support\Facades\Facade;
4+
5+
class DependencyFacade extends Facade
6+
{
7+
protected static function getFacadeAccessor()
8+
{
9+
return 'dependency';
10+
}
11+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php namespace Sourcescript\LaravelDependencyInjector\Handler;
2+
3+
4+
use Illuminate\Foundation\Application as App;
5+
use Sourcescript\LaravelDependencyInjector\Interfaces\DependencyInterface;
6+
7+
class DependencyHandler implements DependencyInterface
8+
{
9+
10+
protected $app;
11+
12+
public function __construct($app)
13+
{
14+
$this->app = $app;
15+
}
16+
17+
public function app()
18+
{
19+
return $this->app;
20+
}
21+
22+
public function input()
23+
{
24+
return $this->app->make('input');
25+
}
26+
27+
public function response()
28+
{
29+
return $this->app->make('response');
30+
}
31+
32+
public function validator()
33+
{
34+
return $this->app->make('validator');
35+
}
36+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php namespace Sourcescript\LaravelDependencyInjector\Interfaces;
2+
3+
interface DependencyInterface
4+
{
5+
public function app();
6+
public function input();
7+
public function response();
8+
public function validator();
9+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php namespace Sourcescript\LaravelDependencyInjector;
2+
3+
use Illuminate\Support\ServiceProvider;
4+
5+
use Sourcescript\LaravelDependencyInjector\Handler\DependencyHandler;
6+
use Sourcescript\LaravelDependencyInjector\Interfaces\DependencyInterface;
7+
8+
class LaravelDependencyInjectorServiceProvider extends ServiceProvider {
9+
10+
/**
11+
* Indicates if loading of the provider is deferred.
12+
*
13+
* @var bool
14+
*/
15+
protected $defer = false;
16+
17+
/**
18+
* Register the service provider.
19+
*
20+
* @return void
21+
*/
22+
public function register()
23+
{
24+
$app = $this->app;
25+
26+
$app->bind(
27+
'Sourcescript\LaravelDependencyInjector\Interfaces\DependencyInterface',
28+
function($app)
29+
{
30+
return new DependencyHandler($app);
31+
}
32+
);
33+
34+
$app['dependency'] = $this->app->share(function($app)
35+
{
36+
return new DependencyInterface;
37+
});
38+
}
39+
40+
/**
41+
* Get the services provided by the provider.
42+
*
43+
* @return array
44+
*/
45+
public function provides()
46+
{
47+
return array();
48+
}
49+
50+
}

tests/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)