Skip to main content

On This Page

Using Local Packages with Composer for PHP Development

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

The Scenario

Composer simplifies dependency management for PHP projects, typically fetching libraries from Packagist. However, the repositories option allows overriding dependencies with local directories, crucial when developing or debugging related projects simultaneously.

This feature enables developers to test changes in a library immediately without publishing new versions, streamlining the development workflow and reducing deployment overhead.

Why This Matters

PHP projects often rely on external libraries, but frequent publishing to Packagist can be time-consuming and unnecessary during active development. Maintaining a smooth development loop requires the ability to test local changes in a project context, and relying solely on published versions introduces delays and potential integration issues. Uncoordinated updates can lead to compatibility problems and increased debugging time, costing valuable development resources.

Key Insights

  • repositories option introduced in Composer 1.0: Enables the use of local paths as dependencies.
  • Path-based repositories vs. VCS repositories: Path repositories are simpler for local development, while VCS repositories (like Git) are better for more complex scenarios.
  • symlink option: Composer can create symbolic links to local packages, improving performance and reducing disk space usage.

Working Example

{
"require": {
"storyblok/php-management-api-client": "dev-main",
"vlucas/phpdotenv": "^5.6"
},
"repositories": [
{
"type": "path",
"url": "../php-management-api-client",
"options": {
"symlink": true
}
}
]
}

Practical Applications

  • Use Case: A company developing a custom CMS uses a local path repository to test changes in its core components with a frontend application.
  • Pitfall: Committing the repositories configuration to a public repository can expose internal development paths and unintentionally lock other developers into using local dependencies.

References:

Continue reading

Next article

ICE03 epitomises the potential of a circular economy for data centres

Related Content