It looks like you are viewing these slides on GitHub. Please clone the source repository in order to get the included PHP examples to work.
Welcome to the Head Museum. I'm Leonard Nimoy.
.zip
Warning: This library is outdated (last release 2010) and is in desperate need of a code refresh!
We'll merely use it to make a few arguments later on.
<?php
// Include needed classes
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_pie.php');
// Our data
$data = array(78, 22);
// Create the Pie Graph
$graph = new PieGraph(350, 300, 'auto');
$graph->SetShadow();
// Set A title for the plot + disable the border
$graph->title->Set("Percentage of chart which resembles Pac-man");
$graph->SetFrame(false);
// Create the pieplot
$pieplot = new PiePlot($data);
$pieplot->SetCenter(0.5, 0.5);
$pieplot->SetStartAngle(39);
$pieplot->SetLegends(array('Pac-man', 'Not Pac-Man'));
// Add the pieplot to the graph
$graph->Add($pieplot);
// JpGraph Bug: one must add the pieplot before setting colors
$pieplot->SetSliceColors(array('#FFFF00','#FF0000'));
// Style the Legend
$graph->legend->SetFrameWeight(0);
$graph->legend->Pos(0.5, 0.90, 'center', 'top');
$graph->legend->SetFillColor('white');
$graph->legend->SetColumns(2);
// Display the graph
$graph->Stroke();
require
it.<?php
// Include SwiftMailer Autoloader
require_once 'swiftmailer/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('relay.odisee.be', 25);
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Lorem Ipsum')
->setFrom(array('johndoe@example.org' => 'John Doe'))
->setTo(array(
'blackhole@bram.us' => 'blackhole'
))
->setBody(strip_tags(file_get_contents('assets/content.html')))
->addPart(file_get_contents('assets/content.html'), 'text/html');
// Send it (or at least try to)
if(!$mailer->send($message, $errors)) {
echo 'Mailer Error: ';
print_r($errors);
} else {
echo 'Message sent!';
}
// EOF
include
or require
.
spl_autoload_register('nameOfTheFunction');
function autoload($class) {
if (0 !== strpos($class, 'Swift_')) { //Don't interfere w other autoloaders
return;
}
$path = __DIR__ . '/' . str_replace('_', '/', $class) . '.php';
if (!file_exists($path)) return;
require $path;
}
Swift_InputByteStream
it'll include /path/to/swiftmailer/Swift/InputByteStream.php
Swift_Encoder_Base64Encoder
it'll include /path/to/swiftmailer/Swift/Encoder/Base64Encoder.php
Swift_Encoder_Base64Encoder
Base64Encoder
in the Swift\Encoder
namespaceLet's take a look at the files in assets/01/examples/namespaces/
→
namespace Ikdoeict\Demo;
class Foo { ... }
$foo = new \Ikdoeict\Demo\Foo('hello-foo');
use
– imported namespaces.
namespace Ikdoeict\Demo;
class Bar extends Foo { ... } // = extends Ikdoeict\Demo\Foo
use \Ikdoeict\Demo\Baz;
$baz = new Baz('hello-baz'); // = \Ikdoeict\Demo\Baz
\
$di = new \DirectoryIterator(__DIR__);
\<VendorName>\(<Namespace>\)*<ClassName>
/path/to/project/vendor/Vendorname/Namespace/ClassName.php
\Vendorname\Namespace\ClassName
/path/to/project/Vendorname/Namespace/ClassName.php
/path/to/project/ClassName.php
Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.
vendor
subfolder), not system-wide (cfr. PEAR)$ curl -s https://getcomposer.org/installer | php
$ sudo mkdir /usr/local/bin/
$ mv composer.phar /usr/local/bin/composer
OS X users beware: If you're using MAMP, make sure that the php
binary used is the one included with MAMP, and not the one shipped with OS X. (instructions)!
composer require vendor/package version
on the CLI
$ composer require swiftmailer/swiftmailer 4.*
composer.json
{
"require": {
"swiftmailer/swiftmailer": "4.*"
}
}
./vendor/vendorname/packagename
composer.lock
composer.json
in your project root to declare your dependencies in
{
"require": {
"swiftmailer/swiftmailer": "4.*"
}
}
composer install
and composer will:
./vendor/vendorname/packagename
composer.lock
require_once __DIR__ . '/vendor/autoload.php';
<?php
// Require composer autoloader
require_once __DIR__ . '/vendor/autoload.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('relay.odisee.be', 25);
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Lorem Ipsum')
->setFrom(array('johndoe@example.org' => 'John Doe'))
->setTo(array(
'blackhole@bram.us' => 'blackhole'
))
->setBody(strip_tags(file_get_contents('assets/content.html')))
->addPart(file_get_contents('assets/content.html'), 'text/html');
// Send it (or at least try to)
if(!$mailer->send($message, $errors)) {
echo 'Mailer Error: ';
print_r($errors);
} else {
echo 'Message sent!';
}
// EOF
composer.lock
has precedence over composer.json
.
composer install
it will look for composer.lock
.composer.json
.
composer install
will use the lock file, even if you've changed composer.json
composer install
composer require vendor/package newversion
on the CLI
composer.json
composer update
composer.lock
file will be generated.
"dev-master"
"4.2.1"
">=4.1.6,<=5.0"
"4.1.*"
>=4.1.0,<4.2.0
"~4.1"
>=4.1,<5.0
vendor/
folder to version control!vendor/
folder!composer.json
to version control!composer.lock
to version control!composer require twig/twig ~1.0
composer install
Let's take a look at the files in assets/01/examples/with-composer/2.twig/
→
composer.json
/composer.lock
composer install
autoloader.php
composer require doctrine/dbal ~2.3
composer install
Let's take a look at the files in assets/01/examples/with-composer/3.doctrine/
→
Don't forget the utf8mb4
charset on the connection!