Suyati Technologies
  • Services
    • Custom Development
    • Salesforce
    • Analytics
    • Enablers
      • RPA
      • Cloud
      • Testing as a Service
  • Intel
    • Blog
    • eBooks
    • Webinars
    • Case Studies
  • About Us
    • Management Team
    • Advisory Board
    • Our Story
    • Testimonials
  • Careers
  • Contact Us
Suyati Technologies
  • Services
    • Custom Development
    • Salesforce
    • Analytics
    • Enablers
      • RPA
      • Cloud
      • Testing as a Service
  • Intel
    • Blog
    • eBooks
    • Webinars
    • Case Studies
  • About Us
    • Management Team
    • Advisory Board
    • Our Story
    • Testimonials
  • Careers
  • Contact Us
Suyati Technologies > Blog > Composer In PHP Rapid Development

Composer In PHP Rapid Development

by Tony Benny July 9, 2014
by Tony Benny July 9, 2014 0 comment

Introduction

Composer is used for Package Management in PHP. It gives the facility for you to declare libraries of your own as well as custom libraries and it will install them in your project for you.
Composer is not a package manager or a library manager alone but it manages your library for a per project basis so it is actually a dependency manager.
Composer is highly inspired by node’s npm and ruby’s bundler.
The solution provided by Composer?
a) My project depends on PHPUnit Library.
b)PHPUnit Library depend on other libraries.
c)The things on which My project depends is declared
d) Composer look for which versions of which packages is required to be installed, and installs them (Meaning it downloads them into My project).

Declaring dependencies

Let’s conside the senarion in which you are developing a project, and library is required that does unit Testing as well as Integration Testing. PHPUnit is decided by you to use. In order to add it to your project, all you require to do is to make a composer.json file which outlines the project’s dependencies.

We are simply stating that our project requires phpunit/phpunit package, any version beginning with 3.7.14

System Requirements For Using Composer

Composer requires PHP 5.3.2+ to run. A few php settings and compile flags are also needed, but the installer will advise you about any incompatibilities.
If packages is to be installed from sources instead of simple zip archives, you require git(a distributed revision control), svn(version control system) or hg depending on how the package is version-controlled.
Composer is multi-platform and we can make it run equally well on Windows, Linux ,OSX.

Installation – *nix

Downloading the Composer Executable
Locally
To actually get Composer, we need to do two things.
The step one is to install Composer(again, which means downloading it into your project):
$ curl -sS https://getcomposer.org/installer | php
Or download composer.phar into your project root.
Install Dependencies
Execute this in your project root.
php composer.phar install
This will just check a few PHP settings and then download composer.phar to your working directory. This file is the Composer binary. It is a PHAR (PHP archive), which is an archive format for PHP which can be run on the command line, along with other things.
The Composer can be installed to a specific directory by using the –install-dir option and providing a target directory (it can be an absolute or relative path):
$ curl -sS https://getcomposer.org/installer | php — –install-dir=bin
Globally
The composer file can be placed wherever you desire. If you put it in your PATH, it can be accessed globally. On unixy machines it can be made executable and invoke it without php.
These commands can be run to easily access composer from anywhere on your system:
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer

Note: If any of the above commands did not work due to permissions, run the mv command line again with sudo.
Then, simply run composer in order to run Composer instead of php composer.phar.
Globally (on OSX via homebrew)
Composer is a portion of the homebrew-php project.
1. Tap the homebrew-php repository to the brew installation if it is not done so yet: brew tap josegonzalez/homebrew-php
2. Run brew install josegonzalez/php/composer.
3. Use Composer with the composer command.
Note: If you get an error saying PHP53 or higher is missing , Kindly use this command to install php brew install php53-intl

Installation – Windows

Using the Installer
This is the best way of getting Composer set up on your Windows Machine.
Download and run Composer-Setup.exe, this will install the latest version of Composer and set up your PATH so that you just need to call composer from any directory in your command line.

Manual Installation

