Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Persistence in PHP with Doctrine ORM

You're reading from   Persistence in PHP with Doctrine ORM This book is designed for PHP developers and architects who want to modernize their skills through better understanding of Persistence and ORM. You'll learn through explanations and code samples, all tied to the full development of a web application.

Arrow left icon
Product type Paperback
Published in Dec 2013
Publisher Packt
ISBN-13 9781782164104
Length 114 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Kevin Dunglas Kevin Dunglas
Author Profile Icon Kevin Dunglas
Kevin Dunglas
Arrow right icon
View More author details
Toc

Installing Doctrine


The following steps should be performed to install Doctrine:

  1. To install Doctrine, we need to create a file called composer.json in our new blog directory. It lists dependencies of our project as shown in the following code:

    {
        "name": "myname/blog",
        "type": "project",
        "description": "My small blog to play with Doctrine",
    
        "require": {
            "doctrine/orm": "2.4.*"
        },
    
        "autoload": {
            "psr-0": { "": "src/" }
        }
    } 

    This standard JSON file will be parsed by Composer to download and install all dependencies specified. Once installed, Composer will load all classes of these libraries automatically.

    The name, type, and description attributes are optional but it's a good practice to always fill them. They provide general information about the project we are working on.

    The more interesting part of this composer.json file is the require field. In order to get it installed by Composer, all libraries used by our app must be listed here. A lot of PHP libraries are available on Packagist, the default Composer package repository. Of course, it's the case of Doctrine projects.

    Note

    For more information on Packagist, go through the following link: https://packagist.org/

    We indicate that we need the latest minor release of the 2.4 branch of Doctrine ORM. You can set a major or minor version here, and even more complicated things.

    Note

    For more information on a package version, you can refer to the following link: http://getcomposer.org/doc/01-basic-usage.md#package-versions

    The autoload field is here to tell Composer to automatically load classes of our app. We will put our specific code in a directory called src/. Our files and classes will follow the PSR-0 namespacing and file-naming standard.

    Note

    PHP Specification Requests are attempts to improve interoperability of PHP applications and libraries. They are available at http://www.php-fig.org/.

  2. It's time to use Composer to install the ORM. Run the following command:

        php composer.phar install
    

    New files appear in the vendor/ directory. Doctrine ORM has been installed, and Composer was smart enough to get all its dependencies, including Doctrine DBAL and Doctrine Common.

    A composer.lock file has also been created. It contains exact versions of installed libraries. This is useful for deploying applications. Thanks to this file, when running the install command, Composer will be able to retrieve the same versions that have been used in the development.

    Doctrine is now properly installed. Easy, isn't it?

  3. To update libraries when there are new releases in the 2.4 branch, we just need to type the following command:

        php composer.phar update
    
You have been reading a chapter from
Persistence in PHP with Doctrine ORM
Published in: Dec 2013
Publisher: Packt
ISBN-13: 9781782164104
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image