39
Bibliotecas PHP Por Jefersson Nathan

Palestra codephant

Embed Size (px)

Citation preview

Page 1: Palestra codephant

Bibliotecas PHPPor Jefersson Nathan

www.princexml.com
Prince - Non-commercial License
This document was created with Prince, a great way of getting web content onto paper.
Page 2: Palestra codephant

Jefersson Nathanmalukenho is a leader and representative of

the PHP User Group of the State of Sergipe,

Brazil. Where works to keep the local community

strong and united. Currently, he works in a

company focusing on web solutions and devotes

his free time to help with community projects

OpenSources contributions.

- Web and PHP Magazine, May 2013

2

Page 3: Palestra codephant

O que é uma biblioteca?

Page 4: Palestra codephant

Dicio1. ...

2. Coleção de obras de um autor.

3. Coleção de obras sobre assuntos determinados.

4. Coleção de obras de um povo

4

Page 5: Palestra codephant
Page 6: Palestra codephant

Porque usar uma biblioteca?

Page 7: Palestra codephant

Porque?1. Fácilidade para resolver um problema

2. Reusabilidade

3. Confiança

4. Produtividade

5. $$ Dinaro $$

7

Page 8: Palestra codephant

Tipos de biblioteca

Page 9: Palestra codephant

Existem 2 principais tipos de bibliotecas nophp

1. Extensões escritas em C (Ex: SPL)

2. Bibliotecas em PHP (Composer, PHPunit, etc)

9

Page 10: Palestra codephant

bla bla bla bla bla

10

Page 11: Palestra codephant

COMPOSER

Page 12: Palestra codephant

Composer

12

Page 13: Palestra codephant

Instalação$ curl -sS https://getcomposer.org/installer | php

--install-dir=bin

01.

02.

13

Page 14: Palestra codephant

composer.json{

require: {

"respect/validation": "dev-develop",

"phpunit/phpunit": "3.7.*"

}

}

01.

02.

03.

04.

05.

06.

14

Page 15: Palestra codephant

Gerar composer.json$ composer init

15

Page 16: Palestra codephant

Autoloading{

"autoload": {

"psr-0": { "PHPSergipe\\" : "src/"}

}

}

01.

02.

03.

04.

05.

16

Page 17: Palestra codephant

Baixando dependências$ composer install

$ php composer.phar install

01.

02.

17

Page 18: Palestra codephant

Usando as bibliotecasrequire "vendor/autoload.php";

$loader = require "vendor/autoload.php";

$loader->add('PHPSergipe\\codePhant\\', __DIR__);

01.

02.

03.

04.

18

Page 19: Palestra codephant

composer.lockArquivo gerado depois que suas dependências são instaladas.

É altamente recomendável sua distribuição.“19

Page 20: Palestra codephant

PackagistPackagist é o repositório principal do composer. Ele agrega todos os tipos de

pacotes do PHP que são instaláveis com Composer. Aqui você pode procurar

pacotes ou enviar o seu próprio.

packagist.org

“20

Page 21: Palestra codephant
Page 22: Palestra codephant

Distribuindo sua bibliotecaSigam as PSRs

22

Page 23: Palestra codephant

Bibliotecas

23

Page 24: Palestra codephant

24

Page 25: Palestra codephant

Respect\Validation{

"require": {

"respect/validation": "dev-develop"

}

}

01.

02.

03.

04.

05.

25

Page 26: Palestra codephant

Respect\Validation<?php

use Respect\Validation\Validator as v;

$number = 123;

v::numeric()->validate($number); //true

https://github.com/Respect/Validation

01.

02.

03.

04.

05.

26

Page 27: Palestra codephant

Respect\Validation$user = new stdClass;

$user->name = 'PHP Sergipe';

$user->birthdate = '1987-07-01';

$v = v::attribute('name', v::string()->length(1,32))

->attribute('birthdate', v::date()->minimumAge(18));

$v->validate($user); //true

https://github.com/Respect/Validation

01.

02.

03.

04.

05.

06.

07.

08.

27

Page 28: Palestra codephant

Respect\Templateuse Respect\Template\Html;

use Respect\Template\HtmlElement as H;

require __DIR__.'/../tests/bootstrap.php';

$template = new Html('./cssZenGarden.html', '#lselect');

https://github.com/Respect/Template

01.

02.

03.

04.

05.

06.

28

Page 29: Palestra codephant

Respect\Template$template['#pageHeader h1'] = 'codePhant\PHPSergipe';

$template['#preamble .p1'] = H::div(

H::p('Qual o nome do primeiro evento PHP em Sergipe?'),

H::dl(

H::dt('codePhant?'),

H::dd('Yeah!')

)

)->class('p1');

01.

02.

03.

04.

05.

06.

07.

08.

29

Page 30: Palestra codephant

Respect\Template

echo $template->render();

01.

02.

03.

30

Page 31: Palestra codephant
Page 32: Palestra codephant

filp\whoops{

"require": {

"filp/whoops": "1.*"

}

}

01.

02.

03.

04.

05.

32

Page 33: Palestra codephant

filp\whoops$app->register(

new Whoops\Provider\Silex\WhoopsServiceProvider

);

01.

02.

03.

33

Page 34: Palestra codephant

filp\whoopsif ($app['debug']) {

$app->register(

new Whoops\Provider\Silex\WhoopsServiceProvider

);

}

01.

02.

03.

04.

05.

34

Page 35: Palestra codephant
Page 36: Palestra codephant

MENTORING

Page 37: Palestra codephant
Page 38: Palestra codephant

Augusto Pascutti

38

Page 39: Palestra codephant

// Thanks@malukenho

[email protected]

www.jefersson.com.br

39