Hey. It has always been interesting to create your own project in composer, as it is a more modular and adequate approach when developing large applications. What is it for? The answer is simple: this is necessary in order to cut your tools into modules that can be used separately. For example, you can create a module to work with sessions, files, and more. Suppose you are making your own framework, which has a lot of self-written modules. And I, as a third party developer, want to use only 1 or 2. I don't need the whole framework! What to do? By resorting to packages (modules), you can provide this flexibility in the toolbox.
To implement simple packages, the composer config file looks like this.
{
"name": "kernel",
"description": "",
"license": "",
"keywords": [
"",
],
"authors": [
{
"name": "",
"email": ""
}
],
"require": {
"php": "^7.4|^8.0"
},
"autoload": {
"psr-4": {
"kernel\\": "kernel"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
But if you want to make a project like Laravel, Yii 2 and other frameworks, then you need to have both the project core and its skeleton. In the case of the kernel, everything is quite transparent - the root folder of all the internals of the framework, where we will not climb. And the skeleton is the wrapper, the structure of the entire project. For example, a skeleton can contain empty folders required by the kernel, root files, and so on.
If you want to work with the kernel and skeleton, then the config file will look like this:
Kenrel
{
"name": "kernel",
"description": "",
"license": "",
"keywords": [
"",
],
"authors": [
{
"name": "",
"email": ""
}
],
"require": {
"php": "^7.4|^8.0"
},
"autoload": {
"psr-4": {
"kernel\\": "kernel"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Skeleton
{
"name": "username/kernel-skeleton",
"type": "project",
"description": "",
"license": "",
"keywords": [
"",
],
"authors": [
{
"name": "",
"email": ""
}
],
"require": {
"php": "^7.4|^8.0",
"username/kernel": "^1.0"
},
"autoload": {
"psr-4": {
"kernel\\": "kernel"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
As you can see, there is some information hidden here, but the whole point is that the kernel is of type type by default and is a library. And the project skeleton has a type project. The kernel and its version were specified in the dependencies.
The launch of the whole miracle was like this: composer create-project HERE_SKELETON PROJECT_NAME
. create-project
will both pull and install all dependencies at once.
Thus, it turns out that to implement the libraries, you need to have only one project on Github, and if you want to use the project format, then you need to create a separate repository for the project skeleton and its core.
Top comments (0)