<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jon Lebensold &#187; Doctrine</title>
	<atom:link href="http://lebensold.net/category/doctrine/feed" rel="self" type="application/rss+xml" />
	<link>http://lebensold.net</link>
	<description>thoughts on web development, technology and media</description>
	<lastBuildDate>Tue, 22 Jun 2010 16:04:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Setting Unicode in Zend_Db and Doctrine with MySQL</title>
		<link>http://lebensold.net/zend/setting-unicode-in-zend_db-and-doctrine-with-mysql</link>
		<comments>http://lebensold.net/zend/setting-unicode-in-zend_db-and-doctrine-with-mysql#comments</comments>
		<pubDate>Tue, 26 Aug 2008 12:46:38 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[character encoding]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[utf8]]></category>
		<category><![CDATA[zend_db]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/?p=184</guid>
		<description><![CDATA[When your using a persistence layer like Zend_Db or Doctrine, setting the character set is crucial in order for everything to turn out as expected in your database. I've spent too much time trying to sort character encoding issues in the past, so I'm putting it here as a reference.
In Zend_Db, after configuring your database, [...]]]></description>
			<content:encoded><![CDATA[<p>When your using a persistence layer like Zend_Db or Doctrine, setting the character set is crucial in order for everything to turn out as expected in your database. I've spent too much time trying to sort character encoding issues in the past, so I'm putting it here as a reference.</p>
<p>In Zend_Db, after configuring your database, in order for arabic / persian / non-ascii characters to persist properly, you need to configure the character set:</p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">// setup database</span>
<span style="color: #0000ff;">$db</span> = Zend_Db::<span style="color: #006600;">factory</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$config</span>-&gt;<span style="color: #006600;">db</span>-&gt;<span style="color: #006600;">adapter</span>, <span style="color: #0000ff;">$config_values</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// for Unicode support</span>
<span style="color: #0000ff;">$db</span>-&gt;<span style="color: #006600;">query</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SET NAMES 'utf8'&quot;</span><span style="color: #66cc66;">&#41;</span>;
Zend_Db_Table::<span style="color: #006600;">setDefaultAdapter</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$db</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>In Doctrine, a similar declaration is needed to setup the right character set. These lines would be in the config.php file included in the sample project, or whenever you initialize your Doctrine_Manager:</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$connection</span> = Doctrine_Manager::<span style="color: #006600;">connection</span><span style="color: #66cc66;">&#40;</span>DB_PATH<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$connection</span>-&gt;<span style="color: #006600;">setCharset</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'UTF8'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/zend/setting-unicode-in-zend_db-and-doctrine-with-mysql/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Doctrine, MySQL and Zend_Date</title>
		<link>http://lebensold.net/development/doctrine-mysql-and-zend_date</link>
		<comments>http://lebensold.net/development/doctrine-mysql-and-zend_date#comments</comments>
		<pubDate>Mon, 11 Aug 2008 02:54:30 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[zend_date]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/?p=143</guid>
		<description><![CDATA[Something that I've found really helpful in C# is the DateTime object and how it can be natively mapped to NHibernate classes and then straight to the database.
The equivalent Doctrine code is almost as elegant. Here's an excellent example of when objects abstract you from the nitty-gritty string parsing code that would be required to [...]]]></description>
			<content:encoded><![CDATA[<p>Something that I've found really helpful in C# is the DateTime object and how it can be natively mapped to NHibernate classes and then straight to the database.</p>
<p>The equivalent Doctrine code is almost as elegant. Here's an excellent example of when objects abstract you from the nitty-gritty string parsing code that would be required to do time-stamping in a database:</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$today</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Date<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$newPost</span> = <span style="color: #000000; font-weight: bold;">new</span> Post<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$newPost</span>-&gt;<span style="color: #006600;">title</span> = <span style="color: #ff0000;">'posting for '</span> . <span style="color: #0000ff;">$today</span>-&gt;<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span>Zend_Date::<span style="color: #006600;">TIME_MEDIUM</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$newPost</span>-&gt;<span style="color: #006600;">createdAt</span> = <span style="color: #0000ff;">$today</span>-&gt;<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span>Zend_Date::<span style="color: #006600;">W3C</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$newPost</span>-&gt;<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Zend_Date::W3C returns a W3C compliant timestamp, which the Doctrine Model then passes to the underlying persistence layer.</p>
<p>Assuming that you had a UnitOfWork class handling your persistence, you could add createdAt to all of the YAML models, and have every record stamped with updatedAt and createdAt without changing any higher level code. </p>
<h1>Why Bother With UpdatedAt and CreatedAt?</h1>
<p>having these two columns in a table can save tremendous amounts of time sorting out concurrency issues. They also allow you to do some very primitive reporting on your data at no cost to adding complexity to the rest of your application. </p>
<p>My Doctrine Model was configured using a YAML file:</p>
<pre>&nbsp;
Post:
  tableName: post
  columns:
    id:
      primary: true
      autoincrement: true
      type: integer(4)
    createdAt: date
    title: string(255)
&nbsp;</pre>
<p>Then it's just a matter of running './doctrine rebuild-db' from the command line from the Doctrine directory and it create's the PHP classes and prepares the database columns. </p>
<p>Using Zend_Date, you can easily do date comparisons, generate different date formats, do complex date querying and so on without having to get into the string / number manipulations. </p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/doctrine-mysql-and-zend_date/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Contributing a Tutorial for Doctrine&#8217;s Cookbook</title>
		<link>http://lebensold.net/development/contributing-to-doctrine-or-hibernate-for-php</link>
		<comments>http://lebensold.net/development/contributing-to-doctrine-or-hibernate-for-php#comments</comments>
		<pubDate>Fri, 08 Aug 2008 21:51:59 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[poeaa]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[unit of work]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/?p=134</guid>
		<description><![CDATA[I recently put together a tutorial for how to write a Unit of Work in Doctrine. Doctrine is a core piece of technology for people who have experience with Hibernate or NHibernate and want the same kind of elegant query language and ORM solution. Many thanks to Jonathan Wage for reviewing my code.
]]></description>
			<content:encoded><![CDATA[<p>I recently put together a tutorial for <a href='http://www.phpdoctrine.org/blog/creating-a-unit-of-work-using-doctrine'>how to write a Unit of Work in Doctrine</a>. Doctrine is a core piece of technology for people who have experience with Hibernate or NHibernate and want the same kind of elegant query language and ORM solution. Many thanks to <a href='http://www.jwage.com/'>Jonathan Wage</a> for reviewing my code.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/contributing-to-doctrine-or-hibernate-for-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Unit of Work in PHP</title>
		<link>http://lebensold.net/php/a-unit-of-work-in-php</link>
		<comments>http://lebensold.net/php/a-unit-of-work-in-php#comments</comments>
		<pubDate>Tue, 05 Aug 2008 21:25:34 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[free code]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[poeaa]]></category>
		<category><![CDATA[unit of work]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/?p=105</guid>
		<description><![CDATA[A couple of days ago I was looking at the Repository Pattern and how you could implement it in PHP.
According to Evans' Domain-Driven-Design book, a Repository depends on a Unit of Work.
Why Bother Using A Unit of Work?
The Unit of Work is an enterprise design pattern that facilitates the persistence of many objects across a [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago I was looking at <a href='http://jon.lebensold.ca/zend/repository-pattern-in-php-not-quite-yet'>the Repository Pattern</a> and how you could implement it in PHP.</p>
<p>According to Evans' Domain-Driven-Design book, a Repository depends on a Unit of Work.</p>
<h1>Why Bother Using A Unit of Work?</h1>
<p>The Unit of Work is an enterprise design pattern that facilitates the persistence of many objects across a single or several data sources. It’s helpful to think of the Unit of Work as a way of putting everything that you would want to update, insert and delete into one bag before sending it to the database.<br />
Functionally, the Unit of Work simplifies transactional requests and helps mitigate concurrency issues on multi-user systems. </p>
<p>I wrote a Unit of Work that depends on Doctrine. Assuming we have a Project model with a name property, the consuming class can perform operations like so: </p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$t</span> = Doctrine::<span style="color: #006600;">getTable</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Project'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$lastProjects</span> = <span style="color: #0000ff;">$t</span>-&gt;<span style="color: #006600;">findByName</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'new project'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$unitOfWork</span> = <span style="color: #000000; font-weight: bold;">new</span> UnitOfWork<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// prepare an UPDATE</span>
    <span style="color: #0000ff;">$lastProjects</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>-&gt;<span style="color: #006600;">username</span> = <span style="color: #ff0000;">'old project'</span>;
    <span style="color: #0000ff;">$unitOfWork</span>-&gt;<span style="color: #006600;">RegisterModelForCreateOrUpdate</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lastProjects</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// prepare a CREATE</span>
    <span style="color: #0000ff;">$project</span> = <span style="color: #000000; font-weight: bold;">new</span> Project<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0000ff;">$project</span>-&gt;<span style="color: #006600;">name</span> = <span style="color: #ff0000;">'new project name'</span>;
&nbsp;
    <span style="color: #0000ff;">$unitOfWork</span>-&gt;<span style="color: #006600;">RegisterModelForCreateOrUpdate</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$project</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// prepare a DELETE</span>
    <span style="color: #0000ff;">$unitOfWork</span>-&gt;<span style="color: #006600;">RegisterModelForDelete</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lastProjects</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// perform the transaction</span>
<span style="color: #0000ff;">$unitOfWork</span>-&gt;<span style="color: #006600;">CommitAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>A commit already leverages the existing Doctrine connection and handles the transaction for you, ensuring that the Unit of Work either commits, or throws an Exception.</p>
<p>The UnitOfWork is also an excellent place to include logging code or event additional column data (such as UpdatedAt and UpdatedBy which might exist in all Doctrine models for concurrency / logging purposes.) </p>
<p>I haven't found a better way of doing object-comparison in PHP arrays, however I've pulled out that code into existsInCollections() if anyone has any ideas.</p>
<pre class="php">&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> UnitOfWork <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Collection of models to be persisted
	 *
	 * @var array Doctrine_Record
	 */</span>
	protected <span style="color: #0000ff;">$createOrUpdateCollection</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Collection of models to be persisted
	 *
	 * @var array Doctrine_Record
	 */</span>
	protected <span style="color: #0000ff;">$deleteCollection</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Add a model object to the create collection
	 *
	 * @param Doctrine_Record $model
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> RegisterModelForCreateOrUpdate<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$model</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// code to check to see if the model exists already</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">existsInCollections</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$model</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		    throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'model already in another collection for this transaction'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// no? add it</span>
			<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">createOrUpdateCollection</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$model</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Add a model object to the delete collection
	 *
	 * @param Doctrine_Record $model
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> RegisterModelForDelete<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$model</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// code to check to see if the model exists already</span>
		    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">existsInCollections</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$model</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    		    throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'model already in another collection for this transaction'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// no? add it</span>
			<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">deleteCollection</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$model</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Clear the Unit of Work
	 *
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ClearAll<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">deleteCollection</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">createOrUpdateCollection</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/**
	 * Perform a Commit and clear the Unit Of Work. Throw an Exception if it fails and roll back.
	 *
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CommitAll<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
    	<span style="color: #0000ff;">$manager</span> = Doctrine_Manager::<span style="color: #006600;">getInstance</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    	<span style="color: #0000ff;">$conn</span> = <a href="http://www.php.net/array_pop"><span style="color: #000066;">array_pop</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$manager</span>-&gt;<span style="color: #006600;">getConnections</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
    	try <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0000ff;">$conn</span>-&gt;<span style="color: #006600;">beginTransaction</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">performCreatesOrUpdates</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$conn</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">performDeletes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$conn</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #0000ff;">$conn</span>-&gt;<span style="color: #006600;">commit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    	<span style="color: #66cc66;">&#125;</span>
    	catch<span style="color: #66cc66;">&#40;</span>Doctrine_Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">&#41;</span>
    	<span style="color: #66cc66;">&#123;</span>
    	    <span style="color: #0000ff;">$conn</span>-&gt;<span style="color: #006600;">rollback</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>	    
&nbsp;
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">ClearAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> performCreatesOrUpdates<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$conn</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
	    <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">createOrUpdateCollection</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$model</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #0000ff;">$model</span>-&gt;<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$conn</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> performDeletes<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$conn</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">deleteCollection</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$model</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #0000ff;">$model</span>-&gt;<span style="color: #006600;">delete</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$conn</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> existsInCollections<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$model</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
	   <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">createOrUpdateCollection</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$m</span><span style="color: #66cc66;">&#41;</span>
	   <span style="color: #66cc66;">&#123;</span>
	        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$model</span>-&gt;__toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #0000ff;">$m</span>-&gt;__toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
	   <span style="color: #66cc66;">&#125;</span>
&nbsp;
	   <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">deleteCollection</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$m</span><span style="color: #66cc66;">&#41;</span>
	   <span style="color: #66cc66;">&#123;</span>
	        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$model</span>-&gt;__toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #0000ff;">$m</span>-&gt;__toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
	   <span style="color: #66cc66;">&#125;</span>
&nbsp;
	   <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/php/a-unit-of-work-in-php/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Hibernate for PHP: using Doctrine as part of a Unit-Test workflow</title>
		<link>http://lebensold.net/development/hibernate-for-php-using-doctrine-as-part-of-a-unit-test-workflow</link>
		<comments>http://lebensold.net/development/hibernate-for-php-using-doctrine-as-part-of-a-unit-test-workflow#comments</comments>
		<pubDate>Fri, 06 Jun 2008 16:52:37 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/development/hibernate-for-php-using-doctrine-as-part-of-a-unit-test-workflow</guid>
		<description><![CDATA[On the Zend general mailing list, Josh Team asked some interesting questions about form validation and best practices. Lately, I've been looking for an alternative to NHibernate for my PHP development. Thinking that I would have to use Hibernate and run PHP inside a Java bucket, I figured the barrier to entry would be too [...]]]></description>
			<content:encoded><![CDATA[<p>On the Zend general mailing list, Josh Team asked some interesting questions about form validation and best practices. Lately, I've been looking for an alternative to NHibernate for my PHP development. Thinking that I would have to use Hibernate and run PHP inside a Java bucket, I figured the barrier to entry would be too great and would require a lot of research. Then someone mentioned to Josh Team that he should use <a href="http://www.phpdoctrine.org">Doctrine</a>, an object-relational mapper in PHP.</p>
<p>The <a href="http://www.phpdoctrine.org/documentation/manual/0_10/chapter/dql-doctrine-query-language">Doctrine Documentation looks pretty solid</a> and <a href="http://ruben.savanne.be/articles/integrating-zend-framework-and-doctrine">Ruben Savanne wrote a great article about integrating Doctrine into a Zend Framework project</a>. I wholeheartedly agree with his statement that Zend_Db is a little too low level for 90% of tasks that application developers are aiming to accomplish. With a simple YAML configuration, Doctrine promises to generate the necessary classes and even your database schema. These two features are a must if you want to be able to model your database on the fly and run unit tests against a clean schema without writing a complex setup harness.</p>
<p>My only concern is the lack of any obvious enterprise support, regardless this library is worth looking at as an alternative to Zend_Db.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/hibernate-for-php-using-doctrine-as-part-of-a-unit-test-workflow/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
