SlideShare una empresa de Scribd logo
1 de 177
Descargar para leer sin conexión
Create a PHP Library the Right
way
By Christian Varela
@gabriel0702
cvarela@conquerorsoft.com
https://joind.in/talk/de19a
1
Slides at:
https://www.slideshare.net/
ChristianVarela5/create-a-php-library-
the-right-way
2
Requirements
3
https://goo.gl/StPczG
Christian Varela
➤ I have a wife and 3 daughters
➤ I am from Mexico
➤ Master Degree in Computer Science
➤ 13 years programming with PHP
➤ I live in Miami
➤ I created Conqueror Soft Inc
➤ I play guitar and piano
4
5
Conqueror Soft will take your business to the next Level!
6
www.conquerorsoft.com
info@conquerorsoft.com
facebook.com/conquerorsoft
What is this session about?
Have you found yourself wondering how to take advantage of
what you have developed in the past for current or future
projects? Are you tired of copying/pasting then adapting from
your previous projects to the new ones? Start developing for
the future and contribute to others by developing libraries and
sharing them for use. Where do you start? You’ll be guided
through this tutorial step by step to include security, tests and
all the factors you need to consider when building a library.
7
Library / Package
A Software Library is a collection of methods, functions, classes,
etc, that provides a particular functionality to be used or reused
partially or in whole as part of a more complex system.
It is independent enough to be integrated as a functional block or
module along with other libraries to achieve a common goal.
It can be used by multiple systems that have no connections or
relations between them.
8
9
Why should I create libraries?
1. They provide reusability
2. They can help open source
3. They are modular in functionality context
4. They are easier to maintain
10
Web application
A web application is an application running in the web and
that provides a solution to a particular problem.
The application can have modules, programs, configuration
files, etc, all connected and related in a way that each piece
provides a specific purpose and that all together accomplish a
common goal.
11
Web application
1. Served by a server
2. Requested by a user (through a browser)
3. Can interact with DBs
4. Use third party libraries
5. Use private libraries
6. Has configuration files
12
Web application
13
Web Application
Web Server
Application Server
DB Server
Internal dependencies
External dependencies
Configuration files
14
15
How the web application
knows about its dependencies?
16
17
Web Application
Web Server
Application Server
DB Server
Internal dependencies
External dependencies
Configuration files
Dependencies!?!?
composer.json
COMPOSER
Dependency manager
18
Composer
1. Composer is a tool for dependency management in PHP. It
allows you to declare the libraries your project depends on
and it will manage (install/update) them for you.
2. Enables you to declare the libraries you depend on.
3. Finds out which versions of which packages can and need to
be installed, and installs them
19
composer.json
1. This is all you need to specify dependencies
2. This file is used when creating libraries and / or projects
3. "require" key specifies which packages your project needs
4. "repositories" key specifies where to find those packages
20
composer.json keys (most popular)
1. name
2. description
3. type
4. keywords
5. homepage
6. authors
7. support
8. require
9. require-dev
10.suggest
11.autoload
12.autoload-dev
13.repositories
14.scripts
21
Where composer get the
packages from?
22
23
Packages!?!?
packagist.org packagist.com custom repositories
PACKAGIST.ORG
Composer repository
24
packagist.org
Packagist is the main Composer repository. A Composer
repository is basically a package source: a place where you can
get packages from. Packagist aims to be the central repository
that everybody uses. This means that you can
automatically require any package that is available there, without
further specifying where Composer should look for the package.
25
PACKAGIST.COM
Composer repository
26
packagist.com
Private Packagist is a commercial package hosting product
offering professional support and web based management of
private and public packages, and granular access permissions.
Private Packagist provides mirroring for packages' zip files which
makes installs faster and independent from third party systems -
e.g. you can deploy even if GitHub is down because your zip files
are mirrored.
27
CUSTOM
REPOSITORIES
From different VCS
28
Custom repositories
The following repository types are supported:
1. composer: A Composer repository is simply a packages.json file served via the
network (HTTP, FTP, SSH), that contains a list of composer.json objects with
additional dist and/or sourceinformation. The packages.json file is loaded using a
PHP stream. You can set extra options on that stream using the options parameter.
2. vcs: The version control system repository can fetch packages from git, svn, fossil
and hg repositories.
3. pear: With this you can import any pear repository into your Composer project.
4. package: If you depend on a project that does not have any support for composer
whatsoever you can define the package inline using a package repository. You
basically just inline the composer.json object.
29
Platform packages
1. Required system packages
2. Not installed by composer
3. Examples:
1. php
2. php extensions (ext-gd)
3. php libraries (lib-curl)
30
Autoloading
1. Uses "autoload" key and PRS-4
2. vendor/autoload.php is generated by Composer
3. autoload.php is regenerated with composer dump-autoload
31
PSR-4
1. PHP Standard Recommendation 4
2. describes a specification for autoloading classes from file
paths. It is fully interoperable, and can be used in addition to
any other autoloading specification, including PSR-0. This
PSR also describes where to place files that will be autoloaded
according to the specification.
32
Packages versioning
33
Versioning (when developing)
1. They can be handled manually in composer.json
2. They can be handled using a Version Control System (VCS,
this is recommended)
1. By using branches
2. By using tags (this is recommended)
3. Use a consistent versioning standard, like SemVer.org (this is
recommended)
34
Versioning (when installing dependencies)
1. Use constraints
1. Exact version (1.2.3)
2. Version range (>=2.0 <3.0)
3. with hyphen (1.1.0 - 1.2.0, equals to >=1.1.0 <= 1.2.0)
4. with wildcard (1.1.*, equals to >=1.1 <1.2)
5. with tilde (~1.3.1, equals to >=1.3.1 <1.4.0)
6. with caret (^0.3, equals to >=0.3 <0.4.0)
35
SemVer
Given a version number MAJOR.MINOR.PATCH, increment the:
1. MAJOR version when you make incompatible API changes,
2. MINOR version when you add functionality in a backwards-
compatible manner, and
3. PATCH version when you make backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as
extensions to the MAJOR.MINOR.PATCH format.
http://semver.org/
36
License for your library
37
License for your library
38https://choosealicense.com/
Minimum-stability options
1. dev
2. alpha
3. beta
4. RC
5. stable
39
Code Quality
40
PSR-2
1. This guide extends and expands on PSR-1, the basic coding
standard.
2. The intent of this guide is to reduce cognitive friction when
scanning code from different authors. It does so by enumerating a
shared set of rules and expectations about how to format PHP code.
3. it helps to have one set of guidelines to be used among all those
projects.
4. There are tools to help to comply with this (php code sniffer is
recommended)
41http://www.php-fig.org/psr/psr-2/
PHP Code Sniffer
PHP_CodeSniffer is a set of two PHP scripts; the
main phpcs script that tokenizes PHP, JavaScript and CSS files to
detect violations of a defined coding standard, and a
second phpcbf script to automatically correct coding standard
violations. PHP_CodeSniffer is an essential development tool
that ensures your code remains clean and consistent.
42
Changelog
43
Changelog
1. it is a file which contains a curated, chronologically ordered
list of notable changes for each version of a project.
2. it makes it easier for users and contributors to see precisely
what notable changes have been made between each release
(or version) of the project.
44
Changelog rules
1. There should be an entry for every single version.
2. Same types of changes should be grouped
3. Versions and sections should be linkable
4. The latest version comes first
5. The release date of each versions is displayed
6. SemVer as versioning (recommended)
45
Changelog changes
1. Added for new features.
2. Changed for changes in existing functionality.
3. Deprecated for soon-to-be removed features.
4. Removed for now removed features.
5. Fixed for any bug fixes.
6. Security in case of vulnerabilities.
46
Continuos Integration tools
47
Travis CI prerequisites
1. GitHub login
2. Project hosted as a repository on GitHub
3. Working code in your project
4. Working build or test script
5. Travis CI .org for public repositories
6. Travis CI .com for private repositories
48
Travis CI
1. Sign in to Travis using GitHub account
2. Activate GitHub repositories
3. Add a .travis.yml file
4. Add the .travis.yml file to git, commit and push, to trigger a
Travis CI build
5. Check the build status page to see if your build passes or fails
6. Github will have the service in the web hooks settings.
49
Scrutinizer CI
1. Sign in to Scrutinizer using GitHub account
2. Activate GitHub repositories
3. Add a .scrutinizer.yml file
4. Add the .scrutinizer.yml file to git, commit and push, to
trigger a Scrutinizer CI build
5. Check the build status page to see code quality and coverage
6. Github will have the service in the web hooks settings.
50
Composer install
51
Composer
install
composer.json?
Yes
composer.lock?
Yes
files match?
Yes Install libraries
from
composer.lock
Error
No
Install libraries
from
composer.json
No
Error
No
Generate
composer.lock
Composer update
52
Composer
install
composer.json?
Yes
composer.lock?
Yes
files match?
Yes
Install most
recent versions
Error
No
Install libraries
from
composer.json
No
Error
No
Generate
composer.lock
Generate
composer.lock
Exercise 1. Creating a library
composer.json file manually
53
Exercise 1
1. cd ~ && mkdir -p phplibrary/exercise1
2. cd phplibrary/exercise1
3. Create composer.json
4. composer validate
5. composer install
54
Exercise 1 values for composer.json
1. name: php_library_right_way/exercise1
2. description: "Creating a composer.json file manually"
3. require: php ^5.6 || ^7.0
4. require-dev: phpunit/phpunit ^5.7
5. type: library
6. License: MIT
55
Exercise 1 solution
1 {
2 "name": "php_library_right_way/exercise1",
3 "description": "Creating a composer.json file manually",
4 "require": {
5 "php": "^5.6 || ^7.0"
6 },
7 "require-dev": {
8 "phpunit/phpunit": "^5.7"
9 },
10 "type": "library",
11 "license": "MIT"
12 }
56
Exercise 2. Creating a library
composer.json file using
composer init
57
Exercise 2
1. cd ~ && mkdir -p phplibrary/exercise2
2. cd phplibrary/exercise2
3. composer init
4. composer validate
5. composer install
58
Exercise 2 values for composer.json
1. name: php_library_right_way/exercise2
2. description: "Created with composer init"
3. Author: your name and email
4. require: php ^5.6 || ^7.0
5. require-dev: phpunit/phpunit ^5.7
6. type: library
7. License: MIT
8. Others: leave default
59
Exercise 2 solution
1 {
2 "name": "php_library_right_way/exercise2",
3 "description": "Created with composer init",
4 "type": "library",
5 "require": {
6 "php": "^5.6 || ^7.0"
7 },
8 "require-dev": {
9 "phpunit/phpunit": "^5.7"
10 },
11 "license": "MIT",
12 "authors": [
13 {
14 "name": "Christian Varela",
15 "email": "cvarela@conquerorsoft.com"
16 }
17 ]
18 }
60
Exercise 3. Creating my first
library
61
Repositories
1. https://github.com/ConquerorSoft/my_first_library
2. https://github.com/ConquerorSoft/my_first_project
62
Exercise 3
1. cd ~ && mkdir -p phplibrary/my_first_library
2. Create a README.md file
63
README.md
1 # My First Library #
2
3 This is my very first library I created at php[world].
64
Exercise 3
3. git init
4. git add .
git commit -m "First commit"
5. git tag -a v0.1.0 -m "version 0.1.0"
6. Create a repository in GitHub
7. Connect your repository with GitHub
65
66
67
Exercise 3
8. composer init
9. provide the following values
68
Exercise 3 values for composer init
1. name: php_library_right_way/my_first_library
2. description: "Created with composer init”
3. Author: your name and email
4. require: php ^5.6 || ^7.0
5. require-dev: phpunit/phpunit ^5.7
6. type: library
7. License: MIT
8. Others: leave default
69
Exercise 3 composer.json
1 {
2 "name": "php_library_right_way/my_first_library",
3 "description": "Created with composer init",
4 "type": "library",
5 "require": {
6 "php": "^5.6 || ^7.0"
7 },
8 "require-dev": {
9 "phpunit/phpunit": "^5.7"
10 },
11 "license": "MIT",
12 "authors": [
13 {
14 "name": "Christian Varela",
15 "email": "cvarela@conquerorsoft.com"
16 }
17 ]
18 }
70
Exercise 3
10. commit to git
git add .
git commit -m "Composer init"
git tag -a v0.1.1 -m "version 0.1.1"
git push -u origin master
git push origin v0.1.1
11.composer install
12.echo "composer.lock" >> .gitignore
71
Exercise 3 (click link)
13.Create a CHANGELOG.md file
72
1 # Changelog #
2
3 All notable changes to this library will be documented in this file.
4
5 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
8 ## [Unreleased] ##
9
10 ## [0.1.2] - 2017-11-04 ##
11 ### Added ###
12 - CHANGELOG.md file created
13
14 ### Changed ###
15 - .gitignore file ignores composer.lock
16 - README.md add steps and fixes
17
18 ## [0.1.1] - 2017-11-04 ##
19 ### Added ###
20 - composer init ran
21 - composer.json file created
22 - .gitignore file created to ignore vendor directory
23
24 ### Changed ###
25 - README.md file has more steps
26
27 ## [0.1.0] - 2017-11-04 ##
28 ### Added ###
29 - README.md file created
73
Exercise 3
14. commit to git
git add .
git commit -m "Changelog file added"
git tag -a v0.1.2 -m "version 0.1.2"
git push -u origin master
git push origin v0.1.2
15.mkdir src && mkdir tests
16.add the next to the composer.json file (click link)
74
1 {
2 ...
3 "keywords": [
4 "conquerorsoft",
5 "my_first_library",
6 "tutorial",
7 "phpworld 2017",
8 "workshop"
9 ],
10 "homepage": "http://www.conquerorsoft.com/my_first_library",
11 "require-dev": {
12 "phpunit/phpunit": “^5.7”,
13 "squizlabs/php_codesniffer": "3.*"
14 },
15 "require": {
16 "php": "~5.6 || ~7.0"
17 },
18 "autoload": {
19 "psr-4": {
20 "conquerorsoftmy_first_library": "src"
21 }
22 },
23 "autoload-dev": {
24 "psr-4": {
25 "conquerorsoftmy_first_library": "tests"
26 }
27 },
28 "scripts": {
29 "test": "phpunit",
30 "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set
ignore_warnings_on_exit 1 src tests",
31 "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set
ignore_warnings_on_exit 1 src tests"
32 },
33 ...
34 } 75
Exercise 3
17.create phpunit.xml (click link)
1 <?xml version="1.0" encoding="UTF-8"?>
2 <phpunit bootstrap="vendor/autoload.php"
3 colors="true"
4 verbose="true"
5 convertErrorsToExceptions="true"
6 convertNoticesToExceptions="true"
7 convertWarningsToExceptions="true">
8 <testsuites>
9 <testsuite name="conquerorsoft my_first_library Test Suite">
10 <directory>tests</directory>
11 </testsuite>
12 </testsuites>
13 <filter>
14 <whitelist>
15 <directory suffix=".php">src/</directory>
16 </whitelist>
17 </filter>
18 <logging>
19 <log type="tap" target="build/report.tap"/>
20 <log type="junit" target="build/report.junit.xml"/>
21 <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
22 <log type="coverage-text" target="build/coverage.txt"/>
23 <log type="coverage-clover" target="build/logs/clover.xml"/>
24 </logging>
25 </phpunit>
76
Exercise 3
18.echo build >> .gitignore
19.composer update
20.commit to git
git add .
git commit -m "Preparation for development"
git tag -a v0.1.3 -m "version 0.1.3"
git push -u origin master
git push origin v0.1.3
77
Exercise 3
21.Add a LICENSE.md file (for this example we chose MIT, click link)
22.vim tests/FirstClassTest.php
23.vim src/FirstClass.php
24.commit to git
git add .
git commit -m "Encode and decode string functionality"
git tag -a v0.1.4 -m "version 0.1.4"
git push -u origin master
git push origin v0.1.4
78
Exercise 3
25.add docblock to everything
/**
* This is a summary example
*
* This is a description
*
* @example this is tag
*/
79
Exercise 3
26.commit to git
git add .
git commit -m "Docblocks added everywhere"
git tag -a v0.1.5 -m "version 0.1.5"
git push -u origin master
git push origin v0.1.5
27.add repository to Travis and create travis configuration file
80
.travis.yml (click link)
1 dist: trusty
2 language: php
3
4 php:
5 - 5.6
6 - 7.0
7 - 7.1
8 - hhvm
9
10 # This triggers builds to run on the new TravisCI infrastructure.
11 # See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
12 sudo: false
13
14 ## Cache composer
15 cache:
16 directories:
17 - $HOME/.composer/cache
18
19 matrix:
20 include:
21 - php: 5.6
22 env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
23
24 before_script:
25 - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
26
27 script:
28 - vendor/bin/phpcs --standard=psr2 src/
29 - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
30
31 after_script:
32 - |
33 if [[ "$TRAVIS_PHP_VERSION" != 'hhvm' && "$TRAVIS_PHP_VERSION" != '7.0' ]]; then
34 wget https://scrutinizer-ci.com/ocular.phar
35 php ocular.phar code-coverage:upload --format=php-clover coverage.clover
36 fi
81
82
83
84
85
86
87
88
89
Exercise 3
28.commit to git
git add .
git commit -m "Travis CI integration"
git tag -a v0.1.6 -m "version 0.1.6"
git push -u origin master
git push origin v0.1.6
29. make sure version for phpunit is ^5.7 in composer.json to
support php 5.6
90
Exercise 3
30.commit to git
git add .
git commit -m "Phpunit version changed to support php version
5.6"
git tag -a v0.1.7 -m "version 0.1.7"
git push -u origin master
git push origin v0.1.7
91
Exercise 3
31.get travis badge to put in README.md
92
Exercise 3
32. Put license badge in README
[![Software License][ico-license]](LICENSE.md)
[ico-license]: https://img.shields.io/badge/license-MIT-
brightgreen.svg?style=flat
93
94
Exercise 3
33.commit to git
git add .
git commit -m "Travis CI and License badges in README"
git tag -a v0.1.8 -m "version 0.1.8"
git push -u origin master
git push origin v0.1.8
34.Create scrutinizer-ci account and link with GitHub
35.Create .scrutinizer.yml file
95
.scrutinizer.yml (click link)
1 filter:
2 excluded_paths: [tests/*]
3
4 checks:
5 php:
6 remove_extra_empty_lines: true
7 remove_php_closing_tag: true
8 remove_trailing_whitespace: true
9 fix_use_statements:
10 remove_unused: true
11 preserve_multiple: false
12 preserve_blanklines: true
13 order_alphabetically: true
14 fix_php_opening_tag: true
15 fix_linefeed: true
16 fix_line_ending: true
17 fix_identation_4spaces: true
18 fix_doc_comments: true
19
20 tools:
21 external_code_coverage:
22 timeout: 600
23 runs: 3
96
97
98
99
100
101
102
103
104
105
106
Exercise 3
36.Get scrutinizer badges in README file
107
Exercise 3
37.commit to git
git add .
git commit -m "Scrutinizer CI and badges in README"
git tag -a v0.1.9 -m "version 0.1.9"
git push -u origin master
git push origin v0.1.9
38.Make sure there are no type hinting for PHP 7.0 only
108
109
Exercise 3
39.commit to git
git add .
git commit -m "Fixes to uncompatible type hinting"
git tag -a v0.1.10 -m "version 0.1.10"
git push -u origin master
git push origin v0.1.10
40.Apply any patch proposed from scrutinizer
110
Exercise 3
41.commit to git
git add .
git commit -m "Spacing patch from scrutinizer applied"
git tag -a v0.1.11 -m "version 0.1.11"
git push -u origin master
git push origin v0.1.11
111
Exercise 3
42.Create contributing files
1. CONTRIBUTING.md (click link)
2. CODE_OF_CONDUCT.md (click link)
112
Exercise 3
43.Add more sections to README file
1. Install
2. Usage
3. Change log
4. Testing
5. Contributing
6. Security
7. Credits
8. License
113
Exercise 3
44.commit to git
git add .
git commit -m "Improvements to README"
git tag -a v0.1.12 -m "version 0.1.12"
git push -u origin master
git push origin v0.1.12
45.Add .gitattributes file to ignore some files or folders when --
prefer-dist is used
114
Exercise 3
46.commit to git
git add .
git commit -m ".gitattributes file created"
git tag -a v0.1.13 -m "version 0.1.13"
git push -u origin master
git push origin v0.1.13
115
Exercise 3
47.create an account in packagist.org and submit your library using your github
repository
48.Make your package in packagist to be autoupdated on push
49.Add last version in packagist badge to README.md file
[![Latest Version on Packagist][ico-version]][link-packagist]
[ico-version]: https://img.shields.io/packagist/v/conquerorsoft/
my_first_library.svg?style=flat
[link-packagist]: https://packagist.org/packages/conquerorsoft/my_first_library
116
117
118
119
120
121
122
123
124
Exercise 3
50.commit to git
git add .
git commit -m "Instructions to use packagist.org in README"
git tag -a v0.1.14 -m "version 0.1.14"
git push -u origin master
git push origin v0.1.14
125
Exercise 3
51.create gh-pages branch
git checkout -b gh-pages
git push -u origin gh-pages
git checkout master
52.Go to github settings for your repository
53.Choose a theme in GitHub Pages section
54.Your library page is ready: https://conquerorsoft.github.io/
my_first_library/
126
127
128
129
Exercise 3
54.Your library page is ready: https://conquerorsoft.github.io/
my_first_library/
55.commit to git
git add .
git commit -m "Documentation instructions for the library"
git tag -a v1.0.0 -m "version 1.0.0"
git push -u origin master
git push origin v1.0.0
130
131
Exercise 4. Creating my first
project using my first library
132
Exercise 4
1. cd ~ && mkdir -p phplibrary/my_first_project && cd
phplibrary/my_first_project
2. create a README.md file
133
README.md
1 # My First Project #
2
3 This is my very first project I created at php[world].
134
Exercise 4
3. git init
4. commit to git
git add .
git commit -m "First commit of my project"
5. Assign a version to your project
git tag -a v0.1.0 -m "version 0.1.0"
6. Create a repository in GitHub
135
Exercise 4
7. connect your repository
git remote add origin https://github.com/ConquerorSoft/
my_first_project.git
git push -u origin master
git push origin v0.1.0
8. composer init
9. Provide the next values
136
Exercise 4 values for composer.json
1. name: php_library_right_way/my_first_project
2. description: "Project created with composer init"
3. require: php ^5.6 || ^7.0
4. require-dev:
1. phpunit/phpunit latest ^5.7
2. squizlabs/php_codesniffer 3.*
5. type: project
6. License: MIT
7. Author: your name and email
8. Others: leave default
137
Exercise 4 composer.json
1 {
2 "name": "conquerorsoft/my_first_project",
3 "description": "Project created with composer init",
4 "type": "project",
5 "require": {
6 "php": "^5.6 || ^7.0"
7 },
8 "require-dev": {
9 "phpunit/phpunit": "^5.7",
10 "squizlabs/php_codesniffer": "3.*"
11 },
12 "license": "MIT",
13 "authors": [
14 {
15 "name": "Christian Varela",
16 "email": "cvarela@conquerorsoft.com"
17 }
18 ]
19 }
138
Exercise 4
10.edit composer to include your library
139
Exercise 4 composer.json
1 {
2 "name": "conquerorsoft/my_first_project",
3 "description": "Project created with composer init",
4 "type": "project",
5 "repositories": [
6 {
7 "type": "vcs",
8 "url": "/Users/gabriel/phplibrary/my_first_library"
9 }
10 ],
11 "require": {
12 "php": "^5.6 || ^7.0",
13 "conquerorsoft/my_first_library": "^0.1"
14 },
15 "require-dev": {
16 "phpunit/phpunit": "^5.7",
17 "squizlabs/php_codesniffer": "3.*"
18 },
19 "license": "MIT",
20 "authors": [
21 {
22 "name": "Christian Varela",
23 "email": "cvarela@conquerorsoft.com"
24 }
25 ]
26 }
140
Exercise 4
11.commit to git
git add .
git commit -m "Composer init"
git tag -a v0.1.1 -m "version 0.1.1"
git push -u origin master
git push origin v0.1.1
12.composer install
13.create a CHANGELOG.md file (click link)
141
1 # Changelog #
2
3 All notable changes to this library will be documented in this file.
4
5 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
8 ## [Unreleased] ##
9
10 ## [0.1.2] - 2017-11-09 ##
11 ### Added ###
12 - CHANGELOG.md file created
13
14 ### Changed ###
15 - README.md add steps and fixes
16
17
18 ## [0.1.1] - 2017-11-09 ##
19 ### Added ###
20 - composer init ran
21 - composer.json file created
22 - .gitignore file created to ignore vendor directory
23 - composer.lock file created
24
25 ### Changed ###
26 - README.md file has more steps and fixes
27
28 ## [0.1.0] - 2017-11-09 ##
29 ### Added ###
30 - README.md file created 142
Exercise 4
14.commit to git
git add .
git commit -m "Changelog file added"
git tag -a v0.1.2 -m "version 0.1.2"
git push -u origin master
git push origin v0.1.2
15.mkdir src && mkdir tests
16.add more information to composer.json
143
1 {
2 ...
3 "keywords": [
4 "conquerorsoft",
5 "my_first_project",
6 "tutorial",
7 "phpworld 2017",
8 "workshop"
9 ],
10 "homepage": "http://www.conquerorsoft.com/my_first_project",
11 "minimum-stability": "stable",
12 "scripts": {
13 "test": "phpunit",
14 "check-style": "phpcs -p --standard=PSR2 --runtime-set
ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src
tests",
15 "fix-style": "phpcbf -p --standard=PSR2 --runtime-set
ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src
tests"
16 }
17 ...
18 }
144
Exercise 4
17.create phpunit.xml (click link)
1 <?xml version="1.0" encoding="UTF-8"?>
2 <phpunit bootstrap="vendor/autoload.php"
3 colors="true"
4 verbose="true"
5 convertErrorsToExceptions="true"
6 convertNoticesToExceptions="true"
7 convertWarningsToExceptions="true">
8 <testsuites>
9 <testsuite name="conquerorsoft my_first_project Test Suite">
10 <directory>./tests</directory>
11 </testsuite>
12 </testsuites>
13 <filter>
14 <whitelist>
15 <directory suffix=".php">src/</directory>
16 </whitelist>
17 </filter>
18 <logging>
19 <log type="tap" target="build/report.tap"/>
20 <log type="junit" target="build/report.junit.xml"/>
21 <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
22 <log type="coverage-text" target="build/coverage.txt"/>
23 <log type="coverage-clover" target="build/logs/clover.xml"/>
24 </logging>
25 </phpunit>
145
Exercise 4
18.echo build >> .gitignore
19.composer update
20.commit to git
echo "build/" >> .gitignore
git add .
git commit -m "Preparation for development"
git tag -a v0.1.3 -m "version 0.1.3"
git push -u origin master
git push origin v0.1.3
146
Exercise 4
21.Add a LICENSE.md file (for this example we chose MIT click
link)
22.Create tests/FirstProjectClassTest.php
23.Create src/FirstProjectClass.php
24.Add the next sections to composer.json
147
1 {
2 ...
3 "autoload": {
4 "psr-4": {
5 "conquerorsoftmy_first_project": "src"
6 }
7 },
8 "autoload-dev": {
9 "psr-4": {
10 "conquerorsoftmy_first_project": "test"
11 }
12 },
13 ...
14 }
148
Exercise 4
25.composer dump-autoload
26.commit to git
git add .
git commit -m "Classes from project calling my library"
git tag -a v0.1.4 -m "version 0.1.4"
git push -u origin master
git push origin v0.1.4
27.add repository to Travis and create travis configuration file
149
.travis.yml (click link)
1 dist: trusty
2 language: php
3
4 php:
5 - 5.6
6 - 7.0
7 - 7.1
8 - hhvm
9
10 # This triggers builds to run on the new TravisCI infrastructure.
11 # See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
12 sudo: false
13
14 ## Cache composer
15 cache:
16 directories:
17 - $HOME/.composer/cache
18
19 matrix:
20 include:
21 - php: 5.6
22 env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
23
24 before_script:
25 - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
26
27 script:
28 - vendor/bin/phpcs --standard=psr2 src/
29 - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
30
31 after_script:
32 - |
33 if [[ "$TRAVIS_PHP_VERSION" != 'hhvm' && "$TRAVIS_PHP_VERSION" != '7.0' ]]; then
34 wget https://scrutinizer-ci.com/ocular.phar
35 php ocular.phar code-coverage:upload --format=php-clover coverage.clover
36 fi
150
151
152
153
Exercise 4
28.commit to git
git add .
git commit -m "Travis CI integration"
git tag -a v0.1.5 -m "version 0.1.5"
git push -u origin master
git push origin v0.1.5
29.Change composer.json to use github repository instead of file
system local folder
154
1 {
2 ...
3 "repositories": [
4 {
5 "type": "vcs",
6 "url": "https://github.com/ConquerorSoft/
my_first_library"
7 }
8 ],
9 ...
10 }
155
Exercise 4
30.composer update
31.commit to git
git add .
git commit -m "VCS reference changed for my_first_library in
composer.json"
git tag -a v0.1.6 -m "version 0.1.6"
git push -u origin master
git push origin v0.1.6
32.Remove references for repositories in composer.json
156
Exercise 4
33.Run composer update
composer clearcache
composer update
34.commit to git
git add .
git commit -m "my_first_library is now taken from packagist"
git tag -a v0.1.7 -m "version 0.1.7"
git push -u origin master
git push origin v0.1.7
157
Exercise 4
35.Link scrutinizer-ci account with github and
create .scrutinizer.yml file
158
.scrutinizer.yml (click link)
1 filter:
2 excluded_paths: [tests/*]
3
4 checks:
5 php:
6 remove_extra_empty_lines: true
7 remove_php_closing_tag: true
8 remove_trailing_whitespace: true
9 fix_use_statements:
10 remove_unused: true
11 preserve_multiple: false
12 preserve_blanklines: true
13 order_alphabetically: true
14 fix_php_opening_tag: true
15 fix_linefeed: true
16 fix_line_ending: true
17 fix_identation_4spaces: true
18 fix_doc_comments: true
19
20 tools:
21 external_code_coverage:
22 timeout: 600
23 runs: 3
159
Exercise 4
36.commit to git
git add .
git commit -m "Scrutinizer support added"
git tag -a v0.1.8 -m "version 0.1.8"
git push -u origin master
git push origin v0.1.8
37.change composer.json to require version ^1.0.0 for my_first_library
38.composer update
160
Exercise 4
39.commit to git
git add .
git commit -m "Using version ^1.0 from my_first_library"
git tag -a v0.1.9 -m "version 0.1.9"
git push -u origin master
git push origin v0.1.9
40.Create contributing files: CONTRIBUTING.md and
CODE_OF_CONDUCT.md
161
Exercise 4
41.Add more sections to README
1. Install
2. Change log
3. Testing
42.commit to git
git add .
git commit -m "Improvements to README"
git tag -a v0.1.10 -m "version 0.1.10"
git push -u origin master
git push origin v0.1.10
162
Exercise 4
43.submit the package to packagist.org using the github repository
44.Make the package to be autoupdated in packagist on push
1. Go to your GitHub repository
2. Click the "Settings" button
3. Click "Integrations & services"
4. Add a "Packagist" service, and configure it with your API
token, plus your Packagist username
5. Check the "Active" box and submit the form
163
164
165
166
167
168
Exercise 4
45.Add last version in packagist badge to README.md file
[![Latest Version on Packagist][ico-version]][link-packagist]
[ico-version]: https://img.shields.io/packagist/v/conquerorsoft/
my_first_project.svg?style=flat
[link-packagist]: https://packagist.org/packages/conquerorsoft/
my_first_project
169
Exercise 4
46.commit to git
git add .
git commit -m "Instructions to use packagist.org in README"
git tag -a v0.1.11 -m "version 0.1.11"
git push -u origin master
git push origin v0.1.11
170
Exercise 4
47.create a gh-pages branch
git checkout -b gh-pages
git push -u origin gh-pages
git checkout master
48.Go to github settings for your repository
49.Choose a theme in GitHub Pages section
50.Your project page is ready now: https://
conquerorsoft.github.io/my_first_project/
171
172
Exercise 4
51.commit to git
git add .
git commit -m "Documentation instructions for the project"
git tag -a v1.0.0 -m "version 1.0.0"
git push -u origin master
git push origin v1.0.0
173
Project Code
174
Questions?
175
Thank you
176
https://joind.in/talk/de19a
References, credits and resources
1. SemVer.org
2. keepachangelog.com
3. phppackagechecklist.com
4. composer.org
5. thephpleague.com
6. poser.pugx.org
7. readthedocs.org
8. www.phpdoc.org
9. phpunit.de
10.packagist.org
11.packagist.com
12.www.php-fig.org/psr/psr-2
13.github.com/squizlabs/PHP_CodeSniffer
14.pages.github.com
15.travis-ci.org
16.choosealicense.com
17.spdx.org/licenses
18.codeclimate.com
19.getcomposer.org/doc/articles/handling-
private-packages-with-satis.md
20.https://www.contributor-covenant.org/
21.http://www.mkdocs.org/
177

Más contenido relacionado

La actualidad más candente

What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0Luca Milanesio
 
Source Code Management systems
Source Code Management systemsSource Code Management systems
Source Code Management systemsxSawyer
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015Hossein Zahed
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with GitLuigi De Russis
 
Yale Jenkins Show and Tell
Yale Jenkins Show and TellYale Jenkins Show and Tell
Yale Jenkins Show and TellE. Camden Fisher
 
Understanding GIT and Version Control
Understanding GIT and Version ControlUnderstanding GIT and Version Control
Understanding GIT and Version ControlSourabh Sahu
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)Andrew Bayer
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHubDSCVSSUT
 
Editor config, eslint, prettier
Editor config, eslint, prettierEditor config, eslint, prettier
Editor config, eslint, prettierSamundra khatri
 
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...Simplilearn
 
Formation autour de git et git lab
Formation autour de git et git labFormation autour de git et git lab
Formation autour de git et git labAbdelghani Azri
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & ActuatorsVMware Tanzu
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersKostas Saidis
 

La actualidad más candente (20)

What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0What's new in Gerrit Code Review 3.0
What's new in Gerrit Code Review 3.0
 
Source Code Management systems
Source Code Management systemsSource Code Management systems
Source Code Management systems
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
 
Git collaboration
Git collaborationGit collaboration
Git collaboration
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with Git
 
Github
GithubGithub
Github
 
git and github
git and githubgit and github
git and github
 
Yale Jenkins Show and Tell
Yale Jenkins Show and TellYale Jenkins Show and Tell
Yale Jenkins Show and Tell
 
Understanding GIT and Version Control
Understanding GIT and Version ControlUnderstanding GIT and Version Control
Understanding GIT and Version Control
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHub
 
Editor config, eslint, prettier
Editor config, eslint, prettierEditor config, eslint, prettier
Editor config, eslint, prettier
 
Git
GitGit
Git
 
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Formation autour de git et git lab
Formation autour de git et git labFormation autour de git et git lab
Formation autour de git et git lab
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java Developers
 

Destacado

Inheritance: Vertical or Horizontal
Inheritance: Vertical or HorizontalInheritance: Vertical or Horizontal
Inheritance: Vertical or HorizontalMark Niebergall
 
Web Performance 2017: Myths and Truths (php[world] 2017)
Web Performance 2017: Myths and Truths (php[world] 2017)Web Performance 2017: Myths and Truths (php[world] 2017)
Web Performance 2017: Myths and Truths (php[world] 2017)Christian Wenz
 
Developing applications for performance
Developing applications for performanceDeveloping applications for performance
Developing applications for performanceLeon Fayer
 
Leveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantageLeveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantageMichelangelo van Dam
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoRyan Weaver
 
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017Carlos Buenosvinos
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsDave Stokes
 
MySQL 8.0 Preview: What Is Coming?
MySQL 8.0 Preview: What Is Coming?MySQL 8.0 Preview: What Is Coming?
MySQL 8.0 Preview: What Is Coming?Gabriela Ferrara
 

Destacado (8)

Inheritance: Vertical or Horizontal
Inheritance: Vertical or HorizontalInheritance: Vertical or Horizontal
Inheritance: Vertical or Horizontal
 
Web Performance 2017: Myths and Truths (php[world] 2017)
Web Performance 2017: Myths and Truths (php[world] 2017)Web Performance 2017: Myths and Truths (php[world] 2017)
Web Performance 2017: Myths and Truths (php[world] 2017)
 
Developing applications for performance
Developing applications for performanceDeveloping applications for performance
Developing applications for performance
 
Leveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantageLeveraging a distributed architecture to your advantage
Leveraging a distributed architecture to your advantage
 
Webpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San FranciscoWebpack Encore Symfony Live 2017 San Francisco
Webpack Encore Symfony Live 2017 San Francisco
 
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
MySQL 8.0 Preview: What Is Coming?
MySQL 8.0 Preview: What Is Coming?MySQL 8.0 Preview: What Is Coming?
MySQL 8.0 Preview: What Is Coming?
 

Similar a Create a PHP Library the right way

PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with ComposerAdam Englander
 
02-version control(DevOps Series)
02-version control(DevOps Series)02-version control(DevOps Series)
02-version control(DevOps Series)Mohammed Shaban
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Clark Everetts
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with ComposerJason Grimes
 
Digital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: InformationDigital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: InformationMassimo Menichinelli
 
Hackaton for health 2015 - Sharing the Code we Make
Hackaton for health 2015 - Sharing the Code we MakeHackaton for health 2015 - Sharing the Code we Make
Hackaton for health 2015 - Sharing the Code we Makeesben1962
 
Beginning with Composer - Dependency manager in php
Beginning with Composer  - Dependency manager in php Beginning with Composer  - Dependency manager in php
Beginning with Composer - Dependency manager in php Yogesh Salvi
 
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...sparkfabrik
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning TalkEric Johnson
 
Digital Fabrication Studio 0.3 Information
Digital Fabrication Studio 0.3 InformationDigital Fabrication Studio 0.3 Information
Digital Fabrication Studio 0.3 InformationMassimo Menichinelli
 
Version Uncontrolled - How to Manage Your Version Control (whitepaper)
Version Uncontrolled - How to Manage Your Version Control (whitepaper)Version Uncontrolled - How to Manage Your Version Control (whitepaper)
Version Uncontrolled - How to Manage Your Version Control (whitepaper)Revelation Technologies
 
Python Automation With Gauge + Selenium + API + Jenkins
Python Automation With Gauge + Selenium + API + JenkinsPython Automation With Gauge + Selenium + API + Jenkins
Python Automation With Gauge + Selenium + API + JenkinsFagun Priyadarshi
 
Digital Fabrication Studio.02 _Information @ Aalto Media Factory
Digital Fabrication Studio.02 _Information @ Aalto Media FactoryDigital Fabrication Studio.02 _Information @ Aalto Media Factory
Digital Fabrication Studio.02 _Information @ Aalto Media FactoryMassimo Menichinelli
 
Hacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginnersHacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginnersDeepikaRana30
 

Similar a Create a PHP Library the right way (20)

PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
02-version control(DevOps Series)
02-version control(DevOps Series)02-version control(DevOps Series)
02-version control(DevOps Series)
 
BitBucket presentation
BitBucket presentationBitBucket presentation
BitBucket presentation
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with Composer
 
Digital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: InformationDigital Fabrication Studio v.0.2: Information
Digital Fabrication Studio v.0.2: Information
 
Subversion
SubversionSubversion
Subversion
 
Hackaton for health 2015 - Sharing the Code we Make
Hackaton for health 2015 - Sharing the Code we MakeHackaton for health 2015 - Sharing the Code we Make
Hackaton for health 2015 - Sharing the Code we Make
 
Beginning with Composer - Dependency manager in php
Beginning with Composer  - Dependency manager in php Beginning with Composer  - Dependency manager in php
Beginning with Composer - Dependency manager in php
 
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning Talk
 
Digital Fabrication Studio 0.3 Information
Digital Fabrication Studio 0.3 InformationDigital Fabrication Studio 0.3 Information
Digital Fabrication Studio 0.3 Information
 
Version Uncontrolled - How to Manage Your Version Control (whitepaper)
Version Uncontrolled - How to Manage Your Version Control (whitepaper)Version Uncontrolled - How to Manage Your Version Control (whitepaper)
Version Uncontrolled - How to Manage Your Version Control (whitepaper)
 
Python Automation With Gauge + Selenium + API + Jenkins
Python Automation With Gauge + Selenium + API + JenkinsPython Automation With Gauge + Selenium + API + Jenkins
Python Automation With Gauge + Selenium + API + Jenkins
 
Svn tutorial
Svn tutorialSvn tutorial
Svn tutorial
 
Svn tutorial
Svn tutorialSvn tutorial
Svn tutorial
 
CASCON 2017 - OpenAPI v3
CASCON 2017 - OpenAPI v3CASCON 2017 - OpenAPI v3
CASCON 2017 - OpenAPI v3
 
Digital Fabrication Studio.02 _Information @ Aalto Media Factory
Digital Fabrication Studio.02 _Information @ Aalto Media FactoryDigital Fabrication Studio.02 _Information @ Aalto Media Factory
Digital Fabrication Studio.02 _Information @ Aalto Media Factory
 
Hacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginnersHacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginners
 

Último

Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 

Último (20)

Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 

Create a PHP Library the right way

  • 1. Create a PHP Library the Right way By Christian Varela @gabriel0702 cvarela@conquerorsoft.com https://joind.in/talk/de19a 1
  • 4. Christian Varela ➤ I have a wife and 3 daughters ➤ I am from Mexico ➤ Master Degree in Computer Science ➤ 13 years programming with PHP ➤ I live in Miami ➤ I created Conqueror Soft Inc ➤ I play guitar and piano 4
  • 5. 5
  • 6. Conqueror Soft will take your business to the next Level! 6 www.conquerorsoft.com info@conquerorsoft.com facebook.com/conquerorsoft
  • 7. What is this session about? Have you found yourself wondering how to take advantage of what you have developed in the past for current or future projects? Are you tired of copying/pasting then adapting from your previous projects to the new ones? Start developing for the future and contribute to others by developing libraries and sharing them for use. Where do you start? You’ll be guided through this tutorial step by step to include security, tests and all the factors you need to consider when building a library. 7
  • 8. Library / Package A Software Library is a collection of methods, functions, classes, etc, that provides a particular functionality to be used or reused partially or in whole as part of a more complex system. It is independent enough to be integrated as a functional block or module along with other libraries to achieve a common goal. It can be used by multiple systems that have no connections or relations between them. 8
  • 9. 9
  • 10. Why should I create libraries? 1. They provide reusability 2. They can help open source 3. They are modular in functionality context 4. They are easier to maintain 10
  • 11. Web application A web application is an application running in the web and that provides a solution to a particular problem. The application can have modules, programs, configuration files, etc, all connected and related in a way that each piece provides a specific purpose and that all together accomplish a common goal. 11
  • 12. Web application 1. Served by a server 2. Requested by a user (through a browser) 3. Can interact with DBs 4. Use third party libraries 5. Use private libraries 6. Has configuration files 12
  • 13. Web application 13 Web Application Web Server Application Server DB Server Internal dependencies External dependencies Configuration files
  • 14. 14
  • 15. 15
  • 16. How the web application knows about its dependencies? 16
  • 17. 17 Web Application Web Server Application Server DB Server Internal dependencies External dependencies Configuration files Dependencies!?!? composer.json
  • 19. Composer 1. Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. 2. Enables you to declare the libraries you depend on. 3. Finds out which versions of which packages can and need to be installed, and installs them 19
  • 20. composer.json 1. This is all you need to specify dependencies 2. This file is used when creating libraries and / or projects 3. "require" key specifies which packages your project needs 4. "repositories" key specifies where to find those packages 20
  • 21. composer.json keys (most popular) 1. name 2. description 3. type 4. keywords 5. homepage 6. authors 7. support 8. require 9. require-dev 10.suggest 11.autoload 12.autoload-dev 13.repositories 14.scripts 21
  • 22. Where composer get the packages from? 22
  • 25. packagist.org Packagist is the main Composer repository. A Composer repository is basically a package source: a place where you can get packages from. Packagist aims to be the central repository that everybody uses. This means that you can automatically require any package that is available there, without further specifying where Composer should look for the package. 25
  • 27. packagist.com Private Packagist is a commercial package hosting product offering professional support and web based management of private and public packages, and granular access permissions. Private Packagist provides mirroring for packages' zip files which makes installs faster and independent from third party systems - e.g. you can deploy even if GitHub is down because your zip files are mirrored. 27
  • 29. Custom repositories The following repository types are supported: 1. composer: A Composer repository is simply a packages.json file served via the network (HTTP, FTP, SSH), that contains a list of composer.json objects with additional dist and/or sourceinformation. The packages.json file is loaded using a PHP stream. You can set extra options on that stream using the options parameter. 2. vcs: The version control system repository can fetch packages from git, svn, fossil and hg repositories. 3. pear: With this you can import any pear repository into your Composer project. 4. package: If you depend on a project that does not have any support for composer whatsoever you can define the package inline using a package repository. You basically just inline the composer.json object. 29
  • 30. Platform packages 1. Required system packages 2. Not installed by composer 3. Examples: 1. php 2. php extensions (ext-gd) 3. php libraries (lib-curl) 30
  • 31. Autoloading 1. Uses "autoload" key and PRS-4 2. vendor/autoload.php is generated by Composer 3. autoload.php is regenerated with composer dump-autoload 31
  • 32. PSR-4 1. PHP Standard Recommendation 4 2. describes a specification for autoloading classes from file paths. It is fully interoperable, and can be used in addition to any other autoloading specification, including PSR-0. This PSR also describes where to place files that will be autoloaded according to the specification. 32
  • 34. Versioning (when developing) 1. They can be handled manually in composer.json 2. They can be handled using a Version Control System (VCS, this is recommended) 1. By using branches 2. By using tags (this is recommended) 3. Use a consistent versioning standard, like SemVer.org (this is recommended) 34
  • 35. Versioning (when installing dependencies) 1. Use constraints 1. Exact version (1.2.3) 2. Version range (>=2.0 <3.0) 3. with hyphen (1.1.0 - 1.2.0, equals to >=1.1.0 <= 1.2.0) 4. with wildcard (1.1.*, equals to >=1.1 <1.2) 5. with tilde (~1.3.1, equals to >=1.3.1 <1.4.0) 6. with caret (^0.3, equals to >=0.3 <0.4.0) 35
  • 36. SemVer Given a version number MAJOR.MINOR.PATCH, increment the: 1. MAJOR version when you make incompatible API changes, 2. MINOR version when you add functionality in a backwards- compatible manner, and 3. PATCH version when you make backwards-compatible bug fixes. Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. http://semver.org/ 36
  • 37. License for your library 37
  • 38. License for your library 38https://choosealicense.com/
  • 39. Minimum-stability options 1. dev 2. alpha 3. beta 4. RC 5. stable 39
  • 41. PSR-2 1. This guide extends and expands on PSR-1, the basic coding standard. 2. The intent of this guide is to reduce cognitive friction when scanning code from different authors. It does so by enumerating a shared set of rules and expectations about how to format PHP code. 3. it helps to have one set of guidelines to be used among all those projects. 4. There are tools to help to comply with this (php code sniffer is recommended) 41http://www.php-fig.org/psr/psr-2/
  • 42. PHP Code Sniffer PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent. 42
  • 44. Changelog 1. it is a file which contains a curated, chronologically ordered list of notable changes for each version of a project. 2. it makes it easier for users and contributors to see precisely what notable changes have been made between each release (or version) of the project. 44
  • 45. Changelog rules 1. There should be an entry for every single version. 2. Same types of changes should be grouped 3. Versions and sections should be linkable 4. The latest version comes first 5. The release date of each versions is displayed 6. SemVer as versioning (recommended) 45
  • 46. Changelog changes 1. Added for new features. 2. Changed for changes in existing functionality. 3. Deprecated for soon-to-be removed features. 4. Removed for now removed features. 5. Fixed for any bug fixes. 6. Security in case of vulnerabilities. 46
  • 48. Travis CI prerequisites 1. GitHub login 2. Project hosted as a repository on GitHub 3. Working code in your project 4. Working build or test script 5. Travis CI .org for public repositories 6. Travis CI .com for private repositories 48
  • 49. Travis CI 1. Sign in to Travis using GitHub account 2. Activate GitHub repositories 3. Add a .travis.yml file 4. Add the .travis.yml file to git, commit and push, to trigger a Travis CI build 5. Check the build status page to see if your build passes or fails 6. Github will have the service in the web hooks settings. 49
  • 50. Scrutinizer CI 1. Sign in to Scrutinizer using GitHub account 2. Activate GitHub repositories 3. Add a .scrutinizer.yml file 4. Add the .scrutinizer.yml file to git, commit and push, to trigger a Scrutinizer CI build 5. Check the build status page to see code quality and coverage 6. Github will have the service in the web hooks settings. 50
  • 51. Composer install 51 Composer install composer.json? Yes composer.lock? Yes files match? Yes Install libraries from composer.lock Error No Install libraries from composer.json No Error No Generate composer.lock
  • 52. Composer update 52 Composer install composer.json? Yes composer.lock? Yes files match? Yes Install most recent versions Error No Install libraries from composer.json No Error No Generate composer.lock Generate composer.lock
  • 53. Exercise 1. Creating a library composer.json file manually 53
  • 54. Exercise 1 1. cd ~ && mkdir -p phplibrary/exercise1 2. cd phplibrary/exercise1 3. Create composer.json 4. composer validate 5. composer install 54
  • 55. Exercise 1 values for composer.json 1. name: php_library_right_way/exercise1 2. description: "Creating a composer.json file manually" 3. require: php ^5.6 || ^7.0 4. require-dev: phpunit/phpunit ^5.7 5. type: library 6. License: MIT 55
  • 56. Exercise 1 solution 1 { 2 "name": "php_library_right_way/exercise1", 3 "description": "Creating a composer.json file manually", 4 "require": { 5 "php": "^5.6 || ^7.0" 6 }, 7 "require-dev": { 8 "phpunit/phpunit": "^5.7" 9 }, 10 "type": "library", 11 "license": "MIT" 12 } 56
  • 57. Exercise 2. Creating a library composer.json file using composer init 57
  • 58. Exercise 2 1. cd ~ && mkdir -p phplibrary/exercise2 2. cd phplibrary/exercise2 3. composer init 4. composer validate 5. composer install 58
  • 59. Exercise 2 values for composer.json 1. name: php_library_right_way/exercise2 2. description: "Created with composer init" 3. Author: your name and email 4. require: php ^5.6 || ^7.0 5. require-dev: phpunit/phpunit ^5.7 6. type: library 7. License: MIT 8. Others: leave default 59
  • 60. Exercise 2 solution 1 { 2 "name": "php_library_right_way/exercise2", 3 "description": "Created with composer init", 4 "type": "library", 5 "require": { 6 "php": "^5.6 || ^7.0" 7 }, 8 "require-dev": { 9 "phpunit/phpunit": "^5.7" 10 }, 11 "license": "MIT", 12 "authors": [ 13 { 14 "name": "Christian Varela", 15 "email": "cvarela@conquerorsoft.com" 16 } 17 ] 18 } 60
  • 61. Exercise 3. Creating my first library 61
  • 63. Exercise 3 1. cd ~ && mkdir -p phplibrary/my_first_library 2. Create a README.md file 63
  • 64. README.md 1 # My First Library # 2 3 This is my very first library I created at php[world]. 64
  • 65. Exercise 3 3. git init 4. git add . git commit -m "First commit" 5. git tag -a v0.1.0 -m "version 0.1.0" 6. Create a repository in GitHub 7. Connect your repository with GitHub 65
  • 66. 66
  • 67. 67
  • 68. Exercise 3 8. composer init 9. provide the following values 68
  • 69. Exercise 3 values for composer init 1. name: php_library_right_way/my_first_library 2. description: "Created with composer init” 3. Author: your name and email 4. require: php ^5.6 || ^7.0 5. require-dev: phpunit/phpunit ^5.7 6. type: library 7. License: MIT 8. Others: leave default 69
  • 70. Exercise 3 composer.json 1 { 2 "name": "php_library_right_way/my_first_library", 3 "description": "Created with composer init", 4 "type": "library", 5 "require": { 6 "php": "^5.6 || ^7.0" 7 }, 8 "require-dev": { 9 "phpunit/phpunit": "^5.7" 10 }, 11 "license": "MIT", 12 "authors": [ 13 { 14 "name": "Christian Varela", 15 "email": "cvarela@conquerorsoft.com" 16 } 17 ] 18 } 70
  • 71. Exercise 3 10. commit to git git add . git commit -m "Composer init" git tag -a v0.1.1 -m "version 0.1.1" git push -u origin master git push origin v0.1.1 11.composer install 12.echo "composer.lock" >> .gitignore 71
  • 72. Exercise 3 (click link) 13.Create a CHANGELOG.md file 72
  • 73. 1 # Changelog # 2 3 All notable changes to this library will be documented in this file. 4 5 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 8 ## [Unreleased] ## 9 10 ## [0.1.2] - 2017-11-04 ## 11 ### Added ### 12 - CHANGELOG.md file created 13 14 ### Changed ### 15 - .gitignore file ignores composer.lock 16 - README.md add steps and fixes 17 18 ## [0.1.1] - 2017-11-04 ## 19 ### Added ### 20 - composer init ran 21 - composer.json file created 22 - .gitignore file created to ignore vendor directory 23 24 ### Changed ### 25 - README.md file has more steps 26 27 ## [0.1.0] - 2017-11-04 ## 28 ### Added ### 29 - README.md file created 73
  • 74. Exercise 3 14. commit to git git add . git commit -m "Changelog file added" git tag -a v0.1.2 -m "version 0.1.2" git push -u origin master git push origin v0.1.2 15.mkdir src && mkdir tests 16.add the next to the composer.json file (click link) 74
  • 75. 1 { 2 ... 3 "keywords": [ 4 "conquerorsoft", 5 "my_first_library", 6 "tutorial", 7 "phpworld 2017", 8 "workshop" 9 ], 10 "homepage": "http://www.conquerorsoft.com/my_first_library", 11 "require-dev": { 12 "phpunit/phpunit": “^5.7”, 13 "squizlabs/php_codesniffer": "3.*" 14 }, 15 "require": { 16 "php": "~5.6 || ~7.0" 17 }, 18 "autoload": { 19 "psr-4": { 20 "conquerorsoftmy_first_library": "src" 21 } 22 }, 23 "autoload-dev": { 24 "psr-4": { 25 "conquerorsoftmy_first_library": "tests" 26 } 27 }, 28 "scripts": { 29 "test": "phpunit", 30 "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests", 31 "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests" 32 }, 33 ... 34 } 75
  • 76. Exercise 3 17.create phpunit.xml (click link) 1 <?xml version="1.0" encoding="UTF-8"?> 2 <phpunit bootstrap="vendor/autoload.php" 3 colors="true" 4 verbose="true" 5 convertErrorsToExceptions="true" 6 convertNoticesToExceptions="true" 7 convertWarningsToExceptions="true"> 8 <testsuites> 9 <testsuite name="conquerorsoft my_first_library Test Suite"> 10 <directory>tests</directory> 11 </testsuite> 12 </testsuites> 13 <filter> 14 <whitelist> 15 <directory suffix=".php">src/</directory> 16 </whitelist> 17 </filter> 18 <logging> 19 <log type="tap" target="build/report.tap"/> 20 <log type="junit" target="build/report.junit.xml"/> 21 <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/> 22 <log type="coverage-text" target="build/coverage.txt"/> 23 <log type="coverage-clover" target="build/logs/clover.xml"/> 24 </logging> 25 </phpunit> 76
  • 77. Exercise 3 18.echo build >> .gitignore 19.composer update 20.commit to git git add . git commit -m "Preparation for development" git tag -a v0.1.3 -m "version 0.1.3" git push -u origin master git push origin v0.1.3 77
  • 78. Exercise 3 21.Add a LICENSE.md file (for this example we chose MIT, click link) 22.vim tests/FirstClassTest.php 23.vim src/FirstClass.php 24.commit to git git add . git commit -m "Encode and decode string functionality" git tag -a v0.1.4 -m "version 0.1.4" git push -u origin master git push origin v0.1.4 78
  • 79. Exercise 3 25.add docblock to everything /** * This is a summary example * * This is a description * * @example this is tag */ 79
  • 80. Exercise 3 26.commit to git git add . git commit -m "Docblocks added everywhere" git tag -a v0.1.5 -m "version 0.1.5" git push -u origin master git push origin v0.1.5 27.add repository to Travis and create travis configuration file 80
  • 81. .travis.yml (click link) 1 dist: trusty 2 language: php 3 4 php: 5 - 5.6 6 - 7.0 7 - 7.1 8 - hhvm 9 10 # This triggers builds to run on the new TravisCI infrastructure. 11 # See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ 12 sudo: false 13 14 ## Cache composer 15 cache: 16 directories: 17 - $HOME/.composer/cache 18 19 matrix: 20 include: 21 - php: 5.6 22 env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"' 23 24 before_script: 25 - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist 26 27 script: 28 - vendor/bin/phpcs --standard=psr2 src/ 29 - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover 30 31 after_script: 32 - | 33 if [[ "$TRAVIS_PHP_VERSION" != 'hhvm' && "$TRAVIS_PHP_VERSION" != '7.0' ]]; then 34 wget https://scrutinizer-ci.com/ocular.phar 35 php ocular.phar code-coverage:upload --format=php-clover coverage.clover 36 fi 81
  • 82. 82
  • 83. 83
  • 84. 84
  • 85. 85
  • 86. 86
  • 87. 87
  • 88. 88
  • 89. 89
  • 90. Exercise 3 28.commit to git git add . git commit -m "Travis CI integration" git tag -a v0.1.6 -m "version 0.1.6" git push -u origin master git push origin v0.1.6 29. make sure version for phpunit is ^5.7 in composer.json to support php 5.6 90
  • 91. Exercise 3 30.commit to git git add . git commit -m "Phpunit version changed to support php version 5.6" git tag -a v0.1.7 -m "version 0.1.7" git push -u origin master git push origin v0.1.7 91
  • 92. Exercise 3 31.get travis badge to put in README.md 92
  • 93. Exercise 3 32. Put license badge in README [![Software License][ico-license]](LICENSE.md) [ico-license]: https://img.shields.io/badge/license-MIT- brightgreen.svg?style=flat 93
  • 94. 94
  • 95. Exercise 3 33.commit to git git add . git commit -m "Travis CI and License badges in README" git tag -a v0.1.8 -m "version 0.1.8" git push -u origin master git push origin v0.1.8 34.Create scrutinizer-ci account and link with GitHub 35.Create .scrutinizer.yml file 95
  • 96. .scrutinizer.yml (click link) 1 filter: 2 excluded_paths: [tests/*] 3 4 checks: 5 php: 6 remove_extra_empty_lines: true 7 remove_php_closing_tag: true 8 remove_trailing_whitespace: true 9 fix_use_statements: 10 remove_unused: true 11 preserve_multiple: false 12 preserve_blanklines: true 13 order_alphabetically: true 14 fix_php_opening_tag: true 15 fix_linefeed: true 16 fix_line_ending: true 17 fix_identation_4spaces: true 18 fix_doc_comments: true 19 20 tools: 21 external_code_coverage: 22 timeout: 600 23 runs: 3 96
  • 97. 97
  • 98. 98
  • 99. 99
  • 100. 100
  • 101. 101
  • 102. 102
  • 103. 103
  • 104. 104
  • 105. 105
  • 106. 106
  • 107. Exercise 3 36.Get scrutinizer badges in README file 107
  • 108. Exercise 3 37.commit to git git add . git commit -m "Scrutinizer CI and badges in README" git tag -a v0.1.9 -m "version 0.1.9" git push -u origin master git push origin v0.1.9 38.Make sure there are no type hinting for PHP 7.0 only 108
  • 109. 109
  • 110. Exercise 3 39.commit to git git add . git commit -m "Fixes to uncompatible type hinting" git tag -a v0.1.10 -m "version 0.1.10" git push -u origin master git push origin v0.1.10 40.Apply any patch proposed from scrutinizer 110
  • 111. Exercise 3 41.commit to git git add . git commit -m "Spacing patch from scrutinizer applied" git tag -a v0.1.11 -m "version 0.1.11" git push -u origin master git push origin v0.1.11 111
  • 112. Exercise 3 42.Create contributing files 1. CONTRIBUTING.md (click link) 2. CODE_OF_CONDUCT.md (click link) 112
  • 113. Exercise 3 43.Add more sections to README file 1. Install 2. Usage 3. Change log 4. Testing 5. Contributing 6. Security 7. Credits 8. License 113
  • 114. Exercise 3 44.commit to git git add . git commit -m "Improvements to README" git tag -a v0.1.12 -m "version 0.1.12" git push -u origin master git push origin v0.1.12 45.Add .gitattributes file to ignore some files or folders when -- prefer-dist is used 114
  • 115. Exercise 3 46.commit to git git add . git commit -m ".gitattributes file created" git tag -a v0.1.13 -m "version 0.1.13" git push -u origin master git push origin v0.1.13 115
  • 116. Exercise 3 47.create an account in packagist.org and submit your library using your github repository 48.Make your package in packagist to be autoupdated on push 49.Add last version in packagist badge to README.md file [![Latest Version on Packagist][ico-version]][link-packagist] [ico-version]: https://img.shields.io/packagist/v/conquerorsoft/ my_first_library.svg?style=flat [link-packagist]: https://packagist.org/packages/conquerorsoft/my_first_library 116
  • 117. 117
  • 118. 118
  • 119. 119
  • 120. 120
  • 121. 121
  • 122. 122
  • 123. 123
  • 124. 124
  • 125. Exercise 3 50.commit to git git add . git commit -m "Instructions to use packagist.org in README" git tag -a v0.1.14 -m "version 0.1.14" git push -u origin master git push origin v0.1.14 125
  • 126. Exercise 3 51.create gh-pages branch git checkout -b gh-pages git push -u origin gh-pages git checkout master 52.Go to github settings for your repository 53.Choose a theme in GitHub Pages section 54.Your library page is ready: https://conquerorsoft.github.io/ my_first_library/ 126
  • 127. 127
  • 128. 128
  • 129. 129
  • 130. Exercise 3 54.Your library page is ready: https://conquerorsoft.github.io/ my_first_library/ 55.commit to git git add . git commit -m "Documentation instructions for the library" git tag -a v1.0.0 -m "version 1.0.0" git push -u origin master git push origin v1.0.0 130
  • 131. 131
  • 132. Exercise 4. Creating my first project using my first library 132
  • 133. Exercise 4 1. cd ~ && mkdir -p phplibrary/my_first_project && cd phplibrary/my_first_project 2. create a README.md file 133
  • 134. README.md 1 # My First Project # 2 3 This is my very first project I created at php[world]. 134
  • 135. Exercise 4 3. git init 4. commit to git git add . git commit -m "First commit of my project" 5. Assign a version to your project git tag -a v0.1.0 -m "version 0.1.0" 6. Create a repository in GitHub 135
  • 136. Exercise 4 7. connect your repository git remote add origin https://github.com/ConquerorSoft/ my_first_project.git git push -u origin master git push origin v0.1.0 8. composer init 9. Provide the next values 136
  • 137. Exercise 4 values for composer.json 1. name: php_library_right_way/my_first_project 2. description: "Project created with composer init" 3. require: php ^5.6 || ^7.0 4. require-dev: 1. phpunit/phpunit latest ^5.7 2. squizlabs/php_codesniffer 3.* 5. type: project 6. License: MIT 7. Author: your name and email 8. Others: leave default 137
  • 138. Exercise 4 composer.json 1 { 2 "name": "conquerorsoft/my_first_project", 3 "description": "Project created with composer init", 4 "type": "project", 5 "require": { 6 "php": "^5.6 || ^7.0" 7 }, 8 "require-dev": { 9 "phpunit/phpunit": "^5.7", 10 "squizlabs/php_codesniffer": "3.*" 11 }, 12 "license": "MIT", 13 "authors": [ 14 { 15 "name": "Christian Varela", 16 "email": "cvarela@conquerorsoft.com" 17 } 18 ] 19 } 138
  • 139. Exercise 4 10.edit composer to include your library 139
  • 140. Exercise 4 composer.json 1 { 2 "name": "conquerorsoft/my_first_project", 3 "description": "Project created with composer init", 4 "type": "project", 5 "repositories": [ 6 { 7 "type": "vcs", 8 "url": "/Users/gabriel/phplibrary/my_first_library" 9 } 10 ], 11 "require": { 12 "php": "^5.6 || ^7.0", 13 "conquerorsoft/my_first_library": "^0.1" 14 }, 15 "require-dev": { 16 "phpunit/phpunit": "^5.7", 17 "squizlabs/php_codesniffer": "3.*" 18 }, 19 "license": "MIT", 20 "authors": [ 21 { 22 "name": "Christian Varela", 23 "email": "cvarela@conquerorsoft.com" 24 } 25 ] 26 } 140
  • 141. Exercise 4 11.commit to git git add . git commit -m "Composer init" git tag -a v0.1.1 -m "version 0.1.1" git push -u origin master git push origin v0.1.1 12.composer install 13.create a CHANGELOG.md file (click link) 141
  • 142. 1 # Changelog # 2 3 All notable changes to this library will be documented in this file. 4 5 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 8 ## [Unreleased] ## 9 10 ## [0.1.2] - 2017-11-09 ## 11 ### Added ### 12 - CHANGELOG.md file created 13 14 ### Changed ### 15 - README.md add steps and fixes 16 17 18 ## [0.1.1] - 2017-11-09 ## 19 ### Added ### 20 - composer init ran 21 - composer.json file created 22 - .gitignore file created to ignore vendor directory 23 - composer.lock file created 24 25 ### Changed ### 26 - README.md file has more steps and fixes 27 28 ## [0.1.0] - 2017-11-09 ## 29 ### Added ### 30 - README.md file created 142
  • 143. Exercise 4 14.commit to git git add . git commit -m "Changelog file added" git tag -a v0.1.2 -m "version 0.1.2" git push -u origin master git push origin v0.1.2 15.mkdir src && mkdir tests 16.add more information to composer.json 143
  • 144. 1 { 2 ... 3 "keywords": [ 4 "conquerorsoft", 5 "my_first_project", 6 "tutorial", 7 "phpworld 2017", 8 "workshop" 9 ], 10 "homepage": "http://www.conquerorsoft.com/my_first_project", 11 "minimum-stability": "stable", 12 "scripts": { 13 "test": "phpunit", 14 "check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests", 15 "fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests" 16 } 17 ... 18 } 144
  • 145. Exercise 4 17.create phpunit.xml (click link) 1 <?xml version="1.0" encoding="UTF-8"?> 2 <phpunit bootstrap="vendor/autoload.php" 3 colors="true" 4 verbose="true" 5 convertErrorsToExceptions="true" 6 convertNoticesToExceptions="true" 7 convertWarningsToExceptions="true"> 8 <testsuites> 9 <testsuite name="conquerorsoft my_first_project Test Suite"> 10 <directory>./tests</directory> 11 </testsuite> 12 </testsuites> 13 <filter> 14 <whitelist> 15 <directory suffix=".php">src/</directory> 16 </whitelist> 17 </filter> 18 <logging> 19 <log type="tap" target="build/report.tap"/> 20 <log type="junit" target="build/report.junit.xml"/> 21 <log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/> 22 <log type="coverage-text" target="build/coverage.txt"/> 23 <log type="coverage-clover" target="build/logs/clover.xml"/> 24 </logging> 25 </phpunit> 145
  • 146. Exercise 4 18.echo build >> .gitignore 19.composer update 20.commit to git echo "build/" >> .gitignore git add . git commit -m "Preparation for development" git tag -a v0.1.3 -m "version 0.1.3" git push -u origin master git push origin v0.1.3 146
  • 147. Exercise 4 21.Add a LICENSE.md file (for this example we chose MIT click link) 22.Create tests/FirstProjectClassTest.php 23.Create src/FirstProjectClass.php 24.Add the next sections to composer.json 147
  • 148. 1 { 2 ... 3 "autoload": { 4 "psr-4": { 5 "conquerorsoftmy_first_project": "src" 6 } 7 }, 8 "autoload-dev": { 9 "psr-4": { 10 "conquerorsoftmy_first_project": "test" 11 } 12 }, 13 ... 14 } 148
  • 149. Exercise 4 25.composer dump-autoload 26.commit to git git add . git commit -m "Classes from project calling my library" git tag -a v0.1.4 -m "version 0.1.4" git push -u origin master git push origin v0.1.4 27.add repository to Travis and create travis configuration file 149
  • 150. .travis.yml (click link) 1 dist: trusty 2 language: php 3 4 php: 5 - 5.6 6 - 7.0 7 - 7.1 8 - hhvm 9 10 # This triggers builds to run on the new TravisCI infrastructure. 11 # See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ 12 sudo: false 13 14 ## Cache composer 15 cache: 16 directories: 17 - $HOME/.composer/cache 18 19 matrix: 20 include: 21 - php: 5.6 22 env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"' 23 24 before_script: 25 - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist 26 27 script: 28 - vendor/bin/phpcs --standard=psr2 src/ 29 - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover 30 31 after_script: 32 - | 33 if [[ "$TRAVIS_PHP_VERSION" != 'hhvm' && "$TRAVIS_PHP_VERSION" != '7.0' ]]; then 34 wget https://scrutinizer-ci.com/ocular.phar 35 php ocular.phar code-coverage:upload --format=php-clover coverage.clover 36 fi 150
  • 151. 151
  • 152. 152
  • 153. 153
  • 154. Exercise 4 28.commit to git git add . git commit -m "Travis CI integration" git tag -a v0.1.5 -m "version 0.1.5" git push -u origin master git push origin v0.1.5 29.Change composer.json to use github repository instead of file system local folder 154
  • 155. 1 { 2 ... 3 "repositories": [ 4 { 5 "type": "vcs", 6 "url": "https://github.com/ConquerorSoft/ my_first_library" 7 } 8 ], 9 ... 10 } 155
  • 156. Exercise 4 30.composer update 31.commit to git git add . git commit -m "VCS reference changed for my_first_library in composer.json" git tag -a v0.1.6 -m "version 0.1.6" git push -u origin master git push origin v0.1.6 32.Remove references for repositories in composer.json 156
  • 157. Exercise 4 33.Run composer update composer clearcache composer update 34.commit to git git add . git commit -m "my_first_library is now taken from packagist" git tag -a v0.1.7 -m "version 0.1.7" git push -u origin master git push origin v0.1.7 157
  • 158. Exercise 4 35.Link scrutinizer-ci account with github and create .scrutinizer.yml file 158
  • 159. .scrutinizer.yml (click link) 1 filter: 2 excluded_paths: [tests/*] 3 4 checks: 5 php: 6 remove_extra_empty_lines: true 7 remove_php_closing_tag: true 8 remove_trailing_whitespace: true 9 fix_use_statements: 10 remove_unused: true 11 preserve_multiple: false 12 preserve_blanklines: true 13 order_alphabetically: true 14 fix_php_opening_tag: true 15 fix_linefeed: true 16 fix_line_ending: true 17 fix_identation_4spaces: true 18 fix_doc_comments: true 19 20 tools: 21 external_code_coverage: 22 timeout: 600 23 runs: 3 159
  • 160. Exercise 4 36.commit to git git add . git commit -m "Scrutinizer support added" git tag -a v0.1.8 -m "version 0.1.8" git push -u origin master git push origin v0.1.8 37.change composer.json to require version ^1.0.0 for my_first_library 38.composer update 160
  • 161. Exercise 4 39.commit to git git add . git commit -m "Using version ^1.0 from my_first_library" git tag -a v0.1.9 -m "version 0.1.9" git push -u origin master git push origin v0.1.9 40.Create contributing files: CONTRIBUTING.md and CODE_OF_CONDUCT.md 161
  • 162. Exercise 4 41.Add more sections to README 1. Install 2. Change log 3. Testing 42.commit to git git add . git commit -m "Improvements to README" git tag -a v0.1.10 -m "version 0.1.10" git push -u origin master git push origin v0.1.10 162
  • 163. Exercise 4 43.submit the package to packagist.org using the github repository 44.Make the package to be autoupdated in packagist on push 1. Go to your GitHub repository 2. Click the "Settings" button 3. Click "Integrations & services" 4. Add a "Packagist" service, and configure it with your API token, plus your Packagist username 5. Check the "Active" box and submit the form 163
  • 164. 164
  • 165. 165
  • 166. 166
  • 167. 167
  • 168. 168
  • 169. Exercise 4 45.Add last version in packagist badge to README.md file [![Latest Version on Packagist][ico-version]][link-packagist] [ico-version]: https://img.shields.io/packagist/v/conquerorsoft/ my_first_project.svg?style=flat [link-packagist]: https://packagist.org/packages/conquerorsoft/ my_first_project 169
  • 170. Exercise 4 46.commit to git git add . git commit -m "Instructions to use packagist.org in README" git tag -a v0.1.11 -m "version 0.1.11" git push -u origin master git push origin v0.1.11 170
  • 171. Exercise 4 47.create a gh-pages branch git checkout -b gh-pages git push -u origin gh-pages git checkout master 48.Go to github settings for your repository 49.Choose a theme in GitHub Pages section 50.Your project page is ready now: https:// conquerorsoft.github.io/my_first_project/ 171
  • 172. 172
  • 173. Exercise 4 51.commit to git git add . git commit -m "Documentation instructions for the project" git tag -a v1.0.0 -m "version 1.0.0" git push -u origin master git push origin v1.0.0 173
  • 177. References, credits and resources 1. SemVer.org 2. keepachangelog.com 3. phppackagechecklist.com 4. composer.org 5. thephpleague.com 6. poser.pugx.org 7. readthedocs.org 8. www.phpdoc.org 9. phpunit.de 10.packagist.org 11.packagist.com 12.www.php-fig.org/psr/psr-2 13.github.com/squizlabs/PHP_CodeSniffer 14.pages.github.com 15.travis-ci.org 16.choosealicense.com 17.spdx.org/licenses 18.codeclimate.com 19.getcomposer.org/doc/articles/handling- private-packages-with-satis.md 20.https://www.contributor-covenant.org/ 21.http://www.mkdocs.org/ 177