forked from illuminate3/rakko
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Carsten
committed
Jun 10, 2015
1 parent
7c29930
commit 1975841
Showing
37 changed files
with
1,608 additions
and
282 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
namespace App\Exceptions\Validation; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Class ValidationException | ||
* @package Fully\Exceptions\Validation | ||
* @author Sefa Karagöz | ||
*/ | ||
class ValidationException extends Exception { | ||
|
||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $errors; | ||
|
||
/** | ||
* @param string $message | ||
* @param int $errors | ||
* @param int $code | ||
* @param Exception $previous | ||
*/ | ||
public function __construct($message, $errors, $code = 0, Exception $previous = null) { | ||
|
||
$this->errors = $errors; | ||
|
||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
/** | ||
* Get error messages | ||
* @return int | ||
*/ | ||
public function getErrors() { | ||
|
||
return $this->errors; | ||
} | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
app/Modules/General/Helpers/ConfigWriter/ConfigServiceProvider.php
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
namespace app\Helpers\ConfigWriter; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class ConfigServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
|
||
$this->app->bind('app\Helpers\ConfigWriter\Repository', function($app) | ||
{ | ||
$loader = $app->getConfigLoader(); | ||
$writer = new FileWriter($loader, $app['path.config']); | ||
return new Repository($loader, $writer, $app['env']); | ||
}); | ||
|
||
$this->app['config'] = $this->app->share(function($app) | ||
{ | ||
return $app->make('app\Helpers\ConfigWriter\Repository'); | ||
}); | ||
} | ||
|
||
|
||
} |
113 changes: 113 additions & 0 deletions
113
app/Modules/General/Helpers/ConfigWriter/FileWriter.php
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
namespace app\Helpers\ConfigWriter; | ||
|
||
use Illuminate\Config\LoaderInterface; | ||
|
||
/* | ||
https://github.com/daftspunk/laravel-config-writer | ||
author: daftspunk ( Samuel Georges ) | ||
license: available on github -- issue #6 put's under MIT | ||
*/ | ||
|
||
class FileWriter | ||
{ | ||
/** | ||
* The filesystem instance. | ||
* | ||
* @var \Illuminate\Filesystem\Filesystem | ||
*/ | ||
protected $files; | ||
|
||
/** | ||
* The loader implementation. | ||
* | ||
* @var \Illuminate\Config\LoaderInterface | ||
*/ | ||
protected $loader; | ||
|
||
/** | ||
* The default configuration path. | ||
* | ||
* @var string | ||
*/ | ||
protected $defaultPath; | ||
|
||
/** | ||
* The config rewriter object. | ||
* | ||
* @var \October\Rain\Config\Rewrite | ||
*/ | ||
protected $rewriter; | ||
|
||
/** | ||
* Create a new file configuration loader. | ||
* | ||
* @param \Illuminate\Filesystem\Filesystem $files | ||
* @param string $defaultPath | ||
* @return void | ||
*/ | ||
public function __construct(LoaderInterface $loader, $defaultPath) | ||
{ | ||
$this->loader = $loader; | ||
$this->files = $loader->getFilesystem(); | ||
$this->defaultPath = $defaultPath; | ||
$this->rewriter = new Rewrite; | ||
} | ||
|
||
public function write($item, $value, $environment, $group, $namespace = null) | ||
{ | ||
$path = $this->getPath($environment, $group, $item, $namespace); | ||
if (!$path) | ||
return false; | ||
|
||
$contents = $this->files->get($path); | ||
$contents = $this->rewriter->toContent($contents, [$item => $value]); | ||
|
||
return !($this->files->put($path, $contents) === false); | ||
} | ||
|
||
private function getPath($environment, $group, $item, $namespace = null) | ||
{ | ||
$hints = $this->loader->getNamespaces(); | ||
|
||
$path = null; | ||
if (is_null($namespace)) { | ||
$path = $this->defaultPath; | ||
} | ||
elseif (isset($this->hints[$namespace])) { | ||
$path = $this->hints[$namespace]; | ||
} | ||
|
||
if (is_null($path)) | ||
return null; | ||
|
||
$file = "{$path}/{$environment}/{$group}.php"; | ||
if ( $this->files->exists($file) && | ||
$this->hasKey($file, $item) | ||
) | ||
return $file; | ||
|
||
$file = "{$path}/{$group}.php"; | ||
if ($this->files->exists($file)) | ||
return $file; | ||
|
||
return null; | ||
} | ||
|
||
private function hasKey($path, $key) | ||
{ | ||
$contents = file_get_contents($path); | ||
$vars = eval('?>'.$contents); | ||
|
||
$keys = explode('.', $key); | ||
|
||
$isset = false; | ||
while ($key = array_shift($keys)) { | ||
$isset = isset($vars[$key]); | ||
} | ||
|
||
return $isset; | ||
} | ||
|
||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
namespace app\Helpers\ConfigWriter; | ||
|
||
use Illuminate\Config\LoaderInterface; | ||
use Illuminate\Config\Repository as RepositoryBase; | ||
|
||
/* | ||
https://github.com/daftspunk/laravel-config-writer | ||
author: daftspunk ( Samuel Georges ) | ||
license: available on github -- issue #6 put's under MIT | ||
*/ | ||
|
||
class Repository extends RepositoryBase | ||
{ | ||
/** | ||
* The config rewriter object. | ||
* | ||
* @var string | ||
*/ | ||
protected $writer; | ||
|
||
/** | ||
* Create a new configuration repository. | ||
* | ||
* @param \Illuminate\Config\LoaderInterface $loader | ||
* @param string $environment | ||
* @return void | ||
*/ | ||
public function __construct(LoaderInterface $loader, $writer, $environment) | ||
{ | ||
$this->writer = $writer; | ||
parent::__construct($loader, $environment); | ||
} | ||
|
||
/** | ||
* Write a given configuration value to file. | ||
* | ||
* @param string $key | ||
* @param mixed $value | ||
* @return void | ||
*/ | ||
public function write($key, $value) | ||
{ | ||
list($namespace, $group, $item) = $this->parseKey($key); | ||
$result = $this->writer->write($item, $value, $this->environment, $group, $namespace); | ||
|
||
if(!$result) throw new \Exception('File could not be written to'); | ||
|
||
$this->set($key, $value); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.