first commit
This commit is contained in:
37
vendor/nwidart/laravel-modules/src/Publishing/AssetPublisher.php
vendored
Normal file
37
vendor/nwidart/laravel-modules/src/Publishing/AssetPublisher.php
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Nwidart\Modules\Publishing;
|
||||
|
||||
use Nwidart\Modules\Support\Config\GenerateConfigReader;
|
||||
|
||||
class AssetPublisher extends Publisher
|
||||
{
|
||||
/**
|
||||
* Determine whether the result message will shown in the console.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $showMessage = false;
|
||||
|
||||
/**
|
||||
* Get destination path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDestinationPath()
|
||||
{
|
||||
return $this->repository->assetPath($this->module->getLowerName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSourcePath()
|
||||
{
|
||||
return $this->getModule()->getExtraPath(
|
||||
GenerateConfigReader::read('assets')->getPath()
|
||||
);
|
||||
}
|
||||
}
|
39
vendor/nwidart/laravel-modules/src/Publishing/LangPublisher.php
vendored
Normal file
39
vendor/nwidart/laravel-modules/src/Publishing/LangPublisher.php
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Nwidart\Modules\Publishing;
|
||||
|
||||
use Nwidart\Modules\Support\Config\GenerateConfigReader;
|
||||
|
||||
class LangPublisher extends Publisher
|
||||
{
|
||||
/**
|
||||
* Determine whether the result message will shown in the console.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $showMessage = false;
|
||||
|
||||
/**
|
||||
* Get destination path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDestinationPath()
|
||||
{
|
||||
$name = $this->module->getLowerName();
|
||||
|
||||
return base_path("resources/lang/{$name}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSourcePath()
|
||||
{
|
||||
return $this->getModule()->getExtraPath(
|
||||
GenerateConfigReader::read('lang')->getPath()
|
||||
);
|
||||
}
|
||||
}
|
43
vendor/nwidart/laravel-modules/src/Publishing/MigrationPublisher.php
vendored
Normal file
43
vendor/nwidart/laravel-modules/src/Publishing/MigrationPublisher.php
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Nwidart\Modules\Publishing;
|
||||
|
||||
use Nwidart\Modules\Migrations\Migrator;
|
||||
|
||||
class MigrationPublisher extends AssetPublisher
|
||||
{
|
||||
/**
|
||||
* @var Migrator
|
||||
*/
|
||||
private $migrator;
|
||||
|
||||
/**
|
||||
* MigrationPublisher constructor.
|
||||
* @param Migrator $migrator
|
||||
*/
|
||||
public function __construct(Migrator $migrator)
|
||||
{
|
||||
$this->migrator = $migrator;
|
||||
parent::__construct($migrator->getModule());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get destination path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDestinationPath()
|
||||
{
|
||||
return $this->repository->config('paths.migration');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSourcePath()
|
||||
{
|
||||
return $this->migrator->getPath();
|
||||
}
|
||||
}
|
195
vendor/nwidart/laravel-modules/src/Publishing/Publisher.php
vendored
Normal file
195
vendor/nwidart/laravel-modules/src/Publishing/Publisher.php
vendored
Normal file
@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace Nwidart\Modules\Publishing;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Nwidart\Modules\Contracts\PublisherInterface;
|
||||
use Nwidart\Modules\Contracts\RepositoryInterface;
|
||||
use Nwidart\Modules\Module;
|
||||
|
||||
abstract class Publisher implements PublisherInterface
|
||||
{
|
||||
/**
|
||||
* The name of module will used.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
/**
|
||||
* The modules repository instance.
|
||||
* @var RepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* The laravel console instance.
|
||||
*
|
||||
* @var \Illuminate\Console\Command
|
||||
*/
|
||||
protected $console;
|
||||
|
||||
/**
|
||||
* The success message will displayed at console.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $success;
|
||||
|
||||
/**
|
||||
* The error message will displayed at console.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $error = '';
|
||||
|
||||
/**
|
||||
* Determine whether the result message will shown in the console.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $showMessage = true;
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*
|
||||
* @param Module $module
|
||||
*/
|
||||
public function __construct(Module $module)
|
||||
{
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the result message.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function showMessage()
|
||||
{
|
||||
$this->showMessage = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the result message.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function hideMessage()
|
||||
{
|
||||
$this->showMessage = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module instance.
|
||||
*
|
||||
* @return \Nwidart\Modules\Module
|
||||
*/
|
||||
public function getModule()
|
||||
{
|
||||
return $this->module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set modules repository instance.
|
||||
* @param RepositoryInterface $repository
|
||||
* @return $this
|
||||
*/
|
||||
public function setRepository(RepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get modules repository instance.
|
||||
*
|
||||
* @return RepositoryInterface
|
||||
*/
|
||||
public function getRepository()
|
||||
{
|
||||
return $this->repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set console instance.
|
||||
*
|
||||
* @param \Illuminate\Console\Command $console
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConsole(Command $console)
|
||||
{
|
||||
$this->console = $console;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get console instance.
|
||||
*
|
||||
* @return \Illuminate\Console\Command
|
||||
*/
|
||||
public function getConsole()
|
||||
{
|
||||
return $this->console;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get laravel filesystem instance.
|
||||
*
|
||||
* @return \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
public function getFilesystem()
|
||||
{
|
||||
return $this->repository->getFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get destination path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getDestinationPath();
|
||||
|
||||
/**
|
||||
* Get source path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getSourcePath();
|
||||
|
||||
/**
|
||||
* Publish something.
|
||||
*/
|
||||
public function publish()
|
||||
{
|
||||
if (!$this->console instanceof Command) {
|
||||
$message = "The 'console' property must instance of \\Illuminate\\Console\\Command.";
|
||||
|
||||
throw new \RuntimeException($message);
|
||||
}
|
||||
|
||||
if (!$this->getFilesystem()->isDirectory($sourcePath = $this->getSourcePath())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->getFilesystem()->isDirectory($destinationPath = $this->getDestinationPath())) {
|
||||
$this->getFilesystem()->makeDirectory($destinationPath, 0775, true);
|
||||
}
|
||||
|
||||
if ($this->getFilesystem()->copyDirectory($sourcePath, $destinationPath)) {
|
||||
if ($this->showMessage === true) {
|
||||
$this->console->components->task($this->module->getStudlyName(), fn () => true);
|
||||
}
|
||||
} else {
|
||||
$this->console->components->task($this->module->getStudlyName(), fn () => false);
|
||||
$this->console->components->error($this->error);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user