Composer command line interface and commands (Part 3)
This is the third part of the Composer command line interface and commands.
The “composer remove” command removes packages installed and registered in the composer.json file from the working directory. An example is shown in the code snippet below:
composer remove vendor_name/package_name
The above command completely removes the package with the name given in the command. This composer removes command also accepts a series of options. As discussed below:
- --dev: This removes the packages listed in the “require-dev” of the composer.json file
- --no-progress: This removes the progress display while executing these commands, thus preserving terminals that cannot handle backslashes.
- --no-update: This command disables the automatic update of installed packages.
- --no-scripts: This causes composer to skip the execution of scripts listed in the composer.json file.
- --update-no-dev: This updates our dependencies with the --no-dev option.
- --update-with-dependencies: Also update dependencies of the newly required packages, and that of removed packages.
- --ignore-platform-reqs: This tells composer to ignore php, hhvm, lib-* and ext-* requirements and force the installation even when the target machine does not meet the specifications.
- --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production but can take a bit of time to run so it is currently not done by default.
- --classmap-authoritative (-a): This only autoloads classes from the classmap only. It implicitly enables “--optimize-autoloader”.
- --apcu-autoloader: It tells composer to use APCu to cache found/not-found classes.
composer remove -–apcu-autoloader
The “composer check-platform-reqs” command checks that your PHP and extensions versions match the platform requirements of the installed packages. This can be used to verify that a production server has all the extensions needed to run a project after installation. An example is shown in the below code snippet.
The composer global command allows you to run other commands like install, remove, require or update as if you were running them from the COMPOSER_HOME directory. This is used to manage projects stored in a central location which can hold CLI tools or composer plugins that would be made available to all parts of the project.
composer global install friendsofphp/php-cs-fixer
In the above example, the package installed was installed globally and can be accesses from anywhere in our system including the global vendor binaries directory is our your $PATH environment variable.
This location can be gotten using the following command
composer global config bin-dir --absolute
Globally installed packages can also be updated if need be using the following commands:
composer global update
The search command allows us to search and navigate through the current project's package repositories. This used Packagist by default. When searching, you can simply pass your search parameters as shown in the code snippet below:
composer search monolog
We can also search by passing some of the optional flag parameters:
- --only-name (-N): This flag causes search to be performed only in name
- --type (-t): This searches on a specific package type.
This is used to list all the available packages, in our project. An example of the “composer show” command is shown in the code snippet below.
To trim down the show results, wild cards can be used as shown in the following code snippet:
composer show monolog/*
If you want to see a certain package detail, you can achieve this by passing the package name as a parameter.
composer show monolog/monolog
The versions of a package can also be passed, which will give us the details of that package version if installed as shown:
composer show monolog/monolog 1.0.2
Other optional parameters can also be passed to the “composer show” command, the comprehensive list of this commands is shown below:
- --all : This is used to list all the packages present in our repositories
- --installed (-i): Though this command has been deprecated, its used to show all the installed packages.
- --platform (-p): This list only platform packages (php & extensions).
- --available (-a): This command also lists only the available packages
- --self (-s): It causes the root package info to be displayed.
- --name-only (-N): Displays only package names without descriptions.
- --path (-P): This list package paths only.
- --tree (-t): This lists our packages dependencies as a tree. If a package name is passed it will show the dependency tree for that package.
- --latest (-l): This lists all the installed packages together with their latest versions.
- --outdated (-o): This command invariably Implies --latest, but this only lists packages that have a newer version available.
composer show –-outdated
- --minor-only (-m): This is used, together with --latest. It shows packages that have minor SemVer-compatible updates.
- --direct (-D): Using this command restricts the list of packages to your direct dependencies.
- --strict: When there are outdated packages, a non-zero exit code would be returned.
- --format (-f): With this command, formatting options could be picked. you pick between text (default) or json output format.
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework