R
R
Romi2021-05-21 14:27:16
PHP
Romi, 2021-05-21 14:27:16

Where can I find a good Composer tutorial?

I need to make an application that does NOT use frameworks but still uses Composer packages.

Somehow I've already assembled it there and it works, but I don't want to reinvent the wheel. I want to immediately organize the files somehow clearly. And that with namespaces and autoload, and, probably, even a router.

At the same time, I don’t even want to use Lumen. I want to do it from scratch.

Tell me a good little tutorial.

Those. I want to eventually get a kind of Laravel, but without views and everything else.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lander, 2021-05-21
@romicohen

There is a very interesting article on the topic.

P
Pavel Omelchenko, 2021-05-27
@pOmelchenko

Composer is a package manager, you simply describe what dependencies you will have in your project. It also manages the autoloading of classes.
That is, in fact, at the minimum. Any project will have something like the following composer json structure

{
  "name": "pomelchenko/project",
  "type": "project",
  "description": "description",
  "minimum-stability": "stable",
  "license": "proprietary",
  "require": {
    "php": "^7.4",
    // тут зависимости для продакшена, когда будешь устанавливать приложение с флагом --no-dev
  },
  "require-dev": {
    "phpunit/phpunit": "^9.5"
    // тут зависимости для dev среды, с тестами и прочими инструментами которые несут вспомогательный смысл.
  },
  "autoload": {
    "psr-4": {
      "App\\": "src/"
      // тут перечисляешь нэймспэйсы и пути до директорий с классами этих нэймспэйсов для приложения, которое будет на проде крутиться
    }
  },
  "autoload-dev": {
    "psr-4": {
      "Tests\\": "tests/"
      // тут перечисляешь нэймспэйсы и пути до директорий с классами этих нэймспэйсов для вспомогательных инструментов, как правило для тестов
    }
  }
}

After installation, you will have ./vendor/autoload.php which you will connect to the front controller to make it work.
Essentially everything. The rest will come as needed during work.
Need tests? You put in phpunit so that it ends up in require-dev, that is, composer require --dev ...
Do you need packages for the application to work? For example, a router or an orm, just put composer require ... The composer
does nothing more than dependency management. In a sense, it does not affect the business logic and infrastructure (well, except for the autoload of classes and files) of the project.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question