-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init: First version of public implementation
- Loading branch information
0 parents
commit bd2fa94
Showing
21 changed files
with
2,441 additions
and
0 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,92 @@ | ||
Package manager | ||
=============== | ||
|
||
Search all package dependencies automatically and register to your project. | ||
|
||
**Please help improve code and documentation in English. Pull requests and issues are very welcomed!** | ||
|
||
Install | ||
------- | ||
|
||
Simply use Composer: | ||
|
||
``` | ||
composer require baraja-core/package-manager | ||
``` | ||
|
||
And add to your project `composer.json` this `scripts` section: | ||
|
||
```json | ||
"scripts": { | ||
"post-autoload-dump": "Baraja\\PackageManager\\PackageRegistrator::composerPostAutoloadDump" | ||
} | ||
``` | ||
|
||
Now is your project configured. | ||
|
||
After each `composer ...` command this Package Manager will be called automatically. | ||
|
||
How to use | ||
---------- | ||
|
||
In `Booting` class add create new instance of `PackageRegistrator`: | ||
|
||
```php | ||
$packageRegistrator = new PackageRegistrator( | ||
__DIR__ . '/../', // root path | ||
__DIR__ . '/../temp' // temp path | ||
); | ||
``` | ||
|
||
**Notice:** PackageRegistrator can work alone, Nette framework is not required, only recommended. | ||
|
||
Package.neon | ||
------------ | ||
|
||
Imagine you want install new package. Then it you must set specific configuration to your project `common.neon`. | ||
|
||
PackageRegistrator can scan all your installed packages and automatically create `package.neon` file with merged configuration. In your `common.neon` you define changes only and required parameters. | ||
|
||
For correct work to `app/Booting.php` add generated configuration. | ||
|
||
```php | ||
$configurator->addConfig(__DIR__ . '/config/package.neon') | ||
``` | ||
|
||
> **Warning:** Configuration file can be different in all environment. Commit to repository is not recommended. | ||
Tasks | ||
----- | ||
|
||
After creating internal container with list of packages, call list of special tasks. | ||
|
||
Default task list (but you can add more): | ||
|
||
- Config local neon creator and normalizer | ||
- Assets from packages copier | ||
- Project `composer.json` normalizer | ||
- Clear cache | ||
|
||
Default project assert manager | ||
------------------------------ | ||
|
||
In case of your package contain directory with name `install` or `update`, all inner content will be copied to your project automatically. | ||
|
||
Structure in directory is same as your project root. | ||
|
||
Name convention: | ||
|
||
- `install` copy file and directories only in case when does not exist in your project structure, | ||
- `update` rewrite your project files in all composer actions. | ||
|
||
If you want create file `jquery.js` to `/www/js` for example, simply define package structure: | ||
|
||
``` | ||
/src | ||
- files... | ||
/install | ||
/www | ||
/js | ||
- jquery.js | ||
- composer.json | ||
``` |
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,23 @@ | ||
{ | ||
"name": "baraja-core/package-manager", | ||
"description": "Search all package dependencies automatically and register to your project.", | ||
"homepage": "https://github.com/baraja-core/package-manager", | ||
"authors": [ | ||
{ | ||
"name": "Jan Barášek", | ||
"homepage": "http://baraja.cz" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.1.0", | ||
"ext-PDO": "*", | ||
"ext-json": "*", | ||
"nette/application": "^3.0" | ||
}, | ||
"autoload": { | ||
"classmap": [ | ||
"src/" | ||
] | ||
}, | ||
"minimum-stability": "stable" | ||
} |
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,7 @@ | ||
parameters: | ||
packageRegistrator: | ||
customPackagesNamePatterns: | ||
- '^baraja-' | ||
|
||
tracy: | ||
showLocation: 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,147 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\PackageManager; | ||
|
||
|
||
use Nette\Neon\Neon; | ||
use Nette\SmartObject; | ||
|
||
class Package | ||
{ | ||
|
||
use SmartObject; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var null|string | ||
*/ | ||
private $version; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $dependency; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var mixed[] | ||
*/ | ||
private $composer; | ||
|
||
/** | ||
* @param string $name | ||
* @param string|null $version | ||
* @param string $dependency | ||
* @param string[] $config | ||
* @param mixed[] $composer | ||
*/ | ||
public function __construct(string $name, ?string $version, string $dependency, array $config, array $composer) | ||
{ | ||
$this->name = $name; | ||
$this->version = $version; | ||
$this->dependency = $dependency; | ||
$this->config = $config; | ||
$this->composer = $composer; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return null|string | ||
*/ | ||
public function getVersion(): ?string | ||
{ | ||
return $this->version; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDependency(): string | ||
{ | ||
return $this->dependency; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getConfig(): array | ||
{ | ||
return $this->config; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getComposer(): array | ||
{ | ||
return $this->composer; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getParameters(): array | ||
{ | ||
return $this->getConfigProperty('parameters'); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getServices(): array | ||
{ | ||
return $this->getConfigProperty('services'); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getRouters(): array | ||
{ | ||
return $this->getConfigProperty('routers'); | ||
} | ||
|
||
/** | ||
* @param string[] $parent | ||
* @return string[] | ||
*/ | ||
public function getMenu(array $parent = []): array | ||
{ | ||
return $parent !== [] ? $parent : $this->getConfigProperty('menu'); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* @return string[][] | ||
*/ | ||
private function getConfigProperty(string $key): array | ||
{ | ||
if (isset($this->getConfig()[$key])) { | ||
if ($this->getConfig()[$key]['rewrite'] === true) { | ||
return $this->getConfig()[$key]['data']; | ||
} | ||
|
||
return Neon::decode($this->getConfig()[$key]['data']); | ||
} | ||
|
||
return []; | ||
} | ||
|
||
} |
Oops, something went wrong.