In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shares with you the content of an example of Composer dependency management. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Stop searching around for PHP class extension packs. For modern languages, package managers are basically standard. Java has Maven,Python, pip,Ruby, gem,Nodejs and npm. PHP is PEAR, but PEAR has a lot of holes:
● dependency processing is prone to problems
● configuration is very complex
Difficult command line interface for ●
Fortunately, we have a powerful tool for Composer,PHP dependency management. It is open source, easy to use, and easy to submit your own packages.
For example, usually if we don't use a framework at the beginning, if we want a CAPTCHA, we have to go to Gihutb or other places to find a CAPTCHA class, then include it in the project, and then edit it, so that later project maintenance may have problems. Open source on Github, it can also click watch, see a Bug fix or a new version released, can follow the upgrade in time.
If you download more expansion packs, you need a variety of include, and there may be namespace conflicts, and you have to change the namespace according to the project. If the expansion pack is upgraded, you have to download and edit it again, which is very inconvenient. So the Composer dependency management library was born.
These are the more important requirements scenarios for Compser.
1. It is easy to install the upgrade expansion pack
two。 Just include, you don't have to write include everywhere
3. Avoid namespace conflicts
Usually go to Github, Mayun and other platforms to find expansion packages, but now there is a website to integrate all the packages, that is to say, the current development method: first search on packagist, and then use Composer to install and upgrade.
Install Composer
For silly installation, just click https://getcomposer.org/Composer-Setup.exe, download and install it. The installer will download Composer for you and set your PATH environment variable so that you can simply Composer call from any directory.
What you need to pay attention to during installation is to find the root directory of php.exe and choose the correct PHP path. Screenshots are not provided here, because I didn't do a good job either, and I installed it manually.
The selection directory should look like this:
D:\ phpStudy\ php\ php-7.0.12-nts\ php.exe
The following focuses on manual installation, which I think is very useful:
First download a composer.phar file, put the phar file in the developer folder, you can do whatever you want, there is no restriction on which folder.
Then open the DOS window, or type cmd with the shortcut key windows+R, and use the following command to go to the directory where you placed the phar file
D:\ developer\ composer > echo @ php "% ~ dp0composer.phar"% * > composer.bat
The sign of successful installation is to enter it on the command line
Composer-v
Display the following
When I see this, I assume that Composer has been successfully installed. In the Chinese LAN, it is relatively slow to use Composer, but fortunately, there is a domestic image. Execute the following command to switch to the domestic image. What the domestic image does is cache all installation packages and metadata to the domestic computer room and accelerate through the domestic CDN, so that you do not have to make a request to foreign websites.
Composer config-g repo.packagist composer https://packagist.phpcomposer.com
This is tantamount to a global configuration change, and I chose to modify the composer.json configuration file of the current project:
{"repositories": {"packagist": {"type": "composer", "url": "https://packagist.phpcomposer.com"}"
Composer common commands
Selfupdate
To update composer itself, execute composer selfupdate frequently to keep Composer up-to-date.
Composer selfupdate
Equivalent to
Composer self-update
Dumpautoload
When we change the autoload in the composer.json file, we need to execute composer dumpautoload for the autoload to take effect immediately. Without having to execute the install or update command.
Composer dumpautoload
Equivalent to
Composer dump-autoload
The dumpautoload command has two common options:
-- optimize (- o): convert PSR-0/4 autoloading to classmap for faster loading. This is especially suitable for production environments, but it may take some time to run, so it is not currently the default setting.
-- no-dev: disable the autoload-dev rule.
Install
Composer install
Install the dependency package according to the dependency defined by the composer.lock (lock file) or composer.json file in the current directory.
The install command first checks whether the composer.lock lock file exists, and if so, it downloads the version specified in the composer.lock file, ignoring the definition in the composer.json file.
# View composer install help information composer install-h# install only the dependencies defined in require, but not the dependency composer install defined in require-dev-no-dev
Update
If you want to update your dependency version, or if you modify the dependency in composer.json and want composer to update as defined in the composer.json file, use the update command.
Composer update
Require
The require command is typically used to install a new dependency package and write the dependency to the composer.json file in the current directory.
If dependencies are added or changed in the composer.json file, the modified dependencies will be installed or updated.
Composer require
You can also specify the dependent packages that need to be installed directly in the command.
Composer require barryvdh/laravel-ide-helper
-- the dev option corresponds to require-dev. If your dependency package is only used in the development environment, it is recommended to add the-- dev option.
Composer require-dev barryvdh/laravel-ide-helper
Create-project
You can use create-project to create a new project from an existing package.
It is equivalent to installing the package's dependencies to its own vendor directory after executing the git clone command.
This command has several common uses:
You can deploy your application quickly.
You can check out any resource pack and develop patches for it.
Multi-person development projects can be used to speed up the initialization of applications.
# install Laravel project composer create-project-- prefer-dist laravel/laravel blog 5.5.*
If no version number is specified, the latest version is installed by default.
-- prefer-dist: install from dist when packages are available.
Failed to install composer in phpStudy integrated environment
Error message:
The "https://getcomposer.org/versions" file could not be downloaded: failed to open stream: the connection attempt failed because the connecting party did not reply correctly or the connected host did not respond after a period of time. The "https://getcomposer.org/download/1.2.0/composer.phar.sig" file could not be downloaded: SSL: crypto enabling timeoutFailed to enable cryptofailed to open stream: operation failed
1. To install composer, you need to enable the openssl extension, while phpstudy is off by default.
2. Copy the ssleay32.dll,libeay32.dll in the php directory and the: php_openssl.dll in the php/ext folder to the WINDOWS\ system32 folder.
3. Openssl requires CA certificate and phpstudy does not have it.
Download address of CA certificate:
Http://curl.haxx.se/docs/caextract.html
Right-click after selection and select Save as
Put it under the tmp folder after the download is successful.
4. Then modify the php.ini file
Openssl.cafile = "D:\ phpStudy\ tmp\ cacert.pem"
5. Restart phpStudy and get an error message:
Failed to open stream: HTTP request failed!
1. Check whether the curl extension of php is enabled.
2. Check whether these two configurations are enabled.
Allow_url_fopen = Onuser_agent= "PHP"
You can also configure user_agent= "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)")
Simulated browser access is also a good choice.
3. Restart phpStudy after enabling it.
PS: openssl.cafile configuration option, PHP 5.6.0. Only the above versions are supported.
Thank you for reading! This is the end of this article on "examples of Composer dependency management". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.