Skip to content

Commit ab1ac2e

Browse files
committed
Merge pull request zackkitzmiller#23 from aranw/master
Laravel 5 support for Tiny-PHP
2 parents 8696782 + 0e56c54 commit ab1ac2e

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php namespace ZackKitzmiller\Laravel5;
2+
3+
use ZackKitzmiller\Tiny;
4+
use Illuminate\Console\Command;
5+
use Illuminate\Filesystem\Filesystem;
6+
7+
class TinyGenerateCommand extends Command {
8+
9+
protected $name = 'tiny:generate';
10+
11+
protected $description = "Generate a valid key";
12+
13+
public function fire()
14+
{
15+
$key = Tiny::generate_set();
16+
17+
$path = base_path('.env');
18+
19+
if (file_exists($path) and getenv('LEAGUE_TINY_KEY') !== false) {
20+
$originalContent = file_get_contents($path);
21+
$content = str_replace('LEAGUE_TINY_KEY='.getenv('LEAGUE_TINY_KEY'), 'LEAGUE_TINY_KEY='.$key, $originalContent);
22+
23+
file_put_contents($path, $content);
24+
} else {
25+
$fp = fopen($path, 'a');
26+
fwrite($fp, "\nLEAGUE_TINY_KEY=$key\n");
27+
fclose($fp);
28+
}
29+
30+
$this->info("Tiny key [$key] has been set.");
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php namespace ZackKitzmiller\Laravel5;
2+
3+
use ZackKitzmiller\Tiny;
4+
use Illuminate\Support\ServiceProvider;
5+
6+
class TinyServiceProvider extends ServiceProvider
7+
{
8+
public function boot()
9+
{
10+
$this->app['tiny.generate'] = $this->app->share(function ($app) {
11+
return new TinyGenerateCommand();
12+
});
13+
14+
$this->commands('tiny.generate');
15+
}
16+
17+
public function register()
18+
{
19+
$this->app['tiny'] = $this->app->share(function ($app) {
20+
$key = getenv('LEAGUE_TINY_KEY');
21+
22+
return new Tiny($key);
23+
});
24+
}
25+
26+
public function provides()
27+
{
28+
return array('tiny');
29+
}
30+
}

0 commit comments

Comments
 (0)