Download the PHP package mistralys/composer-local-switcher without Composer

On this page you can find all versions of the php package mistralys/composer-local-switcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package composer-local-switcher

Composer local switcher

PHP library that handles switching between live and local Composer dependencies using Composer scripts.

How it works

Two configurations

The main composer.json file is switched between two configurations:

NOTE: The lock file follows the switching so you can run composer commands separately for each configuration.

Local development with symlinks

Using a list of local packages and their paths, the library will replace the packages in the composer.json file with path repositories that use symlinks to work directly with local package clones. When switching back to production mode, the original composer.json and lock file are restored.

Library refactoring made easy

The library is intended to make local development of interdependent Composer packages easier, especially when coupled with an IDE like PHPStorm that can work with multiple projects at the same time. Refactoring classes in a library can then be done in the library project, and the changes will be immediately available in the project that uses the library.

Setup

1. Local repository configuration

To specify which repositories to switch in the configuration, create a JSON file anywhere you like in your project with the following structure:

All packages listed here will be replaced with path repositories when switching to development mode, and restored to their original configuration when switching back to production mode.

For packages that do not already have an entry in the repositories section of the composer.json file, a new entry will be added.

NOTE: See the section Using specific package versions for more information about the optional version property.

2. Production configuration

Copy your existing composer.json file to a new file, for example composer-production.json. This file will be used as the base configuration when switching back to production mode.

WARNING: From now on, only edit the composer-production.json file. The composer.json file will be modified automatically when switching between configurations.

3. Composer script handler class

Composer scripts are typically static methods in a class, which are called by Composer when the script is executed.

You can use the following class as a starting point for your project:

NOTE: Adjust the paths in the createSwitcher() method to point to your local configuration files, as well as the autoloader path if needed.

4. Set up switching scripts

We will be adding scripts to the composer.json file to switch between development and production configurations, as well as update the current configuration.

NOTE: It's good practice to also have a build script that ensures the configuration is set to production mode before deploying the project. This will minimize the risk of accidentally deploying with development dependencies.

Vendor dependencies in attached projects

A drawback of attaching local packages using path repositories is that the vendor dependencies of the attached packages will be included in the class index of the IDE, causing duplicate class messages to appear, and clicking on classes may be confusing at it often does not open the file you expect.

To fix this, I usually attach a separate local clone of the package I wish to attach. In this clone, I do not run composer install to avoid creating a vendor folder altogether. This way, the IDE's index stays clean, and no confusion is possible.

Script usage

Once the setup is complete, you can use the following Composer commands to switch between the configurations.

Switch to development mode

Switch to production mode

Update current configuration

This command will re-apply the current configuration (DEV or PROD) to update the configurations based on which files have been modified. Use this if you modified either the composer-production.json or the composer.json file directly.

Options

Flag files

These files are created in the same folder as the composer.json file to make the current configuration mode easily visible when looking in a file browser.

They are enabled by default, but can be disabled:

Console logging

By default, only relevant messages are printed to the console. You can enable verbose logging to see all actions taken by the library:

Using specific package versions

By default, path packages get the version constraint * to always use the latest version from the local path. This will not work in all cases however: If you have other version constraints in your require section for the same package, you will get a Composer error like this:

To work around this, you can optionally specify a version to use for packages in the local repositories configuration file:

{ "local-repositories": [ { "package-name": "vendor/package-name", "path": "/path/to/package", "version": "1.2.3" } ] }

The repository will still be loaded as a path repository, but the specified version will be used whenever Composer needs to resolve the package version.

NOTE: The only drawback of this approach is that you will need to maintain the version number manually in the configuration file.

Version control

Here is what you should and should not commit to version control:

NOTE: It is good practice to add a template for the dev-config.json file to version control, so other developers can use this to create their own local configuration file. This is typically named something like dev-config.dist.json.

Why PHP v7.3?

The library is currently used in a legacy Composer environment that is still running PHP v7.3. It is planned to be modernized, but until then this package will remain compatible with PHP v7.3.


All versions of composer-local-switcher with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mistralys/composer-local-switcher contains the following files

Loading the files please wait ....