Change to a directory on your PATH and run the install snippet to get composer.phar downloaded to your machine:
C:Usersusername>cd C:bin
C:bin>php -r “readfile(‘https://getcomposer.org/installer’);” | php

Note: If the above command fails due to readfile, try to use the http url or kindly enable php_openssl.dll in php.ini
Make a new composer.bat file alongwith composer.phar:
C:bin>echo @php “%~dp0composer.phar” %*>composer.bat
Close your current terminal. Test usage with a new terminal:
C:Usersusername>composer -V
Composer version 27d8904
C:Usersusername>

Using Composer

We require Composer to install the project dependencies.
To resolve and download dependencies, run the install command:
$ php composer.phar install
If a global install is done and if you do not have the phar in that directory run this instead:
$ composer install
Autoloading
Apart from downloading the library, Composer also makes an autoload file that’s capable of autoloading all of the classes in any of the libraries that it downloads. To make use of it, following line needs to be added to your code’s bootstrap process:
require ‘vendor/autoload.php’;
Inorder to Run the PHPunit you need to execute the command vendo/bin/phpunit from your project Document root.
While writing tests for my project I needed to install phpdocumentor for my project for more code readability. So I need to just add a line in my composer.json(refer above in Declaring dependencies)

and just give $ composer update.
With this I got the phpdocumentor installed in my project.

Conclusion

Composer thus helps us in rapid PHP development making us free of thinking about which all dependencies need to be installed and also gives our project a package format so that it can be made to a finished software product easily with all the Software methodologies inbuilt in that.
Happy Composer!!!
Sources:
http://getcomposer.org/doc/00-intro.md

php composerphp rapid development
0 comment
0
FacebookTwitterLinkedinTumblr
previous post
How to effectively engage with online customers
next post
SuyatiSTEP 2K14 – "Transformation into an IT Professional”

You may also like

Einstein Analytics & Salesforce CRM Empowering Sales Teams

February 7, 2023

Resolve Cases Easily with Interactive Einstein Search Answers

February 7, 2023

2023 AI Landscape: Key Developments

February 7, 2023

An analytical breakdown of DataOps and its core...

January 5, 2023

Watch Out for These 5 Cloud Computing Trends...

January 5, 2023

How Artificial Intelligence is Improving Customer Experience

January 5, 2023

Top 10 Strategic Technology Trends for 2023

January 4, 2023

How can Enterprises Benefit from DevOps?

January 4, 2023

Leveraging DevOps Capabilities in the Telecom Sector

January 3, 2023

Know more about the Salesforce Winter ’23 Release...

December 12, 2022

Leave a Comment Cancel Reply

Save my name, email, and website in this browser for the next time I comment.

Keep in touch

Twitter Linkedin Facebook Pinterest

Recent Posts

  • Einstein Analytics & Salesforce CRM Empowering Sales Teams

    February 7, 2023
  • Resolve Cases Easily with Interactive Einstein Search Answers

    February 7, 2023
  • 2023 AI Landscape: Key Developments

    February 7, 2023

Categories

  • Twitter
  • Linkedin
  • Facebook
  • Instagram
  • Services
    • Custom Development
    • Salesforce
    • Analytics
    • Enablers
      • RPA
      • Cloud
      • Testing as a Service
  • Intel
    • Blog
    • eBooks
    • Webinars
    • Case Studies
  • About Us
    • Management Team
    • Advisory Board
    • Our Story
    • Testimonials
  • Careers
  • Contact Us

© 2022 Suyati Technologies


Back To Top
Suyati Technologies

Popular Posts

  • MongoDB vs. Couchbase

    May 26, 2013
  • 2

    What is Salesforce CRM and What Does it Do?

    February 19, 2014
  • 3

    A step-by-step guide to configuring emails in MS Dynamics CRM

    April 27, 2017
  • 4

    Top 10 ETL Tools for Salesforce Data Migration 2021

    January 4, 2021
  • 5

    Steps to Migration – Salesforce Classic to Lightning

    September 1, 2021
© 2022 Suyati Technologies

Read alsox

How exciting is the all new ASP.NET 5 Beta7 ?

October 1, 2015

EPiServer Behavioral Merchandising: The right products for the right customers

September 30, 2015

Role of digital signage in healthcare

October 27, 2016
Suyati Logo

Leaving So Soon?

Know more about business technology platforms for your enterprise.

Thank you!

We're glad to have you as part of our community. You'll start receiving updates shortly. Please feel free to contact us anytime with feedback or suggestions.

By continuing to use this website you agree with our use of cookies. Read More Agree