<?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>SayNoToFlash</title>
	<atom:link href="http://www.saynotoflash.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.saynotoflash.com</link>
	<description>PHP, Symfony, Web Development</description>
	<lastBuildDate>Tue, 17 Jan 2012 13:27:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Call your congress-person, oppose the American Firewall</title>
		<link>http://www.saynotoflash.com/archives/call-your-congress-person-oppose-the-american-firewall/</link>
		<comments>http://www.saynotoflash.com/archives/call-your-congress-person-oppose-the-american-firewall/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 16:45:02 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=517</guid>
		<description><![CDATA[In case you haven&#8217;t been paying attention to the US political landscape, there is currently a bill in progress dubbed the great American firewall. It is a thoughtless overreaching nightmare&#8217;ish bill that claims to be for preventing copyright infringement. Please read up and understand the implications of what this bill will do. There has never [...]]]></description>
			<content:encoded><![CDATA[<p>In case you haven&#8217;t been paying attention to the US political landscape, there is currently a bill in progress dubbed the <a href="http://www.nytimes.com/2011/11/16/opinion/firewall-law-could-infringe-on-free-speech.html?_r=3">great American firewall</a>. It is a thoughtless overreaching nightmare&#8217;ish bill that claims to be for preventing copyright infringement.</p>
<p>Please read up and understand the implications of what this bill will do. There has never been a more 1984esque bill to be taken up by both houses of congress. It is absolutely ridiculous that our country would go this far just to help the massive media corporations under the veil that they are doing it for the good of the people. While supportable in concept, this is one of those &#8220;the road to hell was paved with good intentions&#8221; bills in what it will actually do.</p>
<p>Please <a href="http://www.contactingthecongress.org/">contact your congress person</a> and oppose this bill.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/call-your-congress-person-oppose-the-american-firewall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony Parallel Content Delivery &#8211; UPDATE</title>
		<link>http://www.saynotoflash.com/archives/symfony-parallel-content-delivery/</link>
		<comments>http://www.saynotoflash.com/archives/symfony-parallel-content-delivery/#comments</comments>
		<pubDate>Thu, 19 May 2011 17:30:39 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=477</guid>
		<description><![CDATA[UPDATED &#8211; 05-19-2011 I updated the script to make sure that it serves the same image from the same domain on each request. It&#8217;s counter productive to send the same image from different url&#8217;s as this increases the download time. This fix does not hash or internally check the image to see if it is [...]]]></description>
			<content:encoded><![CDATA[<p>UPDATED &#8211; 05-19-2011</p>
<p>I updated the script to make sure that it serves the same image from the same domain on each request. It&#8217;s counter productive to send the same image from different url&#8217;s as this increases the download time. This fix does not hash or internally check the image to see if it is identical to another image with a different name. This also does not store anything in a file or database, so it&#8217;s possible that the image will be served from a different url on a different page / request.</p>
<p>This is a drop in replacement for the original script. The interface for cdn_image_url and cdn_image_tag methods did not change.</p>
<p>Original Information</p>
<p>In order to reduce page latency, I&#8217;ve been implementing a parallel content delivery network on a large symfony project. This code should work on symfony and most any other php based site. What it does is allow a developer to specify a number of subdomains / domains for content delivery, such as content1.mydomain, content2.mydomain, etc&#8230; When serving images in this manner, one can greatly reduce page loading time by using multiple domains for images even if the domains are on the same server.</p>
<p>This script uses a singleton hack to keep a cursor of the current domain that the image is being served from. It then delivers the image in sequential order from the list of domains that the developer has pre-specified. A developer can specify as many domains as they want, and if the page is being served over a secure connection, the script will automatically include secure versions of the images. <em>NOTE: make sure the domains have ssl installed correctly or errors will occur.</em></p>
<p>Add this script to a file in /myproject/lib/.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Cdn <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$current_cdn</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$is_secure</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$prefix_match</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$instance</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mydomain.com'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$cdn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'www.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cd1.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cd2.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_cdn</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_PORT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'443'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_secure</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> cdn_image_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$image_path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000088;">$cdn</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_cdn</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_secure</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cdn</span> <span style="color: #339933;">.</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$domain</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$image_path</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> cdn_image_tag<span style="color: #009900;">&#40;</span><span style="color: #000088;">$image_path</span><span style="color: #339933;">,</span> <span style="color: #000088;">$option_array</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$cdn</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_cdn</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$option_array</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$option_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attribute</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$options</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$attribute</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; '</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_secure</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$cdn</span> <span style="color: #339933;">.</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$domain</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$image_path</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' /&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> get_cdn<span style="color: #009900;">&#40;</span><span style="color: #000088;">$image_path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cdn</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_cdn</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_cdn</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image_path</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prefix_match</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #000088;">$cdn</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prefix_match</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$image_path</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #000088;">$cdn</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$cdn</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_cdn</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prefix_match</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$image_path</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cdn</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_cdn</span><span style="color: #339933;">++;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$cdn</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$instance</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$instance</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Cdn<span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$instance</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then you can call your images using 1 of 2 methods throughout the project and they will be delivered sequentially through all of the domains in your CDN.</p>
<p>If you would just like the image url:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000088;">$my_url</span> <span style="color: #339933;">=</span> Cdn<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cdn_image_url</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'images/my_image.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you want the entire tag:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">echo</span> Cdn<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cdn_image_tag</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'images/swiped-box-b.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can also add attributes to the tag:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">echo</span> Cdn<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cdn_image_tag</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'images/swiped-box-b.jpg'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'alt'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My Image'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If your images are hosted on completely different domains, simply edit the $cdn property to include the full domain, and take out the self::$domain property from the appropriate method: cdn_image_url or cdn_image_tag.</p>
<p>This is a very basic class for delivering images from different domains. It does not take things into account like serving the same image from the same domain every time to take advantage of caching, or checking to see if the image actually exists. However, it should provide a basis for a more complete content delivery script.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/symfony-parallel-content-delivery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The power of caching GD images</title>
		<link>http://www.saynotoflash.com/archives/the-power-of-caching-gd-images/</link>
		<comments>http://www.saynotoflash.com/archives/the-power-of-caching-gd-images/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 16:46:15 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=497</guid>
		<description><![CDATA[I created a GD based credit card logo generator this week. It&#8217;s a simple tool and image API that allows making custom credit card and payment acceptance logos for a website. The script is a simple GD function that compiles PNG images into a single image for display on a website. In creating this, I [...]]]></description>
			<content:encoded><![CDATA[<p>I created a <a href="http://php.net/manual/en/book.image.php">GD</a> based <a href="http://www.merchantequip.com/information-center/credit-card-logos/">credit card logo generator</a> this week. It&#8217;s a simple tool and <a href="http://www.merchantequip.com/merchant-account-blog/1498/credit-card-logo-generator-and-api">image API</a> that allows making custom credit card and payment acceptance logos for a website.</p>
<p>The script is a simple GD function that compiles PNG images into a single image for display on a website. In creating this, I tested caching these images locally to see what the difference in performance would be compared to generating them on the fly every time.</p>
<p>The results were more surprising that I had imagined. I&#8217;m not going to post the code to this tool, but let&#8217;s just assume we&#8217;re creating a PNG with 8 small, 64px images on it. Total image dimensions is roughly 600px x 70px. Using a <a href="http://www.saynotoflash.com/archives/php-script-benchmark-bottleneck-debugging-snippet/">simple benchmark script</a>, I looped through creating the image 1000 times.</p>
<p>To generate this image 1000 times from scratch, it takes roughly <strong>4 seconds</strong>. This is fairly respectable considering the script is about 75 lines long and makes multiple file system calls through imagecreatefrompng.</p>
<p>Next, I created a simple local caching mechanism. It takes a newly generated image and stores it in the file system. When the API is called, the script looks for the image in the file system. If it exists, it delivers the stored image, if not, it creates it and stores using the above script. When I ran this version 1000 times, it took roughly <strong>.04 seconds</strong> to complete.</p>
<p>If you put this into perspective, .04 is 100 times faster. On a high traffic website that generates multiple images on the fly, this could make or break the usability of the website. I see more and more ecommerce sites generating product images and thumbnails on the fly. A local caching mechanism is a perfect match for this sort of usage.</p>
<p>Anyway, if you are using GD or any other image manipulating php library, I strongly urge you to look into a local caching system. It took me about 5 minutes to develop a working local cache. It&#8217;s definitely worth it both in CPU overhead and in content delivery time&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/the-power-of-caching-gd-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When do you have too much code?</title>
		<link>http://www.saynotoflash.com/archives/when-do-you-have-too-much-code/</link>
		<comments>http://www.saynotoflash.com/archives/when-do-you-have-too-much-code/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 21:54:21 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[soap]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=468</guid>
		<description><![CDATA[I was integrating a symfony project with Paypal&#8217;s Express checkout system last week. Having not messed with this API in several years, I went to Paypal&#8217;s site and downloaded their SOAP PHP SDK for integrating with their API. Their scripts work marginally out of the box albeit with terrible documentation. Many classes and functions have [...]]]></description>
			<content:encoded><![CDATA[<p>I was integrating a symfony project with Paypal&#8217;s Express checkout system last week. Having not messed with this API in several years, I went to Paypal&#8217;s site and downloaded their <a href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&#038;content_ID=developer/library_download_sdks#SOAP">SOAP PHP SDK</a> for integrating with their API. Their scripts work marginally out of the box albeit with terrible documentation. Many classes and functions have zero documentation. Some features of their API have no documentation at all. Anyway, with a little work most people can get a basic working integration with Paypal using their SDK.</p>
<p>In trying to implement several advanced features and callbacks, sifting through hundreds of classes and files in their SDK, I decided that I needed to write my own class. Starting from scratch, I came up with a bare-bones class integrating with the Express checkout API. I completely dumped Paypal&#8217;s SOAP implementation in favor of the much simpler NVP (name-value-pair) integration. I don&#8217;t see any reason to stick with SOAP on such a simple API. I did include the more advanced features like adding products and shipping (this was probably in Paypal&#8217;s, but I couldn&#8217;t find it), and shipping and tax callbacks, through the express checkout API. After about 8 hours of coding and testing, I had a working integration that consisted of a handful of files, and about 400 overly spaced lines of code.</p>
<p>I went back and parsed out Paypal&#8217;s SDK to see just how large this monster was, and it is over 190,000 lines of code, and just under 1000 individual files.</p>
<p>I had looked at 2 symfony plugins the <a href="http://www.symfony-project.org/plugins/sfPaypalDirectPlugin">PaypalDirect</a> and <a href="http://www.symfony-project.org/plugins/prestaPaypalPlugin">PrestsPaypal plugin</a>, and the both use a lightly stripped version of Paypal&#8217;s SDK.</p>
<p>So the point of this is, don&#8217;t trust some plugin or package, or script from me, from Paypal, from Symfony, or any provider unless you know it is the best or at least a reasonable way to accomplish your task. Even if the code is cached, the overhead on running 190,000 lines of code every time a customer checks out of your website is simply ridiculous when you can accomplish the same thing with a few hundred. Additionally if you take into account the potential for errors, memory leaks, and security problems with 190,000 lines of code vs. 400, there&#8217;s really no comparison.</p>
<p>Now there are times when a huge SOAP integration would be appropriate, but I can&#8217;t see how this could possibly be one of those. I also think that if a good programmer started from scratch rather than using Paypal&#8217;s bloated code, they could significantly reduce the size of their integration. It&#8217;s absolutely baffling trying to debug or get information on a PHP class or method, when there&#8217;s 1000 files that you need to hop through to find the piece of code you&#8217;re looking for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/when-do-you-have-too-much-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Network Merchants API Script</title>
		<link>http://www.saynotoflash.com/archives/network-merchants-api-script/</link>
		<comments>http://www.saynotoflash.com/archives/network-merchants-api-script/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 19:08:32 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=447</guid>
		<description><![CDATA[Have just completed a Network Merchants API class. This class utilizes the Network Merchants credit card and electronic check processing API. It also includes the customer vault API which allows merchants to securely store their customer&#8217;s credit card and bank account information in Network Merchant&#8217;s secure customer vault. Go to the Network Merchants API PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Have just completed a Network Merchants API class. This class utilizes the Network Merchants credit card and electronic check processing API. It also includes the customer vault API which allows merchants to securely store their customer&#8217;s credit card and bank account information in Network Merchant&#8217;s secure customer vault.</p>
<p><a href="http://www.saynotoflash.com/scripts/network-merchants-api-php-class-script/">Go to the Network Merchants API PHP Class &raquo;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/network-merchants-api-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google chart over HTTPS/SSL</title>
		<link>http://www.saynotoflash.com/archives/google-chart-over-httpsssl/</link>
		<comments>http://www.saynotoflash.com/archives/google-chart-over-httpsssl/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 16:17:14 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=403</guid>
		<description><![CDATA[The google charts API does not support the https protocol. If your website is being delivered through a secure connection, the chart will cause a SSL error. Here&#8217;s a quick way to deliver google chart images over ssl. To start off with, the chart image must be delivered from a secure connection. Google doesn&#8217;t allow [...]]]></description>
			<content:encoded><![CDATA[<p>The google charts API does not support the https protocol. If your website is being delivered through a secure connection, the chart will cause a SSL error. Here&#8217;s a quick way to deliver google chart images over ssl.</p>
<p>To start off with, the chart image must be delivered from a secure connection. Google doesn&#8217;t allow this plain and simple, so we need to figure out how to host it from our own site. We accomplish this by fetching the image from google using the standard API, writing it to a file, and then calling it on our own script. We basically make a image handling proxy.</p>
<p>Let&#8217;s take a simple google chart to experiment with.</p>
<p><img src="http://chart.apis.google.com/chart?chs=500x50&#038;chf=bg,s,ffffff&#038;cht=ls&#038;chd=t:23.52,20.58,26.47,23.52,23.52,23.52,100.00,0.00,23.52,23.52,27.94,20.58,23.52&#038;chco=0066ff" alt="" /></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$chart_image</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://chart.apis.google.com/chart?chs=500x50&amp;chf=bg,s,ffffff&amp;cht=ls&amp;chd=t:23.52,20.58,26.47,23.52,23.52,23.52,100.00,0.00,23.52,23.52,27.94,20.58,23.52&amp;chco=0066ff'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Next we need to make a function to fetch and save the google chart locally. It will check the chart against the local copy and save it if the chart doesn&#8217;t exist, or the image has changed. This way we aren&#8217;t re-writing the same chart on every request, but if the chart changes, it will be updated appropriately.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> saveImage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$chart_url</span><span style="color: #339933;">,</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span><span style="color: #000088;">$file_name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">md5_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #990000;">md5_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chart_url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">.</span><span style="color: #000088;">$file_name</span><span style="color: #339933;">,</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chart_url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$file_name</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Lastly we tie it all together so that it is usable in our application. Im using this within a class, but this could just be used as a function as well. Your image directory will need to be writable for this to work.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> doSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$local_image_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/path/to/images/charts/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$image_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'some_chart_image.png'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$chart_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://chart.apis.google.com/chart?chs=500x50&amp;chf=bg,s,ffffff&amp;cht=ls&amp;chd=t:23.52,20.58,26.47,23.52,23.52,23.52,100.00,0.00,23.52,23.52,27.94,20.58,23.52&amp;chco=0066ff'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">saveImage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chart_url</span> <span style="color: #339933;">,</span><span style="color: #000088;">$local_image_path</span><span style="color: #339933;">,</span><span style="color: #000088;">$image_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You&#8217;ll need to implement your own error handling, and adjust this to meet the paths and specifics of your server, but the image can now be called from:<br />
&lt;img src=&quot;/images/charts/some_chart_image.png&quot; alt=&quot;&quot; /&gt;</p>
<p>If you need help creating your base chart image, <a href="http://www.clabberhead.com/googlechartgenerator.html">this tool is a great place to start</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/google-chart-over-httpsssl/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Firefox 3 broken images breaking SSL</title>
		<link>http://www.saynotoflash.com/archives/firefox-3-broken-images-breaking-ssl/</link>
		<comments>http://www.saynotoflash.com/archives/firefox-3-broken-images-breaking-ssl/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 19:55:54 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=390</guid>
		<description><![CDATA[After battling a SSL error: &#8220;Warning contains unauthenticated content&#8221; in Firefox 3.5 for the past few days, I finally figured out what the problem was. Unlike Internet Explorer and older Firefox versions, Firefox 3.5 gives this error if there are any missing images on a webpage. Meaning, that if an image link or css reference [...]]]></description>
			<content:encoded><![CDATA[<p>After battling a SSL error: &#8220;Warning contains unauthenticated content&#8221; in Firefox 3.5 for the past few days, I finally figured out what the problem was. </p>
<p>Unlike Internet Explorer and older Firefox versions, Firefox 3.5 gives this error if there are any missing images on a webpage. Meaning, that if an image link or css reference is to a non-existent image, Firefox warns that the page is not secure. To my knowledge, Firefox versions previous to 3.something, did not behave like this. Internet explorer, Google Chrome, Safari, and every other non-Firefox browser that I tested don&#8217;t care about broken images. Not to say that Firefox is wrong, but this made the problem more difficult to diagnose because it couldn&#8217;t be reproduced in another program.</p>
<p>The difficulty in diagnosing this, is that background images that don&#8217;t load also don&#8217;t show up in the <em>page info</em> section on Firefox. Firebug didn&#8217;t provide any immediately useful information, and there was no documentation that I could find regarding this situation. </p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/09/ssl-debug1.png" alt="ssl-debug" title="ssl-debug" width="602" height="485" class="alignnone size-full wp-image-399" /></p>
<p>After several hours of searching, I realized that there was a small broken background image. Deleting or correcting the image path immediately corrected the certificate error.</p>
<p>Anyway, if anyone has been pulling out their hair trying to diagnose a mystery ssl error, and this is a possibility, definitely look into your image paths.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/firefox-3-broken-images-breaking-ssl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Symfony 1.2 redirect specific modules and actions to HTTPS (SSL)</title>
		<link>http://www.saynotoflash.com/archives/symfony-1-2-redirect-specific-modules-and-actions-to-https-ssl/</link>
		<comments>http://www.saynotoflash.com/archives/symfony-1-2-redirect-specific-modules-and-actions-to-https-ssl/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 22:24:16 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=370</guid>
		<description><![CDATA[Post Symfony 1.1, the sfSslRequirementPlugin will no longer work. Having needed a way to force a SSL connection for certain pages, I modified a few scripts that I found online, and created a very simple filter to handle this. This was inspired by this script, and the unacceptably poor example in the Symfony 1.2 book. [...]]]></description>
			<content:encoded><![CDATA[<p>Post Symfony 1.1, the <a href="http://www.symfony-project.org/plugins/sfSslRequirementPlugin">sfSslRequirementPlugin</a> will no longer work.</p>
<p>Having needed a way to force a SSL connection for certain pages, I modified a few scripts that I found online, and created a very simple filter to handle this. This was inspired by <a href="http://james.mcglinn.org/2006/10/ssl-redirect-filter-for-symfony/">this script</a>, and the unacceptably poor <a href="http://www.symfony-project.org/book/1_2/06-Inside-the-Controller-Layer#chapter_06_sub_sample_filters">example in the Symfony 1.2 book</a>.</p>
<p>To start off with, we need to modify our app.yml file to specify what modules and/or actions need to be secure. Leave the action completely blank if you want the entire module secure. Also change <strong>ignore_non_secure</strong> to true if you don&#8217;t care if non specified pages are server over a ssl connection. Basically, from the app.yml below, setting this to false, will redirect any module/action to the non-secure version if it is not specifically defined under <strong>secure_actions</strong>. Setting it to true will allow a user to request any page over https, even if it is not listed in app.yml. Let me know if this is confusing in any way.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//app.yml</span>
all<span style="color: #339933;">:</span>
  ssl<span style="color: #339933;">:</span>
    ignore_non_secure<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span>
    secure_actions<span style="color: #339933;">:</span>
      <span style="color: #339933;">-</span> <span style="color: #009900;">&#123;</span> module<span style="color: #339933;">:</span> shopping_cart<span style="color: #009900;">&#125;</span>
      <span style="color: #339933;">-</span> <span style="color: #009900;">&#123;</span> module<span style="color: #339933;">:</span> services  action<span style="color: #339933;">:</span> apply<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next we add this filter. Save this under MyProject/apps/MyApp/lib/sfSslFilter.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> sslFilter <span style="color: #000000; font-weight: bold;">extends</span> sfFilter
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
    * Execute filter
    *
    * @param FilterChain $filterChain The symfony filter chain
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> execute <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filterChain</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$ssl_actions</span> <span style="color: #339933;">=</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'app_ssl_secure_actions'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$allow_ssl</span> <span style="color: #339933;">=</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'app_ssl_ignore_non_secure'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isSecure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//Redirect to the Secure Url</span>
            <span style="color: #666666; font-style: italic;">//If the module and/or action match $ssl_actions set in app.yml</span>
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ssl_actions</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
&nbsp;
               <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'module'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">//The entire module needs to be secure</span>
                    <span style="color: #666666; font-style: italic;">//Redired no matter what the action is.</span>
&nbsp;
                    <span style="color: #000088;">$secure_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'https'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUri</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$secure_url</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">301</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
                <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'module'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$action</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActionName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">//Redirect if the module and action need to be secure</span>
&nbsp;
                    <span style="color: #000088;">$secure_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'https'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUri</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$secure_url</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">301</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
             <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isSecure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$allow_ssl</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$redirect</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//Redirect to the Non-Secure Url</span>
            <span style="color: #666666; font-style: italic;">//If the module and/or action are not in $ssl_actions set in app.yml</span>
            <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ssl_actions</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'module'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'module'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getModuleName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$action</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getActionName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$redirect</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$redirect</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                 <span style="color: #000088;">$non_secure_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'https'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUri</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redirect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$non_secure_url</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">301</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$filterChain</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally, add to the MyProject/apps/MyApp/config/filters.yml file:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">sslFilter<span style="color: #339933;">:</span>
  <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">:</span>  sslFilter</pre></div></div>

<p>Clear the cache <em>(symfony cc)</em>, and there you have it. Let me know if you have a better or different way of dealing with this on a per-module or per-action basis. Hopefully sfSslRequirementPlugin will get ported to work with Symfony 1.2, as the method above will not alter routes on your application.</p>
<p>Additionally, I specifically used 301 redirects to make this more search engine friendly, in case Google or another bot gets on a ssl page. This will help prevent getting duplicate pages indexed due to http and https versions of the same page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/symfony-1-2-redirect-specific-modules-and-actions-to-https-ssl/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>20 Great non-PHP Tools for PHP Developers</title>
		<link>http://www.saynotoflash.com/archives/20-great-non-php-tools-for-php-developers/</link>
		<comments>http://www.saynotoflash.com/archives/20-great-non-php-tools-for-php-developers/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 22:47:18 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=117</guid>
		<description><![CDATA[By nature I always strive to find more efficient, and better ways to perform tasks. There are a number of development tools that I use that really help me develop better applications in a reduced amount of time. These are the tools I use every day for web development. Cheat Sheets: 1.) DZone has created [...]]]></description>
			<content:encoded><![CDATA[<p>By nature I always strive to find more efficient, and better ways to perform tasks. There are a number of development tools that I use that really help me develop better applications in a reduced amount of time. These are the tools I use every day for web development.<br />
<span id="more-117"></span><br />
<h3>Cheat Sheets:</h3>
<p><strong>1.)</strong> DZone has created professional <a href="http://refcardz.dzone.com/">Cheat Sheets</a> for a number of PHP, and web development topics. These can save a ton of time from digging into a manual or doing a search online. These aren&#8217;t by any means the only cheat sheets out there, but you will find PHP, MySQL, XML, ASP, Java, Design Patterns, Joomla, and about 50 more easy to read, well designed cheat sheets.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/php-cheat.png" alt="php-cheat" title="php-cheat" width="550" height="440" class="aligncenter size-full wp-image-335" /></p>
<h3>IDE:</h3>
<p><strong>2.)</strong> <img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/NetBeans-sync.png" alt="NetBeans-sync" title="NetBeans-sync" width="300" height="86" class="alignleft size-full wp-image-336" /><a href="http://www.netbeans.org/">NetBeans</a> is an IDE that stands out above all others. It&#8217;s completely free. It offers a built-in FTP client <em>(Far superior to Dreamweaver)</em> or supports subversion publishing. It is very small, fast, and has many built-in features that help create better code, more efficiently. Netbeans is hands down the best IDE, with the fewest bugs (Not completely bug free), and virtually no learning curve (Try that Eclipse&#8230;), that I&#8217;ve used.</p>
<p>If you are holding on to Dreamweaver because of the FTP, or some other function that Eclipse PDE or Zend Studio is lacking, I urge you to take a look at Netbeans. When I&#8217;m not using SVN, I can save the file I&#8217;m working on and it is automatically uploaded to the web or testing server. Try it, you won&#8217;t be disappointed.</p>
<h3>Database Management:</h3>
<p><strong>3.)</strong> <a href="http://www.navicat.com/">Navicat</a> is by far the best database GUI, and my experience the best tool for database management on the market. Premiumsoft offers MySQL, PostgreSQL, Oracle versions, and now a single package that includes all three. Navicat provides an intelligent and efficient way to create, backup, and manage complex MySQL databases. It allows multiple methods of connecting, including a SSH tunnel, which protects your database from being accessed publicly. Apart from a good IDE, this is the #1 tool in my development toolbox. Navicat also offers a custom <a href="http://www.navicat.com/en/products/report_builder.html">report building application</a>, which can export data into Excel, Access, Text, XML, Lotus 123, or through an ODBC connection. This software is not free but they do offer a free 30 day trial. If you do a lot of database management, this software will probably pay for itself in time the first week you use it.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/navicat.png" alt="navicat" title="navicat" width="500" height="378" class="aligncenter size-full wp-image-315" /></p>
<p><strong>4.)</strong> <a href="http://www.webyog.com/">Monyog</a> is a fantastic real-time MySQL reporting program. It offers visual graphs of a database&#8217;s performance, and stats on just about everything that can be measured in MySQL. It is an excellent way to monitor a Database and is  indispensable for benchmarking and optimizing MySQL performance.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/monyog.png" alt="monyog" title="monyog" width="522" height="429" class="aligncenter size-full wp-image-328" /></p>
<p><strong>5.)</strong> <a href="http://dev.mysql.com/workbench/">MySQL Workbench</a> is a free MySQL development program which can create visual diagrams of a database&#8217;s structure, among many other features. This can be very important when you are working with large or just new databases. A picture can be worth much more than a thousand words when you are diving into a complex database.</p>
<p>Here&#8217;s a diagram of a moderately complex database, which could take a lot of time to understand without anything but the table structure.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/mysql-workbench-diagram.png" alt="mysql-workbench-diagram" title="mysql-workbench-diagram" width="500" height="171" class="aligncenter size-full wp-image-299" /></p>
<p><strong>6.)</strong> <a href="http://www.dpriver.com/pp/sqlformat.htm">SQL Code Formatter</a> is a quick tool that formats SQL code into an easy to read format. This tool can be indispensable when you are debugging other developers code, or trying to break-down a massive jumbled SQL statement.</p>
<p><strong>Turn junk like this:</strong><br />
SELECT users.id, users.name, users.address, billing.order_num, billing.subtotal, billing.shipping, billing.tax, SUM(billing.subtotal + billing.shipping + billing.tax) AS total FROM users LEFT JOIN billing ON users.id = billing.user_id WHERE billing.order_date &gt; &#8217;2009-07-31&#8242; AND billing.complete = &#8217;1&#8242;</p>
<p><strong>Into this <em>(example query may not make any sense)</em>:</strong><br />
[sql]<br />
SELECT users.id,<br />
       users.name,<br />
       users.address,<br />
       billing.order_num,<br />
       billing.subtotal,<br />
       billing.shipping,<br />
       billing.tax,<br />
       Sum(billing.subtotal + billing.shipping + billing.tax) AS total<br />
FROM   users<br />
       LEFT JOIN billing<br />
         ON users.id = billing.user_id<br />
WHERE  billing.order_date > &#8217;2009-07-31&#8242;<br />
       AND billing.complete = &#8217;1&#8242;<br />
[/sql]</p>
<h3>Debugging:</h3>
<p><strong>7.)</strong> <a href="http://users.skynet.be/mgueury/mozilla/">HTML Validator</a> is a Firefox Plugin that provides an instant status of a page&#8217;s w3c validation as you browse. It also replaces Firefox&#8217;s built-in source view, with an intuitive and significantly improved interface. This is one of the best tools out for quickly finding problems with a site&#8217;s (x)html structure.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/google-html.png" alt="google-html" title="google-html" width="510" height="551" class="aligncenter size-full wp-image-324" /></p>
<p><strong>8.)</strong> <a href="http://getfirebug.com/">Firebug</a> is an outstanding debugging program that provides a ton of information about structure, scripts, and problems. Firebug is an amazing tool, but can be quite complex, which is why I also use the HTML Validator plugin.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/firebug.png" alt="firebug" title="firebug" width="538" height="54" class="aligncenter size-full wp-image-325" /></p>
<h3>Version Control:</h3>
<p><strong>9.)</strong> <a href="http://www.git-scm.org/">Git</a> is a very fast version control system, that supports quick branching, merging, and development capabilities. There are a number of public GIT hosting sites such as <a href="http://github.com/">github</a> that allow developers to publish and collaborate on their projects.</p>
<blockquote><p>Git gives each developer a local copy of the entire development history, and changes are copied from one such repository to another. These changes are imported as additional development branches, and can be merged in the same way as a locally developed branch.</p></blockquote>
<p><strong>10.)</strong> <a href="http://subversion.tigris.org/">Subversion</a> or SVN is another version control system, ironically despised by the creator of GIT, but is very commonly used and should be in any programmers repertoire. It is currently one of the most popular version control methods, and works with just about any platform.</p>
<p><a href="http://www.dzone.com/links/git_vs_svn_comparsion.html">Quick comparison of GIT vs. SVN</a>.</p>
<p><strong>11.)</strong> <a href="http://winmerge.org/">WinMerge</a> is a fast file comparison program for Windows. It allows the user to quickly compare 2 files, and merge or edit as needed. This is by no means a version control method, but can quickly help determine differences between 2 documents.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/win-merge.png" alt="win-merge" title="win-merge" width="550" height="433" class="aligncenter size-full wp-image-323" /></p>
<h3>Graphics:</h3>
<p><strong>12.)</strong> <a href="http://www.colorzilla.com/">ColorZilla</a> is a very fast color picker plugin for Firefox. When you need to get a color from a website, ColorZilla is probably the quickest way to do it. Not only will it show the HEX color code, but it shows the RGB values, and exactly what element is using the color. If you ever take on an existing website for further development it can be invaluable in breaking down somebody&#8217;s poorly designed css stylesheets.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/color-zilla.png" alt="color-zilla" title="color-zilla" width="500" height="31" class="aligncenter size-full wp-image-310" /></p>
<p><strong>13.)</strong> <a href="http://colorschemedesigner.com/">Color Scheme Designer</a> is a no BS way to create compatible, attractive color schemes for websites, and user interfaces. There are dozens of color scheme generators out there, but this one does what is needed efficiently, for free, and without any extra fluff. Several pre-defined color patters are a click away, and you can see quick examples of a web page using the color schema that you&#8217;ve generated.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/color-schema-designer.png" alt="color-schema-designer" title="color-schema-designer" width="500" height="309" class="aligncenter size-full wp-image-307" /></p>
<h3>Communication:</h3>
<p><strong>14.)</strong> <img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/xlite1.png" alt="xlite" title="xlite" width="200" height="288" class="alignleft size-full wp-image-348" /><a href="http://www.counterpath.com/x-lite.html">X-Lite</a> is a free VOIP Softphone application. It offers all the features that a very advanced phone would have, including video. </p>
<p>In a world where many people have forgotten what a phone is, this is the perfect compromise. You can get a Plantronics headset and USB adapter, a low cost VOIP service, and have unlimited calling anywhere in the US, and possibly the world, as long as you have an internet connection. Don&#8217;t ignore the good old fashion telephone. Businesses still use these things&#8230;</p>
<p><strong>15.)</strong> <a href="http://www.ceruleanstudios.com/">Trillian</a> is a great way to combine all of your IM clients into a single, light-weight app. This program can free up a considerable amount of system resources compared to running multiple IM clients at the same time. It also lets you access all of your IM contacts through a single interface.</p>
<h3>Miscellaneous:</h3>
<p><strong>16.)</strong> <a href="http://www.screengrab.org/">ScreenGrab</a> is a screen capturing program that&#8217;s slightly better than the <strong>&#8220;Prnt Scrn&#8221;</strong> button on your keyboard. It can either copy or save a capture to a PNG file. It allows capturing a complete page <em>(including below the fold)</em>, only the visible portion of a screen, by selection, or the entire window. The only drawback is that it only works within Firefox. Any screen captures you see on this or my other blogs are done with ScreenGrab.</p>
<p><strong>17.)</strong> <img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/roboform.png" alt="roboform" title="roboform" width="300" height="215" class="alignright size-full wp-image-302" /><a href="http://www.roboform.com/php/land.php?affid=jeste&#038;frm=frame1">Roboform</a> is a username/password management program, and is the most important browser add-on that I use. I currently have over 2,000 website profiles stored in it <em>(One of many pages shown in the image)</em>, every one with a very secure and unique password like &#8220;<strong>fz96Dr%PpaZjaBfk</strong>&#8220;. </p>
<p>It supports a variety of very advanced features and configurations to help keep your login credentials secure and easy to use.</p>
<p>You can <a href="http://www.roboform.com/dist/affs/AiRoboForm-jeste.exe">download a free trial here</a>.</p>
<p><strong>18.)</strong> <img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/sun-vbox-150x150.png" alt="sun-vbox" title="sun-vbox" width="150" height="150" class="alignleft size-thumbnail wp-image-318" /><a href="http://www.virtualbox.org/">SUN Virtualbox</a> is the best virtual computer deployment package that I&#8217;ve come across. It installs on a number of host operating systems, not just Linux, and supports just about every OS on the market for Virtual Appliances. It is extremely easy to install, is very efficient, and can be customized as required. Virtual hosts can easily be backed up, or cloned and distributed.</p>
<p>If you&#8217;ve been afraid of exploring into Virtualization, I highly recommend looking at Virtualbox. There are so many benefits to this sort of technology, it&#8217;s something that every developer should be familiar with.</p>
<p><strong>19.)</strong> <a href="http://www.realtimesoft.com/ultramon/">Ultramon </a>is a multi-monitor taskbar program. unfortunately Windows XP does not include for multiple taskbars if you multiple monitors. Ultramon fixes this in a fast, predictable manner, and includes many additional features such as desktop back ground stretching. Ultramon is not free but is far superior to the free multi-taskbar products that are available.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/ultramon.png" alt="ultramon" title="ultramon" width="418" height="138" class="aligncenter size-full wp-image-342" /></p>
<p><strong>20.)</strong> <a href="http://sourceforge.net/projects/pdfcreator/">PDF Creator</a> is a PDF printing application. It allows printing any file directly into a PDF. If you don&#8217;t need the ability to edit existing PDF documents, this is an excellent alternative to purchasing any other PDF software.</p>
<p><img src="http://www.saynotoflash.com/wp-content/uploads/2009/08/pdf-creator.png" alt="pdf-creator" title="pdf-creator" width="439" height="402" class="aligncenter size-full wp-image-339" /></p>
<p>Let me know if you&#8217;ve got your own set of essential tools that help in your development.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/20-great-non-php-tools-for-php-developers/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>PHP Magic __get, __set Methods, and Retaining Private and Protected Properties</title>
		<link>http://www.saynotoflash.com/archives/php-magic-__get-__set-methods-and-retaining-private-and-protected-properties/</link>
		<comments>http://www.saynotoflash.com/archives/php-magic-__get-__set-methods-and-retaining-private-and-protected-properties/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 08:00:03 +0000</pubDate>
		<dc:creator>jestep</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.saynotoflash.com/?p=272</guid>
		<description><![CDATA[I have been making an integration with a complex API with hundreds of potential user provided variables, necessitating me use of PHP&#8217;s Magic __get and __set methods. Unfortunately, by using these methods, PHP&#8217;s restriction on private and protected properties is bypassed, making all properties public. This is completely unacceptable from my coding perspective. This class [...]]]></description>
			<content:encoded><![CDATA[<p>I have been making an integration with a complex API with hundreds of potential user provided variables, necessitating me use of PHP&#8217;s <a href="http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members">Magic __get and __set methods</a>. </p>
<p>Unfortunately, by using these methods, PHP&#8217;s restriction on private and protected properties is bypassed, making all properties public. This is completely unacceptable from my coding perspective. </p>
<p>This class model overrides the magic __get and __set&#8217;s ability to alter and access private and protected properties. Public properties are unaffected. This script also allows the class to set and access private and protected properties.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> setter_getter_respect 
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$current_page</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$private_properties</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000088;">$class</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$class</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFileName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$class_properties</span> <span style="color: #339933;">=</span> <span style="color: #990000;">get_class_vars</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$class_properties</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$class_property_name</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$property_value</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$prop</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionProperty<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">,</span> <span style="color: #000088;">$class_property_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$prop</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isPrivate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$prop</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isProtected</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">private_properties</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$prop</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$prop</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isPrivate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'private'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'protected'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$requesting_page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">debug_backtrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$requesting_page</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_page</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">private_properties</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
&nbsp;
        	<span style="color: #990000;">trigger_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cannot access &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">private_properties</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; property &quot;</span><span style="color: #339933;">.</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;::&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; in &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$requesting_page</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;on line &quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$requesting_page</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000088;">$requesting_page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">debug_backtrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$requesting_page</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_page</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">private_properties</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #990000;">trigger_error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cannot access &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">private_properties</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; property &quot;</span><span style="color: #339933;">.</span><span style="color: #009900; font-weight: bold;">__CLASS__</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;::&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; in &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$requesting_page</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;on line &quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$requesting_page</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Required property [&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$var</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;] has not been set!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Extended classes will not have access to __get or __set protected properties. I will alter this snippet when I find a suitable method of handling extended classes.</p>
<p>I&#8217;m hoping that php alters the way it handles private and protected properties through the magic methods but until then, this is a way to semi-preserve private and protected properties.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.saynotoflash.com/archives/php-magic-__get-__set-methods-and-retaining-private-and-protected-properties/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

