PayPal - The safer, easier way to pay online!

PHP libraries - 5 minutes starter guide

Create a project

First, prepare Maven and follow the preparation instructions.

Next, type the following Maven goal in your command line and execute it

mvn archetype:generate \
-DarchetypeGroupId=org.phpmaven \
-DarchetypeArtifactId=php5-lib-archetype \
-DarchetypeVersion=2.0.1 \
-DgroupId=org.sample \
-DartifactId=my-app \
-Dversion=0.0.1-SNAPSHOT
			

After some time maven will ask to confirm the parameters. The result will look like this:

my-app 
	|-- pom.xml 
	`-- src 
		|-- main 
		|	 `-- php 
		|		 `-- org 
		|			 `-- sample  
		|				`-- app.php 
		|`-- test 
		|	`-- php 
		|		`-- org 
		|			`-- sample 
		|				`-- apptest.php
		`-- site
			|-- site.xml
			`-- apt
				`-- index.apt
			
  • src/main/php - contains the project source code
  • src/test/php - contains the test source code
  • pom.xml The project's Project Object Model, or POM, looks like this:

The POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <parent>
        <groupId>org.phpmaven</groupId>
        <artifactId>php-parent-pom</artifactId>
        <version>2.0.1</version>
    </parent>
    
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.phpsample</groupId>
	<artifactId>my-app</artifactId>
	<packaging>php</packaging>
	<version>1.0-SNAPSHOT</version>
	<build>
		<plugins>
			<plugin>
				<groupId>org.phpmaven</groupId>
				<artifactId>maven-php-plugin</artifactId>
				<extensions>true</extensions>
			</plugin>
			
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-site-plugin</artifactId>
			    <version>3.0</version>
			    <configuration>
					<reportPlugins>
						<plugin>
							<groupId>org.phpmaven</groupId>
							<artifactId>maven-php-plugin</artifactId>
							<reportSets>
								<reportSet>
									<reports>
										<report>phpdocumentor</report>
									</reports>
								</reportSet>
							</reportSets>
						</plugin>
						<plugin>
							<groupId>org.apache.maven.plugins</groupId>
							<artifactId>maven-surefire-report-plugin</artifactId>
							<version>2.10</version>
							<reportSets>
								<reportSet>
									<reports>
										<report>report-only</report>
									</reports>
								</reportSet>
							</reportSets>
						</plugin>
					</reportPlugins>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<dependencies>
		<!--  phpUnit for PHP 5 -->
		<dependency>
			<groupId>de.phpunit</groupId>
			<artifactId>PHPUnit</artifactId>
			<version>3.6.10</version>
			<type>phar</type>
		</dependency>
	</dependencies>
	
</project>

What have I just done?

What have I just done?

You have just executed the Maven goal archetype:generate and passed various parameters to that goal. The prefix archetype is the plugin containing the goal. This goal created a default project structure for your PHP project.

Build the project

Switch to your sample project directory

cd my-app

and run:

mvn package

The command line will print out various actions, ending with the following:

 ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Thu Jul 20 19:15:06 CDT 2008
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------			
			

Maven created a phar package under the project's target folder.

Project documentation

Go to the "Documentation" section.