CoursesAI WorkshopCompaniesPricingBlogConfAiBotSign inSubscribe
  • Courses
  • AI Workshop
  • Companies
  • Pricing
  • Blog
  • ConfAiBot
Subscribe
  • Courses
  • Companies
  • Communities
  • Blog
  • Gift card
  • Help
  • Shop
  • ConfAiBot
  • Contact
  • Legal notice
  • General conditions
  • Privacy policy
  • Cookies policy

PHP - Namespaces and Composer Autoloader

20 August 2015 | screencasts

Here is the first of a series of videos on Refactoring. Specifically, in this video we are going to focus on using namespaces following PSR-4 and how this is structured at the autoloader level (taking advantage of Composer's own) and the IDE (adjusting the preferences of PhpStorm). Below I leave the list of topics covered and the times of the video as well as the related material:

Topics Covered

  • Transition from a custom autoloader to using the Composer autoloader
  • Applying namespaces following the PSR-4 standard
  • Optimization of the classmap generated by Composer through the configuration of composer.json
  • Project configuration in PhpStorm to generate the correct namespaces based on the folder structure
  • Moving source files to the src/ folder

Video

Index

  • 0:00 - Current state of the code
  • 3:50 - What is a global namespace and why is it necessary
  • 5:24 - Creating the "src/" folder and configuring PhpStorm to recognize the new global namespace
  • 6:45 - Moving all classes to the new "src/" folder
  • 8:15 - Modifying the classes to introduce the namespace
  • 11:12 - Removing the custom autoloader that was included in the project
  • 11:40 - Modifying the composer.json file to include loading policy in order to properly generate the autoloader
    Autoloader Composer with PSR-4
  • 13:05 - Specification of the optimization of the classmap generated by Composer through the configuration of composer.json
    Optimize composer autoloader by configuration
  • 14:35 - Demonstration of class creation through PhpStorm with automatic generation of the correct namespace
  • 15:58 - Recap and conclusion of the process carried out

Related Material

  • Specification of the PSR-4 standard for PHP namespaces from PHP FIG
  • Examples of PSR-4 implementation
  • How to use PSR-4
  • Explanation and benchmarks on optimizing Composer's autoloader
  • Optimize-autoloader directive of composer.json
  • Documentation on PhpStorm directory settings

Upcoming Videos

  • PHP - Code Style, PSR-1 and PSR-2 Standard (Basic Level)
  • SOLID - Single Responsibility Principle and Interface Segregation Principle (Medium Level)
  • SOLID - Dependency Inversion Principle (Medium Level)
  • DTOs / Anemic Domain Models vs Domain Models (Medium Level)

Tags

AutoloaderComposerBasic LevelPHPPhpStorm
AnteriorPHP - Code Style, PSR 2 Standard
SiguienteCodely.TV Launch - Introduction and Objectives

Pay according to your needs

lite (only monthly)

19 €
per month
  • Access to a subset of courses to lay the foundation for maintainable, scalable, and testable code
  • Company invoice
Popular

standard

24,92 €
Save 121 €
Annual payment of 299 €
per month
  • Full course catalog
  • Receive job offers verified by Codely
  • Company invoice

premium

41,58 €
Save 89 €
Annual payment of 499 €
per month
  • All previous benefits
  • Early access to new courses
  • Discount on workshops

We won't increase the price while your subscription is active