SlideShare une entreprise Scribd logo
1  sur  51
Télécharger pour lire hors ligne
implements	Hello_Dolly
Image	Credit:	Ky	on	Flickr	•	https://flic.kr/p/8x4bVQ
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Jonathan	Brinley
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
"Hello,	Dolly!"
Image	Credit:	Classic	Film	on	Flickr	•	https://flic.kr/p/KD7WWE
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
"Hello,	Dolly!"
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
hello.php
/**
	*	@package	Hello_Dolly
	*	@version	1.6
	*/
/*
Plugin	Name:	Hello	Dolly
Plugin	URI:	http://wordpress.org/plugins/hello-dolly/
Description:	This	is	not	just	a	plugin,	it	symbolizes	the	hope	and	enthusiasm	of	an	entire	generation	summed	up	in	
Author:	Matt	Mullenweg
Version:	1.6
Author	URI:	http://ma.tt/
*/
function	hello_dolly_get_lyric()	{
	 /**	These	are	the	lyrics	to	Hello	Dolly	*/
	 $lyrics	=	"Hello,	Dolly
Well,	hello,	Dolly
It's	so	nice	to	have	you	back	where	you	belong
You're	lookin'	swell,	Dolly
I	can	tell,	Dolly
You're	still	glowin',	you're	still	crowin'
You're	still	goin'	strong
We	feel	the	room	swayin'
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Refactor!
github.com/flightless/implements-hello-dolly
Image	Credit:	Classic	Film	on	Flickr	•	https://flic.kr/p/LxazKW
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
implements-hello-dolly.php
/*
Plugin	Name:	implements	Hello_Dolly
Description:	We	start	with	everyone’s	favorite	WordPress	plugin,	“Hello,	Dolly”.	With	a	dramatic	wave	of	our	hands,	w
Author:	Jonathan	Brinley
Version:	2.0
Contributors:	Matt	Mullenweg
*/
namespace	Hello_Dolly;
//	Start	the	plugin
add_action(	'plugins_loaded',	function	()	{
	 require_once	__DIR__	.	'/vendor/autoload.php';
	 Hello_Dolly_Plugin::init();
	 do_action(	'hello_dolly/init'	);
},	1,	0	);
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Composer
Autoloading
Libraries
getcomposer.org
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Composer
composer	init
{
				"name":	"flightless/implements-hello-dolly",
				"description":	"We	start	with	everyone’s	favorite	WordPress	plugin,	“Hello,	Dolly”.	With	a	dramatic	wave	of	our	ha
				"type":	"wordpress-plugin",
				"license":	"GPL-2.0",
				"authors":	[
								{
												"name":	"Jonathan	Brinley",
												"email":	"jonathan@tri.be"
								}
				]
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
composer.json
{
				"name":	"flightless/implements-hello-dolly",
				"description":	"We	start	with	everyone’s	favorite	WordPress	plugin,	“Hello,	Dolly”.	With	a	dramatic	wave	of	our	ha
				"type":	"wordpress-plugin",
				"license":	"GPL-2.0",
				"authors":	[
								{
												"name":	"Jonathan	Brinley",
												"email":	"jonathan@tri.be"
								}
				],
				"autoload":	{
								"psr-4":	{
												"Hello_Dolly":	"src/"
								}
				}
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Codeception
composer	require	--dev	lucatume/wp-browser
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Codeception
composer	install	--no-dev
{
				"name":	"flightless/implements-hello-dolly",
				/*	...	*/
				"autoload":	{
								"psr-4":	{
												"Hello_Dolly":	"src/"
								}
				},
				"require-dev":	{
								"lucatume/wp-browser":	"^1.16"
				}
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
WPLoader
vendor/bin/wpcept	bootstrap
https://github.com/lucatume/wp-browser
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
tests/integration/Hello_Dolly/	Hello_Dolly_Plugin_Test.php
namespace	Hello_Dolly;
use	CodeceptionTestCaseWPTestCase;
class	Hello_Dolly_Plugin_Test	extends	WPTestCase	{
	 public	function	test_get_instance()	{
	 	 $instance	=	Hello_Dolly_Plugin::instance();
	 	 $this->assertInstanceOf(	'Hello_DollyHello_Dolly_Plugin',	$instance	);
	 }
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
implements-hello-dolly.php
namespace	Hello_Dolly;
//	Start	the	plugin
add_action(	'plugins_loaded',	function	()	{
	 require_once	__DIR__	.	'/vendor/autoload.php';
	 Hello_Dolly_Plugin::init();
	 do_action(	'hello_dolly/init'	);
},	1,	0	);
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
src/Hello_Dolly_Plugin.php
namespace	Hello_Dolly;
/**
	*	Initializes	the	Hello,	Dolly	plugin
	*/
class	Hello_Dolly_Plugin	{
	 /**	@var	static	*/
	 private	static	$instance;
	 /**
	 	*	Initialize	the	plugin
	 	*/
	 public	static	function	init()	{
	 	 self::instance();
	 }
	 /**
	 	*	Get	the	global	instance	of	the	class
	 	*	@return	static
	 	*/
	 public	static	function	instance()	{
	 	 if	(	empty(	static::$instance	)	)	{
	 	 	 static::$instance	=	new	static();
	 	 }
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
First	Five	Principles
Single	responsibility	principle
Open/closed	principle
Liskov	substitution	principle
Interface	segregation	principle
Dependency	inversion	principle
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Single	responsibility	principle
Turn	a	string	of	lyrics	into	an	array
Get	a	random	line	from	the	lyrics	array
Texturize	a	line	of	lyrics
Wrap	lyrics	in	a	paragraph	tag
Build	language-appropriate	CSS	rules
Print	the	lyrics	to	the	browser
Print	the	style	rules	to	the	browser
Hook	into	WordPress
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
LyricsLyric_Collection
Responsibility
Fetch	a	single	line	from	an	array	of	lyrics
Why	would	it	change?
If	the	algorithm	to	fetch	a	line	changed
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
tests/integration/Hello_Dolly/	Lyrics/Lyric_Collection_Test.php
namespace	Hello_DollyLyrics;
use	CodeceptionTestCaseWPTestCase;
class	Lyric_Collection_Test	extends	WPTestCase	{
	 public	function	test_get_lyric()	{
	 	 $lyrics	=	[];
	 	 for	(	$i	=	0	;	$i	<	10	;	$i++	)	{
	 	 	 $lyrics[]	=	rand_str(	mt_rand(	0,	32	)	)	.	'	'	.	rand_str(	mt_rand(	0,	32	)	)	.	'	'	.	rand_str(	mt_rand(	0,	32	
	 	 }
	 	 $collection	=	new	Lyric_Collection(	$lyrics	);
	 	 for	(	$i	=	0	;	$i	<	20	;	$i++	)	{
	 	 	 $this->assertContains(	$collection->get_lyric(),	$lyrics	);
	 	 }
	 }
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
LyricsLyric_Collection
namespace	Hello_DollyLyrics;
class	Lyric_Collection	implements	Lyric_Collection_Interface	{
	 /**	@var	string[]	*/
	 protected	$lyrics;
	 /**	@var	int	*/
	 protected	$count	=	0;
	 /**
	 	*	Lyric_Collection	constructor.
	 	*
	 	*	@param	array	$lyrics	An	array	of	single-line	strings
	 	*/
	 public	function	__construct(	array	$lyrics	)	{
	 	 $this->lyrics	=	array_values(	$lyrics	);
	 	 $this->count	=	count(	$this->lyrics	);
	 }
	 public	function	get_lyric()	{
	 	 return	$this->get_random_lyric();
	 }
	 /**
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
LyricsLyric_Collection_Interface
namespace	Hello_DollyLyrics;
/**
	*	Interface	Lyric_Collection_Interface
	*
	*	Implementors	will	return	a	single	line	of	lyrics
	*/
interface	Lyric_Collection_Interface	{
	 /**
	 	*	@return	string	A	single	line	of	lyrics
	 	*/
	 public	function	get_lyric();
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
LyricsLyric_Collection_Factory
Responsibility
Transform	a	string	of	lyrics	into	a	Lyric_Collection
Why	would	it	change?
If	the	return	value	should	be	a	different	class
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
tests/integration/Hello_Dolly/
Lyrics/Lyric_Collection_Factory_Test.php
namespace	Hello_DollyLyrics;
use	CodeceptionTestCaseWPTestCase;
class	Lyric_Collection_Factory_Test	extends	WPTestCase	{
	 public	function	test_create_collection()	{
	 	 $lyrics	=	[];
	 	 for	(	$i	=	0	;	$i	<	10	;	$i++	)	{
	 	 	 $lyrics[]	=	rand_str(	mt_rand(	0,	32	)	)	.	'	'	.	rand_str(	mt_rand(	0,	32	)	)	.	'	'	.	rand_str(	mt_rand(	0,	32	
	 	 }
	 	 $string	=	implode(	"n",	$lyrics	);
	 	 $factory	=	new	Lyric_Collection_Factory();
	 	 $collection	=	$factory->create_collection(	$string	);
	 	 $this->assertInstanceOf(	'Hello_DollyLyricsLyric_Collection',	$collection	);
	 }
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
LyricsLyric_Collection_Factory
namespace	Hello_DollyLyrics;
/**
	*	Class	Lyric_Collection_Factory
	*
	*	Creates	a	Lyric_Collection	instance	from
	*	a	string	of	lyrics.
	*/
class	Lyric_Collection_Factory	implements	Lyric_Collection_Factory_Interface	{
	 /**
	 	*	@param	string	$lyrics
	 	*	@return	Lyric_Collection
	 	*/
	 public	function	create_collection(	$lyrics	)	{
	 	 $lyrics	=	explode(	"n",	$lyrics	);
	 	 return	new	Lyric_Collection(	$lyrics	);
	 }
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
LyricsLyric_Collection_Factory_Interface
namespace	Hello_DollyLyrics;
/**
	*	Interface	Lyric_Collection_Factory_Interface
	*
	*	Creates	a	Lyric_Collection_Interface	from	a
	*	multi-line	string	of	lyrics.
	*/
interface	Lyric_Collection_Factory_Interface	{
	 /**
	 	*	@param	string	$lyrics	A	multi-line	string	of	lyrics
	 	*	@return	Lyric_Collection_Interface
	 	*/
	 public	function	create_collection(	$lyrics	);
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Formatting
Responsibility
Apply	wptexturize()	to	a	string
Wrap	a	string	in	a	paragraph	tag	with	an	ID
Why	would	it	change?
The	formatting	algorithm	changes
The	HTML	element	changes
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Decorator
format(string)
String_Formatter
format(string)
String_Formatter
format(string)
String_Formatter_Interface
format(string)
String_Formatter_Interface
html_id
__construct(formatter,	html_id)
decorate(string)
Paragraph_Tag
html_id
__construct(formatter,	html_id)
decorate(string)
Paragraph_Tag
decorate(string)
WP_Texturize_Formatter
decorate(string)
WP_Texturize_Formatter
formatter
__construct(formatter)
format(string)
decorate(string)
String_Formatter_Decorator
formatter
__construct(formatter)
format(string)
decorate(string)
String_Formatter_Decorator
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
FormattingString_Formatter_Interface
namespace	Hello_DollyFormatting;
/**
	*	Interface	String_Formatter_Interface
	*
	*	Implementors	will	format	and	return	a	string.
	*/
interface	String_Formatter_Interface	{
	 /**
	 	*	@param	string	$string	The	string	to	be	formatted
	 	*	@return	string	The	formatted	string
	 	*/
	 public	function	format(	$string	);
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
FormattingString_Formatter
namespace	Hello_DollyFormatting;
use	CodeceptionTestCaseWPTestCase;
class	String_Formatter_Test	extends	WPTestCase	{
	 public	function	test_passthrough()	{
	 	 $string	=	rand_str();
	 	 $passthrough	=	new	String_Formatter();
	 	 $this->assertEquals(	$string,	$passthrough->format(	$string	)	);
	 }
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
FormattingString_Formatter
namespace	Hello_DollyFormatting;
/**
	*	Class	String_Formatter
	*
	*	A	passthrough	formatter	that	returns	the	given	string
	*/
class	String_Formatter	implements	String_Formatter_Interface	{
	 public	function	format(	$string	)	{
	 	 return	$string;
	 }
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
FormattingString_Formatter_Decorator
namespace	Hello_DollyFormatting;
/**
	*	Class	String_Formatter_Decorator
	*
	*	Base	class	for	string	decorators.
	*/
abstract	class	String_Formatter_Decorator	implements	String_Formatter_Interface	{
	 /**	@var	String_Formatter_Interface	*/
	 protected	$formatter;
	 public	function	__construct(	String_Formatter_Interface	$formatter	)	{
	 	 $this->formatter	=	$formatter;
	 }
	 public	function	format(	$string	)	{
	 	 $string	=	$this->formatter->format(	$string	);
	 	 return	$this->decorate(	$string	);
	 }
	 abstract	protected	function	decorate(	$string	);
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
FormattingWP_Texturize_Formatter
namespace	Hello_DollyFormatting;
use	CodeceptionTestCaseWPTestCase;
class	WP_Texturize_Formatter_Test	extends	WPTestCase	{
	 public	function	test_texturization()	{
	 	 $string	=	"You're	lookin'	swell,	Dolly";
	 	 $texturized_string	=	wptexturize(	$string	);
	 	 $this->assertNotEquals(	$string,	$texturized_string	);
	 	 $formatter	=	new	WP_Texturize_Formatter(	new	String_Formatter()	);
	 	 $this->assertEquals(	$texturized_string,	$formatter->format(	$string	)	);
	 }
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
FormattingWP_Texturize_Formatter
namespace	Hello_DollyFormatting;
/**
	*	Class	WP_Texturize_Formatter
	*
	*	Formats	a	string	with	wptexturize()
	*	@see	wptexturize()
	*/
class	WP_Texturize_Formatter	extends	String_Formatter_Decorator	{
	 protected	function	decorate(	$string	)	{
	 	 return	wptexturize(	$string	);
	 }
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
FormattingParagraph_Tag
namespace	Hello_DollyFormatting;
use	CodeceptionTestCaseWPTestCase;
class	Paragraph_Tag_Test	extends	WPTestCase	{
	 public	function	test_paragraph_tag()	{
	 	 $string	=	rand_str();
	 	 $id	=	rand_str();
	 	 $formatter	=	new	Paragraph_Tag(	new	String_Formatter(),	$id	);
	 	 $expected	=	sprintf(	'<p	id="%s">%s</p>',	$id,	$string	);
	 	 $this->assertEquals(	$expected,	$formatter->format(	$string	)	);
	 }
	 public	function	test_escaped_id()	{
	 	 $string	=	rand_str();
	 	 $id	=	rand_str(8)	.	'	'	.	rand_str(8);
	 	 $escaped_id	=	sanitize_html_class(	$id	);
	 	 $this->assertNotEquals(	$id,	$escaped_id	);
	 	 $formatter	=	new	Paragraph_Tag(	new	String_Formatter(),	$id	);
	 	 $expected	=	sprintf(	'<p	id="%s">%s</p>',	$escaped_id,	$string	);
	 	 $this->assertEquals(	$expected,	$formatter->format(	$string	)	);
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
FormattingParagraph_Tag
namespace	Hello_DollyFormatting;
/**
	*	Class	Paragraph_Tag
	*
	*	Wraps	a	string	in	a	paragraph	tag	with	an	ID
	*/
class	Paragraph_Tag	extends	String_Formatter_Decorator	{
	 /**	@var	string	*/
	 protected	$html_id;
	 /**
	 	*	Paragraph_Tag	constructor.
	 	*
	 	*	@param	String_Formatter_Interface	$formatter
	 	*	@param																												$html_id
	 	*/
	 public	function	__construct(	String_Formatter_Interface	$formatter,	$html_id	)	{
	 	 parent::__construct(	$formatter	);
	 	 $this->html_id	=	$html_id;
	 }
	 protected	function	decorate(	$string	)	{
	 	 return	sprintf(	'<p	id="%s">%s</p>',	sanitize_html_class(	$this->html_id),	$string	);
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
<p	id="dolly">You’re	lookin’	swell,	Dolly</p>
$formatter	=	new	Paragraph_Tag(
																	new	WP_Texturize_Formatter(
																					new	String_Formatter()
																	),
																	'dolly'
													);
return	$formatter->format(	"You're	lookin'	swell,	Dolly"	);
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
StylesStyle_Rules_Interface
namespace	Hello_DollyStyles;
/**
	*	Interface	Style_Rules_Interface
	*
	*	Generates	a	list	of	CSS	properties
	*/
interface	Style_Rules_Interface	{
	 /**
	 	*	@return	string
	 	*/
	 public	function	get_styles();
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
StylesDirectional_Style_Rules
namespace	Hello_DollyStyles;
/**
	*	Class	Directional_Style_Rules
	*
	*	Generates	styles	for	the	given	text	direction
	*/
class	Directional_Style_Rules	implements	Style_Rules_Interface	{
	 protected	$side;
	 /**
	 	*	Directional_Style_Rules	constructor.
	 	*
	 	*	@param	string	$side	The	side	text	floats	to.	'left'	or	'right'
	 	*/
	 public	function	__construct(	$side	)	{
	 	 if	(	empty(	$side	)	)	{
	 	 	 throw	new	InvalidArgumentException(	__(	'$this->side	must	be	set	to	a	non-empty	value'	)	);
	 	 }
	 	 $this->side	=	$side;
	 }
	 public	function	get_styles()	{
	 	 return	"
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
StylesStyle_Printer_Interface
namespace	Hello_DollyStyles;
/**
	*	Interface	Style_Printer_Interface
	*
	*	Prints	CSS	styles
	*/
interface	Style_Printer_Interface	{
	 /**
	 	*	@param	Style_Rules_Interface	$styles
	 	*	@return	void
	 	*/
	 public	function	print_styles(	Style_Rules_Interface	$styles	);
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
StylesStyle_Printer
namespace	Hello_DollyStyles;
/**
	*	Class	Style_Printer
	*
	*	Prints	the	given	style	rules	for	the	element	with	the	given	ID
	*/
class	Style_Printer	implements	Style_Printer_Interface	{
	 protected	$html_id;
	 /**
	 	*	Style_Printer	constructor.
	 	*
	 	*	@param	string	$html_id	The	ID	of	the	targeted	DOM	element
	 	*/
	 public	function	__construct(	$html_id	)	{
	 	 $this->html_id	=	$html_id;
	 }
	 /**
	 	*	@param	Style_Rules_Interface	$styles
	 	*	@return	void
	 	*/
	 public	function	print_styles(	Style_Rules_Interface	$styles	)	{
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
src/Hello_Dolly_Plugin.php
private	function	hooks()	{
	 add_action(	'admin_head',	[	$this,	'print_admin_css'	]	);
	 add_action(	'admin_notices',	[	$this,	'print_admin_notice'	]	);
}
public	function	print_admin_css()	{
	 $style_rules	=	$this->get_style_rules();
	 $printer	=	$this->get_style_printer();
	 $printer->print_styles(	$style_rules	);
}
public	function	print_admin_notice()	{
	 $lyrics	=	$this->get_lyric_collection();
	 $printer	=	$this->get_lyric_printer();
	 $printer->render(	$lyrics->get_lyric()	);
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
src/Hello_Dolly_Plugin.php
/**
	*	@return	Style_Rules_Interface
	*/
private	function	get_style_rules()	{
	 if	(	is_rtl()	)	{
	 	 $style_rules	=	$this->container[	'style_rules.rtl'	];
	 }	else	{
	 	 $style_rules	=	$this->container[	'style_rules.ltr'	];
	 }
	 return	apply_filters(	'hello_dolly/style_rules',	$style_rules	);
}
/**
	*	@return	Style_Printer_Interface
	*/
private	function	get_style_printer()	{
	 $printer	=	$this->container[	'style_printer'	];
	 return	apply_filters(	'hello_dolly/style_printer',	$printer	);
}
/**
	*	@return	Lyric_Collection_Interface
	*/
private	function	get_lyric_collection()	{
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
src/Hello_Dolly_Plugin.php
/**
	*	Initialize	the	plugin
	*
	*	@return	void
	*/
public	static	function	init(	Container	$container	)	{
	 $instance	=	self::instance();
	 $instance->container	=	$container;
	 $instance->hooks();
}
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Dependency	Injection	Container
Aura.Di
PHP-DI
Pimple
SymphonyDependencyInjection
ZendDi
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Pimple
composer	require	pimple/pimple
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
implements-hello-dolly.php
namespace	Hello_Dolly;
use	PimpleContainer;
//	Start	the	plugin
add_action(	'plugins_loaded',	function	()	{
	 require_once	__DIR__	.	'/vendor/autoload.php';
	 $container	=	new	Container();
	 $container->register(	new	Service_Provider()	);
	 Hello_Dolly_Plugin::init(	$container	);
	 do_action(	'hello_dolly/init',	Hello_Dolly_Plugin::instance(),	$container	);
},	1,	0	);
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
src/Service_Provider.php
namespace	Hello_Dolly;
use	Hello_DollyFormattingParagraph_Tag;
use	Hello_DollyFormattingString_Formatter;
use	Hello_DollyFormattingWP_Texturize_Formatter;
use	Hello_DollyLyricsLyric_Collection_Factory;
use	Hello_DollyPrintingFormatted_Printer;
use	Hello_DollyStylesDirectional_Style_Rules;
use	Hello_DollyStylesStyle_Printer;
use	PimpleContainer;
use	PimpleServiceProviderInterface;
class	Service_Provider	implements	ServiceProviderInterface	{
	 public	function	register(	Container	$container	)	{
	 	 $container[	'html_id'	]	=	'dolly';
	 	 $container[	'lyrics'	]	=	"Hello,	Dolly
Well,	hello,	Dolly
It's	so	nice	to	have	you	back	where	you	belong
You're	lookin'	swell,	Dolly
I	can	tell,	Dolly
You're	still	glowin',	you're	still	crowin'
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
implements-hello-dolly.php
namespace	Hello_Dolly;
use	PimpleContainer;
//	Start	the	plugin
add_action(	'plugins_loaded',	function	()	{
	 require_once	__DIR__	.	'/vendor/autoload.php';
	 $container	=	new	Container();
	 $container->register(	new	Service_Provider()	);
	 Hello_Dolly_Plugin::init(	$container	);
	 do_action(	'hello_dolly/init',	Hello_Dolly_Plugin::instance(),	$container	);
},	1,	0	);
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Resources
implements	Hello_Dolly
github.com/flightless/implements-hello-dolly
The	Principles	of	OOD	/	Robert	C.	Martin
butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
Inversion	of	Control	Containers	and	the	Dependency	Injection	pattern	/	Martin	Fowler
martinfowler.com/articles/injection.html
WPBrowser	/	Luca	Tumedei
github.com/lucatume/wp-browser
theaveragedev.com/tag/wp-browser/
Image	Credit:	New	York	Sunday	News
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016
Jonathan	Brinley
@jbrinley	•	jonathan@tri.be
Jonathan	Brinley	•	 	•	#wcorl	•	Slides:	@jbrinley flightless.us/wcorl2016

Contenu connexe

Dernier

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 

Dernier (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 

En vedette

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

En vedette (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

implements Hello_Dolly