<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Symfony Propel Enum types</title>
	<atom:link href="http://stereointeractive.com/blog/2009/03/14/symfony-propel-enum-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://stereointeractive.com/blog/2009/03/14/symfony-propel-enum-types/</link>
	<description>Development Blog</description>
	<lastBuildDate>Mon, 07 May 2012 20:07:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: ksn135</title>
		<link>http://stereointeractive.com/blog/2009/03/14/symfony-propel-enum-types/comment-page-1/#comment-480</link>
		<dc:creator>ksn135</dc:creator>
		<pubDate>Tue, 15 Sep 2009 17:08:21 +0000</pubDate>
		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=210#comment-480</guid>
		<description>&lt;pre lang=&quot;php&quot;&gt;
class Section extends BaseSection
{
  const TYPE_LIST      = &#039;list&#039;
       ,TYPE_LINK      = &#039;link&#039;
       ,TYPE_PAGE      = &#039;page&#039;
       ,TYPE_VOTE      = &#039;vote&#039;
       ,TYPE_AUTHORS   = &#039;authors&#039;

// add new above this line
        ;
  static public function getValidTypesAsArray($context = null)
  {
    $results = array();
    $ext = new ReflectionClass(&#039;Section&#039;);
    $constants = $ext-&gt;getConstants();
    foreach($constants as $name =&gt; $value)
    {
      if (!strncmp($name,&#039;TYPE_&#039;,5))
      {
        // i18n translation
        $results[$value] = myTools::__($value);
      }
    }
    if($context)
    {
      $event = new sfEvent($this, &#039;section.update_valid_types&#039;);
      $context-&gt;dispatcher-&gt;filter($event, $results);
      $results = $event-&gt;getReturnValue();
    }

    return $results;
  }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php"><span class="kw2">class</span> Section <span class="kw2">extends</span> BaseSection
<span class="br0">&#123;</span>
  <span class="kw2">const</span> TYPE_LIST      <span class="sy0">=</span> <span class="st_h">'list'</span>
       <span class="sy0">,</span>TYPE_LINK      <span class="sy0">=</span> <span class="st_h">'link'</span>
       <span class="sy0">,</span>TYPE_PAGE      <span class="sy0">=</span> <span class="st_h">'page'</span>
       <span class="sy0">,</span>TYPE_VOTE      <span class="sy0">=</span> <span class="st_h">'vote'</span>
       <span class="sy0">,</span>TYPE_AUTHORS   <span class="sy0">=</span> <span class="st_h">'authors'</span>
&nbsp;
<span class="co1">// add new above this line</span>
        <span class="sy0">;</span>
  static <span class="kw2">public</span> <span class="kw2">function</span> getValidTypesAsArray<span class="br0">&#40;</span><span class="re0">$context</span> <span class="sy0">=</span> <span class="kw4">null</span><span class="br0">&#41;</span>
  <span class="br0">&#123;</span>
    <span class="re0">$results</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$ext</span> <span class="sy0">=</span> <span class="kw2">new</span> ReflectionClass<span class="br0">&#40;</span><span class="st_h">'Section'</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="re0">$constants</span> <span class="sy0">=</span> <span class="re0">$ext</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>getConstants<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$constants</span> <span class="kw1">as</span> <span class="re0">$name</span> <span class="sy0">=&amp;</span>gt<span class="sy0">;</span> <span class="re0">$value</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
      <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">strncmp</span><span class="br0">&#40;</span><span class="re0">$name</span><span class="sy0">,</span><span class="st_h">'TYPE_'</span><span class="sy0">,</span><span class="nu0">5</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
      <span class="br0">&#123;</span>
        <span class="co1">// i18n translation</span>
        <span class="re0">$results</span><span class="br0">&#91;</span><span class="re0">$value</span><span class="br0">&#93;</span> <span class="sy0">=</span> myTools<span class="sy0">::</span>__<span class="br0">&#40;</span><span class="re0">$value</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="br0">&#125;</span>
    <span class="br0">&#125;</span>
    <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$context</span><span class="br0">&#41;</span>
    <span class="br0">&#123;</span>
      <span class="re0">$event</span> <span class="sy0">=</span> <span class="kw2">new</span> sfEvent<span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">,</span> <span class="st_h">'section.update_valid_types'</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="re0">$context</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>dispatcher<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>filter<span class="br0">&#40;</span><span class="re0">$event</span><span class="sy0">,</span> <span class="re0">$results</span><span class="br0">&#41;</span><span class="sy0">;</span>
      <span class="re0">$results</span> <span class="sy0">=</span> <span class="re0">$event</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>getReturnValue<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
&nbsp;
    <span class="kw1">return</span> <span class="re0">$results</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Jorge Chávez</title>
		<link>http://stereointeractive.com/blog/2009/03/14/symfony-propel-enum-types/comment-page-1/#comment-469</link>
		<dc:creator>Jorge Chávez</dc:creator>
		<pubDate>Wed, 19 Aug 2009 16:46:29 +0000</pubDate>
		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=210#comment-469</guid>
		<description>It&#039;s too bad that not all DB support enum data types, but it&#039;s nice to have at least some options to implement this.
A few weeks ago I was trying to use enum, but at the end I decided to go for the adding table option.
Perhaps the best possible solution yet is to simulate it like in this post.</description>
		<content:encoded><![CDATA[<p>It&#8217;s too bad that not all DB support enum data types, but it&#8217;s nice to have at least some options to implement this.<br />
A few weeks ago I was trying to use enum, but at the end I decided to go for the adding table option.<br />
Perhaps the best possible solution yet is to simulate it like in this post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Meves</title>
		<link>http://stereointeractive.com/blog/2009/03/14/symfony-propel-enum-types/comment-page-1/#comment-426</link>
		<dc:creator>Scott Meves</dc:creator>
		<pubDate>Sat, 06 Jun 2009 18:41:19 +0000</pubDate>
		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=210#comment-426</guid>
		<description>@lawrence, I don&#039;t use constants in this case because I wanted to have my user types stored in an array, and php doesn&#039;t support &quot;constant&quot; arrays.</description>
		<content:encoded><![CDATA[<p>@lawrence, I don&#8217;t use constants in this case because I wanted to have my user types stored in an array, and php doesn&#8217;t support &#8220;constant&#8221; arrays.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lawrence Krubner</title>
		<link>http://stereointeractive.com/blog/2009/03/14/symfony-propel-enum-types/comment-page-1/#comment-423</link>
		<dc:creator>Lawrence Krubner</dc:creator>
		<pubDate>Sat, 06 Jun 2009 07:44:52 +0000</pubDate>
		<guid isPermaLink="false">http://stereointeractive.com/blog/?p=210#comment-423</guid>
		<description>Scott, curious why you wouldn&#039;t use constants? You write you pull the last trick for &quot;a finite number of defined options *that will not change*.&quot;

But then you put them in an array: 

static protected $USER_TYPE_INTEGERS = array(&#039;student&#039;, &#039;supervisor&#039;, &#039;coordinator&#039;, &#039;researcher&#039;, &#039;admin&#039;);
  
I like how fast and flexible this is. But wouldn&#039;t constants better suggest that the intent was a fixed, unchanging, limited set? PHP arrays seem very flexible to me, even if you do apply the &quot;protected&quot; keyword. Seems like the only time I&#039;d want to imitate an ENUM is when I wanted something that was not flexible.</description>
		<content:encoded><![CDATA[<p>Scott, curious why you wouldn&#8217;t use constants? You write you pull the last trick for &#8220;a finite number of defined options *that will not change*.&#8221;</p>
<p>But then you put them in an array: </p>
<p>static protected $USER_TYPE_INTEGERS = array(&#8216;student&#8217;, &#8216;supervisor&#8217;, &#8216;coordinator&#8217;, &#8216;researcher&#8217;, &#8216;admin&#8217;);</p>
<p>I like how fast and flexible this is. But wouldn&#8217;t constants better suggest that the intent was a fixed, unchanging, limited set? PHP arrays seem very flexible to me, even if you do apply the &#8220;protected&#8221; keyword. Seems like the only time I&#8217;d want to imitate an ENUM is when I wanted something that was not flexible.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

