<?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"
	>

<channel>
	<title>Eat my monkeydust &#187; PHP</title>
	<atom:link href="http://eatmymonkeydust.com/category/PHP/feed" rel="self" type="application/rss+xml" />
	<link>http://eatmymonkeydust.com</link>
	<description>Life, PHP and Symfony - straight from the monkey's mouth</description>
	<pubDate>Mon, 04 Aug 2008 08:57:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Symfony security, sessions not cleared when logging out</title>
		<link>http://eatmymonkeydust.com/2008/08/symfony-security-sessions-not-cleared-when-logging-out/</link>
		<comments>http://eatmymonkeydust.com/2008/08/symfony-security-sessions-not-cleared-when-logging-out/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 08:57:48 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[login]]></category>

		<category><![CDATA[security]]></category>

		<category><![CDATA[session]]></category>

		<category><![CDATA[signout]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=36</guid>
		<description><![CDATA[I&#8217;m not sure if this will be covered in 1.1 (maybe someone can shed some light on it?) but currently when you logout using sfGuardAuth standard functionality, the session is not cleared/destroyed.
This only came to light recently, when I was scratching my head over why a parameter I had set was still available in the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure if this will be covered in 1.1 (maybe someone can shed some light on it?) but currently when you logout using sfGuardAuth standard functionality, the session is not cleared/destroyed.</p>
<p>This only came to light recently, when I was scratching my head over why a parameter I had set was still available in the $sf_params array even after logging out, and logging back in again as a <strong>different user</strong>. This threw up an interesting security issue, because I started to wonder if I&#8217;d set any admin specific parameters elsewhere which could be reused by another user on the same machine.</p>
<p>The fix is fairly straightforward, but can only be run when not in test mode, because sfBrowser does not like the session to be destroyed! Maybe this is why it has never been written into the core functionality?</p>
<p>In apps/yourapp/modules/sfGuardAuth/actions/actions.class.php</p>

<div class="wp_syntax"><div class="code"><pre class="php"> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeSignout<span style="color: #66cc66;">&#40;</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>sfConfig<span style="color: #66cc66;">::</span><span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'sf_environment'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">!=</span> <span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066;">session_destroy</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #000066;">session_write_close</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #000066;">session_regenerate_id</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
     <span style="color: #66cc66;">&#125;</span>
     parent<span style="color: #66cc66;">::</span><span style="color: #006600;">executeSignout</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
   <span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Adding the parent::executeSignout() line means that you can let the sfGuard plugin do the remainder of the work for you, so rather than overriding the function, you are just adding a bit to the start of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/08/symfony-security-sessions-not-cleared-when-logging-out/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Symfony generators - automatic wildcards on filters with plugins</title>
		<link>http://eatmymonkeydust.com/2008/07/symfony-generators-automatic-wildcards-on-filters-with-plugins/</link>
		<comments>http://eatmymonkeydust.com/2008/07/symfony-generators-automatic-wildcards-on-filters-with-plugins/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 10:54:13 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[filter]]></category>

		<category><![CDATA[generator]]></category>

		<category><![CDATA[wildcard]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=35</guid>
		<description><![CDATA[I was just working with a user list using an admin generator, and received a suggestion that username searches should automatically include wildcards in the searches (front and back), so it would not be necessary to add the asterisk. The problem was that the list was based on the sfGuardUser plugin, and we all know [...]]]></description>
			<content:encoded><![CDATA[<p>I was just working with a user list using an admin generator, and received a suggestion that username searches should automatically include wildcards in the searches (front and back), so it would not be necessary to add the asterisk. The problem was that the list was based on the sfGuardUser plugin, and we all know that modifying the contents of a plugin can be bad news.</p>
<p>The way to do this without modifying the plugin, is to override the action that is being called, and then call the parent method. In this case, the action that was processing the form submission was sfGuardUserActions->executeList(). So in apps/yourapp/modules/sfGuardUser/actions/actions.class.php add the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">//Add fields to auto-wildcard to this list</span>
    <span style="color: #ff0000">$wildcardFields</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;username&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filters</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">getRequestParameter</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;filters&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #ff0000">$originalFilters</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$filters</span><span style="color: #66cc66;">;</span>
&nbsp;
      <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$wildcardFields</span> <span style="color: #b1b100;">as</span> <span style="color: #ff0000">$fieldName</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">// Only add the wildcards if the user is not already using them</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000066;">strpos</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filters</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000">$fieldName</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">===</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
          <span style="color: #ff0000">$filters</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000">$fieldName</span><span style="color: #66cc66;">&#93;</span>  <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$filters</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000">$fieldName</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #66cc66;">;</span>
        <span style="color: #66cc66;">&#125;</span>
      <span style="color: #66cc66;">&#125;</span>
      <span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">getRequest</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">getParameterHolder</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">set</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;filters&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$filters</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
    <span style="color: #66cc66;">&#125;</span>
    parent<span style="color: #66cc66;">::</span><span style="color: #006600;">executeList</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">// Set the filters back to their original values before the template is rendered</span>
    <span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&gt;</span><span style="color: #006600;">filters</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$original</span><span style="color: #66cc66;">;</span>
  <span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now the request parameters for the selected fields are automatically prepended and appended with an asterisk before calling the parent function of the same name to continue with the request. Once the parent has finished, we then set the filters back to their original value, otherwise the asterisks we added would now appear in the fields when the page is presented.</p>
<p>An enhancement to this would be to specify the auto-wildcards field in the .yml file, rather than specifying it here in the action.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/07/symfony-generators-automatic-wildcards-on-filters-with-plugins/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Symfony sfGuardUser &#8220;remember me&#8221; checkbox/cookie does not work</title>
		<link>http://eatmymonkeydust.com/2008/07/symfony-sfguarduser-remember-me-checkboxcookie-does-not-work/</link>
		<comments>http://eatmymonkeydust.com/2008/07/symfony-sfguarduser-remember-me-checkboxcookie-does-not-work/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 19:27:56 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[cookie]]></category>

		<category><![CDATA[plugin]]></category>

		<category><![CDATA[remember me]]></category>

		<category><![CDATA[sfguarduser]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=34</guid>
		<description><![CDATA[It seems that the sfGuard plugin only checks the &#8220;remember me&#8221; cookie if the user attempts to access a secure module. This is fine if your site requires a login for any access, and thus is always is_secure: on, however if you have any &#8220;public&#8221; pages which logged in and non-logged in users can access, [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that the sfGuard plugin only checks the &#8220;remember me&#8221; cookie if the user attempts to access a secure module. This is fine if your site requires a login for any access, and thus is always is_secure: on, however if you have any &#8220;public&#8221; pages which logged in and non-logged in users can access, users that have selected the &#8220;remember me&#8221; box will not be logged in automatically.</p>
<p>Solution:</p>
<p>Of course this could be fixed in the plugin, but if you do not want to (and shouldn&#8217;t) modify the plugin code directly, you can add another filter which will check the cookie. Assuming you have already installed the sfGuardPlugin, and have a &#8220;remember me&#8221; checkbox implemented, this is all you will need to do to get the automatic logins on non-secure pages:</p>
<p>in apps/yourapp/config/filters.yml add the remember me filter</p>

<div class="wp_syntax"><div class="code"><pre class="php">rendering<span style="color: #66cc66;">:</span> ~
web_debug<span style="color: #66cc66;">:</span> ~
security<span style="color: #66cc66;">:</span>
  <span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">:</span> sfGuardBasicSecurityFilter
&nbsp;
<span style="color: #808080; font-style: italic;"># generally, you will want to insert your own filters here</span>
&nbsp;
remember<span style="color: #66cc66;">:</span>
  <span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">:</span> rememberMeFilter
&nbsp;
cache<span style="color: #66cc66;">:</span>     ~
common<span style="color: #66cc66;">:</span>    ~
flash<span style="color: #66cc66;">:</span>     ~
execution<span style="color: #66cc66;">:</span> ~</pre></div></div>

<p>Now create rememberMeFilter.class.php in apps/yourapp/lib<br />
This example uses Propel</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> rememberMeFilter <span style="color: #000000; font-weight: bold;">extends</span> sfFilter
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$filterChain</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">// execute this filter only once, and if the user is not already logged in, and has a cookie set</span>
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>isFirstCall<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;</span>amp<span style="color: #66cc66;">;&amp;</span>amp<span style="color: #66cc66;">;</span> <span style="color: #66cc66;">!</span><span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getUser<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>isAuthenticated<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&amp;</span>amp<span style="color: #66cc66;">;&amp;</span>amp<span style="color: #66cc66;">;</span> <span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getCookie<span style="color: #66cc66;">&#40;</span>sfConfig<span style="color: #66cc66;">::</span><span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'app_sf_guard_plugin_remember_cookie_name'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'sfRemember'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #808080; font-style: italic;">// See if a user exists with this cookie in the remember database</span>
      <span style="color: #ff0000">$c</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Criteria<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
      <span style="color: #ff0000">$c</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>add<span style="color: #66cc66;">&#40;</span>sfGuardRememberKeyPeer<span style="color: #66cc66;">::</span><span style="color: #006600;">REMEMBER_KEY</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getCookie<span style="color: #66cc66;">&#40;</span>sfConfig<span style="color: #66cc66;">::</span><span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'app_sf_guard_plugin_remember_cookie_name'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'sfRemember'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
      <span style="color: #ff0000">$c</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>add<span style="color: #66cc66;">&#40;</span>sfGuardRememberKeyPeer<span style="color: #66cc66;">::</span><span style="color: #006600;">IP_ADDRESS</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getHttpHeader <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'addr'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'remote'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$resultArray</span> <span style="color: #66cc66;">=</span> sfGuardRememberKeyPeer<span style="color: #66cc66;">::</span><span style="color: #006600;">doSelectJoinsfGuardUser</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$c</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #ff0000">$resultRow</span> <span style="color: #66cc66;">=</span> <span style="color: #000066;">current</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$resultArray</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #ff0000">$this</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getUser<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>signIn<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$resultRow</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>getSfGuardUser<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #808080; font-style: italic;">// execute next filter</span>
    <span style="color: #ff0000">$filterChain</span><span style="color: #66cc66;">-&amp;</span>gt<span style="color: #66cc66;">;</span>execute<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>That should do it, now your users will be logged in on any page if they have the cookie set. The sfGuardPlugin will still take care of setting the cookie and clearing it on logout.</p>
<p>Remember when using these cookies, it&#8217;s good practice to ask the user to re-enter their password when doing anything sensitive, like submitting an order or changing any personal details like their password.</p>
<p>A <a href="http://shiny.ma3x.net/2008/07/03/sfguardplugin-remember-me-follow-up">follow up by Shiny</a> explains that you can also get this working by securing modules with empty permission sets like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php">all<span style="color: #66cc66;">:</span>
  is_secure<span style="color: #66cc66;">:</span> on
&nbsp;
index<span style="color: #66cc66;">:</span>
  credentials<span style="color: #66cc66;">:</span> <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span></pre></div></div>

<p>Be careful with setting that globally though if you&#8217;re trying to set a &#8220;secure it first, grant permissions later&#8221; style system, because with the above - everything is accessible until secured.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/07/symfony-sfguarduser-remember-me-checkboxcookie-does-not-work/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Yaml (yml) file gotchas - trying to set default culture to &#8220;no&#8221;</title>
		<link>http://eatmymonkeydust.com/2008/05/yaml-yml-file-gotchas-trying-to-set-default-culture-to-no/</link>
		<comments>http://eatmymonkeydust.com/2008/05/yaml-yml-file-gotchas-trying-to-set-default-culture-to-no/#comments</comments>
		<pubDate>Fri, 09 May 2008 17:03:49 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[configuration]]></category>

		<category><![CDATA[i18n]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=24</guid>
		<description><![CDATA[The yaml file parser will attempt to parse all the values, rather than taking them as they are - which in most cases is a good thing, however you must remember to use quotes when the intended output is a string, and the parser may interpret the value otherwise:

default_culture:   en
// No problem, en [...]]]></description>
			<content:encoded><![CDATA[<p>The yaml file parser will attempt to parse all the values, rather than taking them as they are - which in most cases is a good thing, however you must remember to use quotes when the intended output is a string, and the parser may interpret the value otherwise:</p>

<div class="wp_syntax"><div class="code"><pre class="php">default_culture<span style="color: #66cc66;">:</span>   en
<span style="color: #808080; font-style: italic;">// No problem, en is treated as a string </span>
<span style="color: #808080; font-style: italic;">// and /en/ is automatically added to links</span>
&nbsp;
default_culture<span style="color: #66cc66;">:</span> no
<span style="color: #808080; font-style: italic;">// Oops, no is translated by Symfony </span>
<span style="color: #808080; font-style: italic;">// the same way as false, 0 or off, giving it a boolean value!</span>
&nbsp;
default_culture<span style="color: #66cc66;">:</span> <span style="color: #ff0000;">'no'</span>
<span style="color: #808080; font-style: italic;">// That's better, now you will have the intended results.</span></pre></div></div>

<p>The same applies to any yml files that you may have &#8220;keywords&#8221; in, so try to always use quotes round everything that is not boolean, integer, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/05/yaml-yml-file-gotchas-trying-to-set-default-culture-to-no/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to write complex queries using Propel</title>
		<link>http://eatmymonkeydust.com/2008/04/how-to-write-complex-queries-using-propel/</link>
		<comments>http://eatmymonkeydust.com/2008/04/how-to-write-complex-queries-using-propel/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 09:27:22 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[propel]]></category>

		<category><![CDATA[criteria]]></category>

		<category><![CDATA[generator]]></category>

		<category><![CDATA[query]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=13</guid>
		<description><![CDATA[This is a monster subject, and I spent a long time scratching my head over a few things yesterday, until I came across this site:
http://propel.jondh.me.uk/
It&#8217;s developed by a Symfony user, and allows you to type in sql statements using nested braces for prioritising. The form will then return a nicely formatted block of Propel code.
It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>This is a monster subject, and I spent a long time scratching my head over a few things yesterday, until I came across this site:</p>
<p><a title="Propel Criteria Builder" href="http://propel.jondh.me.uk/" target="_blank">http://propel.jondh.me.uk/</a></p>
<p>It&#8217;s developed by a Symfony user, and allows you to type in sql statements using nested braces for prioritising. The form will then return a nicely formatted block of Propel code.</p>
<p>It&#8217;s not perfect, and it doesn&#8217;t cover everything just yet, but it&#8217;s great for getting some ideas about the structure and how to use various criteria - it&#8217;s also spot on if you are trying to learn Propel and already know how to structure SQL statements.</p>
<p>Discuss this tool and/or contribute on the <a title="Discuss Propel Criteria Builder" href="http://www.symfony-project.org/forum/index.php/m/32692/" target="_blank">Symfony Forum</a></p>
<p>Using a combination of tools like this, and taking a look at the generated files in lib/model/om should give you a good push, and a bit of a shortcut to more complex queries than you may be used to - rather than having to trawl the Propel documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/04/how-to-write-complex-queries-using-propel/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Propel is complaining about a table that doesn&#8217;t exist</title>
		<link>http://eatmymonkeydust.com/2008/04/propel-is-complaining-about-a-table-that-doesnt-exist/</link>
		<comments>http://eatmymonkeydust.com/2008/04/propel-is-complaining-about-a-table-that-doesnt-exist/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 08:39:39 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[propel]]></category>

		<category><![CDATA[clean up]]></category>

		<category><![CDATA[dump]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[lib]]></category>

		<category><![CDATA[propel-dump-data]]></category>

		<category><![CDATA[schema]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=12</guid>
		<description><![CDATA[When you change your mind about your schema, and rename or remove any of your tables from your schema.yml or xml files, you must manually remove all the related classes in the lib/ folder.
Symfony does not delete these unused files when you run a build, so they will stack up and cause Propel errors, for [...]]]></description>
			<content:encoded><![CDATA[<p>When you change your mind about your schema, and rename or remove any of your tables from your schema.yml or xml files, you must manually remove all the related classes in the lib/ folder.</p>
<p>Symfony does not delete these unused files when you run a build, so they will stack up and cause Propel errors, for example when calling propel-dump-data.</p>
<p>Of course you can safely delete the lib/om and lib/map folders and run the build again, but you should manually delete the relevant files in /lib as there could be some user generated content in there also. These files are unlikely to cause any errors but might as well be deleted as part of your clean up since they are effectively useless if you have removed their referenced tables from the schema.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/04/propel-is-complaining-about-a-table-that-doesnt-exist/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Help! Symfony is ignoring my settings in app.yml</title>
		<link>http://eatmymonkeydust.com/2008/04/help-symfony-is-ignoring-my-settings-in-appyml/</link>
		<comments>http://eatmymonkeydust.com/2008/04/help-symfony-is-ignoring-my-settings-in-appyml/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 08:47:35 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[configuration]]></category>

		<category><![CDATA[app.yml]]></category>

		<category><![CDATA[config]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[ignore]]></category>

		<category><![CDATA[settings]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=11</guid>
		<description><![CDATA[Something that just cropped up today&#8230;
As your site grows, and you add more and more config to the app.yml file, be very careful not to re-declare the same named element. Symfony will not warn you, and there will be no errors - but the second (lower) instance will simple overwrite the first!
For example, if you [...]]]></description>
			<content:encoded><![CDATA[<h3>Something that just cropped up today&#8230;</h3>
<p>As your site grows, and you add more and more config to the app.yml file, be very careful not to re-declare the same named element. Symfony will not warn you, and there will be no errors - but the second (lower) instance will simple overwrite the first!</p>
<p>For example, if you have forgotten that you already have an element called profile hiding near the top of the file, and you add another one called profile at the bottom, with all your profile page settings - the lower one will destroy the one higher in the file.</p>
<p>This can be hard to spot if you have been meticulously coding and added a default value to all your sfConfig::get() calls because chances are when you are developing the site, all your defaults will be the same as the ones you have specified in app.yml.</p>
<p>The problem will become apparent when an end user tries to change the configuration and the change is ignored, because Symfony is simply using the default value rather than the one the user thinks they are setting.</p>
<p>Careful out there kids!</p>
]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/04/help-symfony-is-ignoring-my-settings-in-appyml/feed/</wfw:commentRss>
		</item>
		<item>
		<title>UTF-8 and strlen()</title>
		<link>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/</link>
		<comments>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 10:14:27 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[Web]]></category>

		<category><![CDATA[Encoding]]></category>

		<category><![CDATA[multibyte]]></category>

		<category><![CDATA[strlen]]></category>

		<category><![CDATA[UTF-8]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=9</guid>
		<description><![CDATA[Trying to find out the length of a string and wondering why the values are often wrong?
UTF-8 characters can be multi-byte, and strlen() returns the length of the string in bytes, which means the string ååå would actually have a &#8220;length&#8221; of 6.
One solution is to use the multibyte function &#8220;mb_strlen&#8221; instead, you will need [...]]]></description>
			<content:encoded><![CDATA[<p>Trying to find out the length of a string and wondering why the values are often wrong?</p>
<p>UTF-8 characters can be multi-byte, and strlen() returns the length of the string in bytes, which means the string ååå would actually have a &#8220;length&#8221; of 6.</p>
<p>One solution is to use the multibyte function &#8220;mb_strlen&#8221; instead, you will need to have PHP compiled with this - but it seems to be a default in later versions.</p>
<p>E.g.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #ff0000">$value</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;ÅØÆbob&quot;</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">echo</span> <span style="color: #000066;">strlen</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$value</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">// 9</span>
&nbsp;
<span style="color: #000066;">echo</span> <span style="color: #000066;">mb_strlen</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000">$value</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'UTF-8'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">// 6</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/04/utf-8-and-strlen/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Email validator bug</title>
		<link>http://eatmymonkeydust.com/2008/04/email-validator-bug/</link>
		<comments>http://eatmymonkeydust.com/2008/04/email-validator-bug/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 13:27:12 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[bug]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[june]]></category>

		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=4</guid>
		<description><![CDATA[The problem
There is a bug in Symfony&#8217;s email validator which means that unless you use both modes (strict and non-strict) invalid email addresses are possible.
Time of writing we are at version 1.0.13 - this could well be (and probably will be) fixed in 1.1 but please let me know if you spot that this has [...]]]></description>
			<content:encoded><![CDATA[<h3>The problem</h3>
<p>There is a bug in Symfony&#8217;s email validator which means that unless you use both modes (strict and non-strict) invalid email addresses are possible.</p>
<p>Time of writing we are at version 1.0.13 - this could well be (and probably will be) fixed in 1.1 but please let me know if you spot that this has been fixed beforehand.</p>
<h3>Strict mode validation</h3>
<p>This mode is intended to catch email addresses such as root@localhost, but unfortunately it does not check for valid email strings, so %,%@hotmail.com would be accepted, as well as many other illegal character combinations.</p>
<h3>Non-strict mode</h3>
<p>This mode checks that the email address contains legal characters, but does not check for internal addresses. This is fine for most cases, but it is worth restricting users from using your site to spam your local mail server.</p>
<h3>Solution 1</h3>
<p><a href="http://www.wwwp.de/blog/archives/26-Bug-in-Symfonys-email-validator.html" target="_blank">Sapheriel</a> suggests on his blog that one solution is to override the functionality of the class, and then restore it once an update has been released.</p>
<p>&#8220;The best way to achieve this with the least amount of intrusion is to copy sfEmailValidator.class.php into your project&#8217;s library folder, modify it, and delete it once a fix has been published&#8221;</p>
<p>This may suit many users</p>
<h3>Solution 2</h3>
<p>If you do not want to worry about something you may have to do in the future, you can also run the validator twice, for example in your validator.yml file:</p>

<div class="wp_syntax"><div class="code"><pre class="text">DoubleCheckEmailValidator:
  class: sfEmailValidator
  param:
    class: sfGuardUser
    column: email
    strict: true
    email_error: This email address is invalid
&nbsp;
fields:
  email:
    required:
      msg: Please enter an email address
    sfEmailValidator:
      email_error: This email address is invalid
      strict: false
    sfPropelUniqueValidator:
      class: sfGuardUser
      column: email
      unique_error: This email is already in use
    doubleCheckEmailValidator:</pre></div></div>

<p>You could also write a custom validator which calls the email validator twice, however we have opted for this solution for now.</p>
<h5>Thanks to June for the content.</h5>
]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/04/email-validator-bug/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Symfony and I - an introduction</title>
		<link>http://eatmymonkeydust.com/2008/04/welcome/</link>
		<comments>http://eatmymonkeydust.com/2008/04/welcome/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 10:47:37 +0000</pubDate>
		<dc:creator>Russ</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Personal]]></category>

		<category><![CDATA[Symfony]]></category>

		<category><![CDATA[askeet]]></category>

		<category><![CDATA[hello]]></category>

		<category><![CDATA[object]]></category>

		<category><![CDATA[object oriented]]></category>

		<category><![CDATA[oriented]]></category>

		<category><![CDATA[welcome]]></category>

		<guid isPermaLink="false">http://eatmymonkeydust.com/?p=3</guid>
		<description><![CDATA[I&#8217;ve been working with PHP for several years, and in November of 2007 I became part of a team tasked with researching Symfony for a new web project, with the goal of creating a plugin oriented media portal for Norway.
Other than some Java training at university, and the odd borrowed third-party classes (notably phpclasses.org) my [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" style="float: left;" src="http://www.symfony-project.org/images/homepage/books.jpg" alt="Symfony book" />I&#8217;ve been working with PHP for several years, and in November of 2007 I became part of a team tasked with researching Symfony for a new web project, with the goal of creating a plugin oriented media portal for Norway.</p>
<p>Other than some Java training at university, and the odd borrowed third-party classes (notably <a title="PHP Classes" href="http://www.phpclasses.org" target="_blank">phpclasses.org</a>) my PHP background up to this point was purely based on procedural style programming. I&#8217;d worked on some big projects, some I&#8217;m proud of and some I really want to go back to and rewrite from scratch, a sentence I&#8217;m sure you will hear from many &#8220;code monkeys&#8221;.</p>
<p>Symfony for me, was my first breach into the much hyped object oriented style PHP5 - and a whole new way of thinking. In the following articles, I hope to share with you the experiences I have had, with PHP5, Symfony and any other related technologies that I stumble across.</p>
<p>One of the things I have realised in the last few weeks, is that when searching for answers to problems that are not well documented, the most common results are in the form of developer blogs. Some of these have been invaluable to me and I&#8217;d like to credit them here, I&#8217;d also like this to become one of those blogs - since some of the answers I have sought have not been so easily forthcoming.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatmymonkeydust.com/2008/04/welcome/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
