Skip to content

Instantly share code, notes, and snippets.

@digitalbocca
Last active March 7, 2017 13:44
Show Gist options
  • Save digitalbocca/4981a5012f1fb80a0161179c2b5cb3a3 to your computer and use it in GitHub Desktop.
Save digitalbocca/4981a5012f1fb80a0161179c2b5cb3a3 to your computer and use it in GitHub Desktop.
Como usar Autoload PSR4 Com Composer.

Instale o Composer no seu projeto:

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

ou

php -r "readfile('https://getcomposer.org/installer');" | php

Crie o arquivo composer.json com o texto.

{
    "autoload": {
        "psr-4": {
                "Foo\\Bar\\": "src/"
        }
    }
}

Instale as Dependências sempre que alterar o arquivo.

php composer.phar install

Incluindo suas classes:

<?php
//Inserindo o Autoload.
require_once("vendor/autoload.php");

//Usando a Classe
$minhaClasse = new Foo\Bar;

Atualizando Dependencias:

composer update

Otimizando o autoload:

composer dump-autoload -o
composer dump-autoload -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment