composer one

WBOY
WBOYOriginal
2016-07-29 09:05:461151browse

composer is a PHP package library dependency management tool. If you need to know more about it, you can check the information on the official website. For PHP, composer is really a good thing. Node and npm, Python has pip, and now PHP has also caught up! Let’s try it today

1. First install it

curl -sS https://getcomposer.org/installer | php

2. After the command is run, a composer.phar file will be generated in the current directory, move it Go to the /usr/local/bin directory and install it globally.
3. Create a new composer.json

<code>touch composer<span>.json</span>
vim composer<span>.json</span></code>
<code><span>"require"</span>:{
                <span>"monolog/monolog"</span>:<span>"1.2.*"</span>
                }

}
</code>

Generate the following files in the directory

<code>root<span>@66</span>f625feefa3:~<span># ls</span>
composer<span>.json</span>  composer<span>.lock</span>  vendor</code>

4. When you need to use monolog, introduce 'vendor/autoload.php' in php;

<code><span><span><?php</span><span>require</span><span>'/root/vendor/autoload.php'</span>;
<span>$log</span> = <span>new</span> Monolog\Logger(<span>'name'</span>);
<span>$log</span>->pushHandler(<span>new</span> Monolog\Handler\StreamHandler(<span>'app.log'</span>, Monolog\Logger::WARNING));

<span>$log</span>->addWarning(<span>'Foo'</span>);

<span>?></span></span></span></code>

5.ls View there Is app.log generated

<code>root<span>@66</span>f625feefa3:~<span># ls</span>
app<span>.log</span>  composer<span>.json</span>  composer<span>.lock</span>  test<span>.php</span>  test1<span>.php</span>  vendor
</code>

As expected, app.log is generated

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces composer 1, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn