Composer

Composer

Proper Autoloading

About Class naming, folder naming, namespaces, etc

"autoload": {
    "psr-4": { "": "src/" }
}

This tells Composer to use the src directory to find all classes that it doesn’t already know using the “PSR-4” standard. The details of that standard are not that important right now. Basically it says: “inside this directory, all namespaces are represented by sub directories and classes are .php files.”

Autoloading is PHP’s way to automatically find classes and their corresponding files without having to require all of them manually. You can read more about it here. Autoloading is also one of the reasons why PHP code is usually organized in classes because PHP only supports autoloading for classes, not simple functions for example.

Namespaces and Autoloading — PHP Introduction — A short introduction to PHP web development

Autoloading files

If you want to autoload functions, you can use files autoloading. This can be useful to load your helper functions, but these files will be loaded on every request.

{ “autoload”: { “files”: [“src/helpers.php”] } }

Autoloading performance: Classmap vs PSR-4

NAJZAD SAM SHVATIO!

Note on Classmap and PSR-4

Classmap autoloading is the fastest among autoloaders since it loads classes from the prebuilt array. But the problem with classmap is that you need to regenerate the classmap array every time you create a new class file. So in the development environment PSR-4 autoloading will be the most suited one.

PSR-4 autoloading will be slower compared to classmap because, it needs to check the filesystem before resolving a classname conclusively. But in production you want things to be as fast as possible.

For this reason, composer offers classmap generation from PSR-4. Classmap generation converts all PSR-4/PSR-0 rules into classmap rules. So autoloading will be faster. If a PSR-4 class is not found in the generated classmap, the autoloading fallback to PSR-4 rules.

Why

require DIR . ‘/vendor/autoload.php’; and not require ‘vendor/autoload.php’;

PHP scripts run relative to the current path (result of getcwd()), not to the path of their own file. Using DIR forces the include to happen relative to their own path.

Symfony / Fairwalter

Composer thing

Optimize Class Autoloader

There are a few options to enable this:

  • Not using: Set “optimize-autoloader”: true inside the config key of composer.json
  • composer install or update with -o (–optimize-autoloader)
  • Not using: composer dump-autoload with -o / (–optimize) - see)

Problem with migrations:

https://www.reddit.com/r/PHP/comments/46dif0/symfony2_migrations_for_different_environments/ https://medium.com/@galopintitouan/executing-database-migrations-at-scale-with-symfony-and-doctrine-4c60f86865b4


Better permissions

SAVRŠENO: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-symfony-application-to-production-on-ubuntu-14-04

detaljno pročitaj: https://unix.stackexchange.com/questions/364517/difference-between-chmod-vs-acl https://serverfault.com/questions/847803/correct-permissions-for-www-data

rsync is dropping permissions https://unix.stackexchange.com/questions/93868/using-setfacl-to-create-recursive-permissions-for-apache-with-rsync

rsync –archive
https://unix.stackexchange.com/questions/12198/preserve-the-permissions-with-rsync

sudo setfacl -R -m u:www-data:rX . sudo setfacl -R -m u:www-data:rwX ./var/cache ./var/log sudo setfacl -dR -m u:www-data:rwX ./var/cache ./var/log


https://symfony.com/doc/current/performance.html#optimize-composer-autoloader


php bin/console doctrine:cache:clear-result php bin/console doctrine:cache:clear-query php bin/console doctrine:cache:clear-metadata


This seems quite interesting? Install all packages from normal PHP without having Composer wintercms/packager: Run Composer commands within a PHP application

date 06. Nov 2020 | modified 10. Jun 2024
filename: PHP » Composer and Autoloader