-
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.
Merge pull request #2 from Gerfey/LDS-AL-create_basic_structures
v0.1
- Loading branch information
Showing
14 changed files
with
507 additions
and
49 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 |
---|---|---|
@@ -1,44 +1,45 @@ | ||
{ | ||
"name": "gerfey/laravel-domain-skeleton", | ||
"description": "Make a Domain skeleton", | ||
"license": "MIT", | ||
"homepage": "https://vk.com/gerfey", | ||
"keywords": [ | ||
"gerfey", | ||
"laravel", | ||
"domain", | ||
"skeleton", | ||
"laravel-domain-skeleton" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Alexander Levchenkov", | ||
"email": "sanjia@live.ru" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Gerfey\\LaravelDomainSkeleton\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Gerfey\\LaravelDomainSkeleton\\Tests\\": "tests/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "0.0.1-dev" | ||
"name": "gerfey/laravel-domain-skeleton", | ||
"description": "Make a Domain skeleton", | ||
"license": "MIT", | ||
"homepage": "https://vk.com/gerfey", | ||
"keywords": [ | ||
"gerfey", | ||
"laravel", | ||
"domain", | ||
"skeleton", | ||
"laravel-domain-skeleton" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Alexander Levchenkov", | ||
"email": "sanjia@live.ru" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.1", | ||
"gerfey/repository": "@dev" | ||
}, | ||
"laravel": { | ||
"providers": [ | ||
"Gerfey\\LaravelDomainSkeleton\\LaravelDomainSkeletonServiceProvider" | ||
] | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
"autoload": { | ||
"psr-4": { | ||
"Gerfey\\LaravelDomainSkeleton\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Gerfey\\LaravelDomainSkeleton\\Tests\\": "tests/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "0.1.0-dev" | ||
}, | ||
"laravel": { | ||
"providers": [ | ||
"Gerfey\\LaravelDomainSkeleton\\LaravelDomainSkeletonServiceProvider" | ||
] | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
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,80 @@ | ||
<?php | ||
|
||
return [ | ||
[ | ||
'name' => 'Database', | ||
'type' => 'dir', | ||
'children' => [ | ||
[ | ||
'name' => 'Migrations', | ||
'type' => 'dir', | ||
'children' => [] | ||
], | ||
[ | ||
'name' => 'Models', | ||
'type' => 'dir', | ||
'children' => [ | ||
[ | ||
'name' => '_DomainName_.php', | ||
'type' => 'file', | ||
'template' => 'Model' | ||
] | ||
] | ||
], | ||
[ | ||
'name' => 'Repository', | ||
'type' => 'dir', | ||
'children' => [ | ||
[ | ||
'name' => '_DomainName_Repository.php', | ||
'type' => 'file', | ||
'template' => 'Repository' | ||
] | ||
] | ||
] | ||
] | ||
], | ||
[ | ||
'name' => 'Http', | ||
'type' => 'dir', | ||
'children' => [ | ||
[ | ||
'name' => 'Controller', | ||
'type' => 'dir', | ||
'children' => [ | ||
[ | ||
'name' => '_DomainName_Controller.php', | ||
'type' => 'file', | ||
'template' => 'Controller' | ||
] | ||
] | ||
], | ||
[ | ||
'name' => 'Middleware', | ||
'type' => 'dir', | ||
'children' => [] | ||
], | ||
[ | ||
'name' => 'Requests', | ||
'type' => 'dir', | ||
'children' => [] | ||
] | ||
] | ||
], | ||
[ | ||
'name' => 'Routes', | ||
'type' => 'dir', | ||
'children' => [ | ||
[ | ||
'name' => 'api.php', | ||
'type' => 'file', | ||
'template' => 'Api' | ||
] | ||
] | ||
], | ||
[ | ||
'name' => '_DomainName_ServicesProvider.php', | ||
'type' => 'file', | ||
'template' => 'ServicesProvider' | ||
] | ||
]; |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Gerfey\LaravelDomainSkeleton; | ||
|
||
use Exception; | ||
use Gerfey\LaravelDomainSkeleton\Storage\StorageDomainSkeleton; | ||
|
||
class LaravelDomainSkeleton | ||
{ | ||
/** | ||
* @var | ||
*/ | ||
protected $domainName; | ||
|
||
/** | ||
* @param string $domainName | ||
*/ | ||
public function setNameDomain(string $domainName): void | ||
{ | ||
$this->domainName = $domainName; | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function make(): void | ||
{ | ||
$storage = new StorageDomainSkeleton(); | ||
try { | ||
$storage->createStructure($this->domainName); | ||
} catch (Exception $e) { | ||
throw new Exception($e->getMessage()); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Gerfey\LaravelDomainSkeleton\Storage; | ||
|
||
use Exception; | ||
use Gerfey\LaravelDomainSkeleton\Storage\Structures\DirectoryStructure; | ||
use Gerfey\LaravelDomainSkeleton\Storage\Structures\FileStructure; | ||
|
||
class StorageDomainSkeleton | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $structurePath = __DIR__ . '/../../config/structure.php'; | ||
|
||
/** | ||
* @param string $domainName | ||
* @throws Exception | ||
*/ | ||
public function createStructure(string $domainName) | ||
{ | ||
$pathDomainName = config('default_directory.domain') . '/' . $domainName; | ||
$pathDirectoryDomain = app_path($pathDomainName); | ||
|
||
if (!file_exists($pathDirectoryDomain)) { | ||
if (!$this->createRootDirectoryDomain($pathDirectoryDomain)) { | ||
throw new Exception('Error creating a directory: ' . $pathDomainName); | ||
} | ||
} else { | ||
throw new Exception('Directory on the path: ' . $pathDomainName . ' already exists.'); | ||
} | ||
|
||
foreach ($this->getStructure() as $structure) { | ||
switch ($structure['type']) { | ||
case 'dir': | ||
$structure = new DirectoryStructure($structure, $domainName); | ||
break; | ||
case 'file': | ||
$structure = new FileStructure($structure, $domainName); | ||
break; | ||
} | ||
|
||
try { | ||
$structure->make($pathDirectoryDomain); | ||
} catch (Exception $e) { | ||
throw new Exception($e->getMessage()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param string $pathDirectoryDomain | ||
* @return bool | ||
*/ | ||
private function createRootDirectoryDomain(string $pathDirectoryDomain): bool | ||
{ | ||
return mkdir($pathDirectoryDomain); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getStructure(): array | ||
{ | ||
return require $this->structurePath; | ||
} | ||
} |
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,54 @@ | ||
<?php | ||
|
||
namespace Gerfey\LaravelDomainSkeleton\Storage\Structures; | ||
|
||
use Exception; | ||
|
||
class DirectoryStructure extends Structure | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
protected $children; | ||
|
||
/** | ||
* @param array $params | ||
* @param string $domainName | ||
*/ | ||
public function __construct(array $params, string $domainName) | ||
{ | ||
parent::__construct($params, $domainName); | ||
|
||
$this->children = $params['children']; | ||
} | ||
|
||
/** | ||
* @param string $pathDirectoryName | ||
* @return bool | ||
* | ||
* @throws Exception | ||
*/ | ||
protected function create(string $pathDirectoryName): bool | ||
{ | ||
if (mkdir($pathDirectoryName)) { | ||
if (count($this->children) > 0) { | ||
foreach ($this->children as $structure) { | ||
switch ($structure['type']) { | ||
case 'dir': | ||
$structure = new DirectoryStructure($structure, $this->domainName); | ||
break; | ||
case 'file': | ||
$structure = new FileStructure($structure, $this->domainName); | ||
break; | ||
} | ||
|
||
$structure->make($pathDirectoryName); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
Oops, something went wrong.