<?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>Oli&#039;s 2 cents</title>
	<atom:link href="http://www.oelerich.org/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.oelerich.org</link>
	<description>webdevelopment, physics &#039;n&#039; stuff</description>
	<lastBuildDate>Sat, 21 Aug 2010 19:51:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Doctrine 2 Beta 1 ins Zend Framework 1.10 integrieren</title>
		<link>http://www.oelerich.org/?p=285</link>
		<comments>http://www.oelerich.org/?p=285#comments</comments>
		<pubDate>Sat, 21 Aug 2010 19:49:39 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[doctrine 2]]></category>
		<category><![CDATA[zf-doctrine-integrator]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=285</guid>
		<description><![CDATA[Update 21.08.2010 &#8211; Ich habe soeben ein Update für die neuste Doctrine Beta hochgeladen! Sooo. Einige Leser hatten mich gefragt, wann ich meine Zend Framework Integrations-Anleitung denn auf die Beta 1 von Doctrine updaten würde. Das mache ich in den nächsten Tagen noch, sobald ich Zeit finde. Heute habe ich allerdings schon ein kleines Projekt [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 21.08.2010 &#8211; Ich habe soeben ein Update für die neuste Doctrine Beta hochgeladen!</strong></p>
<p>Sooo. Einige Leser hatten mich gefragt, wann ich meine <a href="http://framework.zend.com">Zend Framework</a> Integrations-Anleitung denn auf die <strong>Beta 1</strong> von <a href="http://www.doctrine-project.com">Doctrine</a> updaten würde.</p>
<p>Das mache ich in den nächsten Tagen noch, sobald ich Zeit finde. Heute habe ich allerdings schon ein kleines Projekt gestartet: Den <a href="http://code.google.com/p/zf-doctrine-integrator">zf-doctrine-integrator</a> (<strong>Zend Framework Doctrine Integrator</strong>). </p>
<p>Prinzipiell besteht das ganze Projekt, welches derzeit auf <a href="http://code.google.com">google code</a> gehostet ist, aus einem <strong>Shellscript</strong> und den nötigen Dateien zur <strong>Integration von Doctrine 2 Beta 1 ins Zend Framework 1.10</strong>. Das Shellscript erstellt euch automatisch ein Projekt mit den ZF und Doctrine Bibliotheken, lädt die nötigen Dateien zur Integration aus dem Repository herunter und erstellt automatisch eine vhost Datei. </p>
<p>Das erspart euch bei der Projekterstellung die Arbeit, den Code zur Integration aus alten Projekten oder irgendwelchen Tutorials zu kopieren, außerdem könnt ihr so sicher stellen, immer die<strong> aktuellsten</strong> ZF und Doctrine Versionen zu nutzen.</p>
<p>Das ganze ist mehr oder weniger überhaupt nicht getestet. Ich würde mich sehr freuen, wenn ihr einfach mal ausprobiert, ob das tool bei euch läuft. <a href="http://code.google.com/p/zf-doctrine-integrator/issues/list">Issues</a> könnt ihr auf der Projektseite direkt posten. Die <a href="http://code.google.com/p/zf-doctrine-integrator/wiki/Systemvoraussetzungen">Systemvoraussetzungen</a> und eine (in Zukunft) ausführliche Dokumentation findet ihr im <a href="http://code.google.com/p/zf-doctrine-integrator/w/list">Wiki</a>.</p>
<ul>
<li><a href="http://code.google.com/p/zf-doctrine-integrator/">zum Projekt</a></li>
<li><a href="http://code.google.com/p/zf-doctrine-integrator/downloads/list">zum Download des Shell Scripts</a></li>
<li><a href="http://code.google.com/p/zf-doctrine-integrator/wiki/Systemvoraussetzungen">Systemvoraussetzungen</a></li>
<li><a href="http://code.google.com/p/zf-doctrine-integrator/wiki/Bedienungsanleitung">Bedienungsanleitung</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=285</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Quicktipp: Weiße Schrift bei Gnuplots epslatex Terminal</title>
		<link>http://www.oelerich.org/?p=298</link>
		<comments>http://www.oelerich.org/?p=298#comments</comments>
		<pubDate>Fri, 02 Jul 2010 13:56:59 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[epslatex]]></category>
		<category><![CDATA[gnuplot]]></category>
		<category><![CDATA[quicktipp]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=298</guid>
		<description><![CDATA[Ich habe eben entdeckt, dass die Titel meiner Datenreihen in weißer Schrift auf weißem Grund dargestellt wurden, beim kompilieren des Tex Files, was das epslatex Terminal von Gnuplot produziert. Ich habe &#8220;latex file.tex; dvips file.dvi; pstopdf file.ps&#8221; gemacht um am Ende meine PDF rauszukriegen. Wenn ich statt den Weg über die Postscript Datei zu machen, [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe eben entdeckt, dass die Titel meiner Datenreihen in weißer Schrift auf weißem Grund dargestellt wurden, beim kompilieren des Tex Files, was das epslatex Terminal von Gnuplot produziert. Ich habe &#8220;<em>latex file.tex; dvips file.dvi; pstopdf file.ps</em>&#8221; gemacht um am Ende meine PDF rauszukriegen.</p>
<p>Wenn ich statt den Weg über die Postscript Datei zu machen, direkt <strong>dvipdf</strong> verwende, läuft alles.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=298</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quicktipp: Gnuplot und Latex&#8230; Der ewige Kampf</title>
		<link>http://www.oelerich.org/?p=293</link>
		<comments>http://www.oelerich.org/?p=293#comments</comments>
		<pubDate>Thu, 01 Jul 2010 18:06:18 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[epslatex]]></category>
		<category><![CDATA[gnuplot]]></category>
		<category><![CDATA[latex]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=293</guid>
		<description><![CDATA[Eigentlich gibt es viele Wege, Gnuplot Grafiken ordentlich in Latex Dokumente einzubinden. Aber alle sind irgendwie doof. Besonders, wenn man pdflatex verwendet, kann es schwierig werden, da Gnuplot lieber mit postscript Formaten hantiert. Mein Ziel war es, alle Beschriftungen in der Schriftart meines Dokumentes zu haben, den Graphen aber in einer gesonderten PDF Datei. Das [...]]]></description>
			<content:encoded><![CDATA[<p>Eigentlich gibt es viele Wege, <strong>Gnuplot</strong> Grafiken ordentlich in <strong>Latex</strong> Dokumente einzubinden. Aber alle sind irgendwie doof. Besonders, wenn man <strong>pdflatex</strong> verwendet, kann es schwierig werden, da Gnuplot lieber mit postscript Formaten hantiert. </p>
<p>Mein Ziel war es, alle Beschriftungen in der Schriftart meines Dokumentes zu haben, den Graphen aber in einer gesonderten PDF Datei.  Das hab ich durch ein simples Shell script und die vielen Tools geschafft, die Latex mitbringt.<span id="more-293"></span></p>
<p>Gelöst hab ich es so: </p>
<ol>
<li>Mit dem Terminal <em>epslatex</em> und der Option <em>standalone</em> von Gnuplot eine Latex Datei erstellen lassen, welche ein gleichzeitig erstelltes eps Bild vom Graphen einbindet. Die Beschriftungen sind im Latex File als Text</li>
<li>Mit latex die<em> .tex</em> Datei in ein <em>.dvi </em>File übersetzen</li>
<li>Anschließend noch <em>dvips</em> und <em>pstopdf</em> anwenden, und fertig ist das Bild</li>
</ol>
<p>Schwierigkeiten gabs eigentlich nur dabei, aus dem Gnuplot file automatisch den Namen der Ausgabedatei herauszuholen, aber auch das hab ich dann hinbekommen.</p>
<p>Hier das Shellscript:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> temp
<span style="color: #c20cb9; font-weight: bold;">cp</span> $<span style="color: #000000;">1</span> .<span style="color: #000000; font-weight: bold;">/</span>temp
<span style="color: #7a0874; font-weight: bold;">cd</span> temp
<span style="color: #007800;">value</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'set output'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span><span style="color: #ff0000;">'&quot;'</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">`</span>
gnuplot $<span style="color: #000000;">1</span>
latex <span style="color: #007800;">$value</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
dvips <span style="color: #000000; font-weight: bold;">*</span>.dvi <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
pstopdf <span style="color: #000000; font-weight: bold;">*</span>.ps <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">*</span>.pdf ..<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;PDF created&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> .<span style="color: #000000; font-weight: bold;">/</span>temp</pre></div></div>

<p>In der Gnuplot Datei, welche als Argument an das Script übergeben wird, braucht man jetzt nur noch folgendermaßen das Terminal und den Output festlegen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> terminal epslatex color standalone
<span style="color: #000000; font-weight: bold;">set</span> output <span style="color: #ff0000;">&quot;output.tex&quot;</span></pre></div></div>

<p>Drauf achten, dass das Shell script doppelte Anführungszeichen bei set output erwartet.<br />
Voraussetzung sind natürlich all die Tools, die das Script aufruft. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=293</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netbeans 6.9 erschienen &#8211; ZF support!</title>
		<link>http://www.oelerich.org/?p=290</link>
		<comments>http://www.oelerich.org/?p=290#comments</comments>
		<pubDate>Wed, 16 Jun 2010 09:50:34 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[netbeans 6.9]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=290</guid>
		<description><![CDATA[Da gibts solange keinen Beitrag von mir, und dann wirds nur so ein kurzer; Sorry! Trotzdem muss hier mal erwähnt werden, dass meine lieblings-IDE NetBeans in der Version 6.9 erschienen ist. Eingebaut wurde u.a. Support fürs Zend Framework. Getestet hab ichs noch nicht, obwohl ich seit der ersten Beta alle Versionen direkt installiert habe. Wer [...]]]></description>
			<content:encoded><![CDATA[<p>Da gibts solange keinen Beitrag von mir, und dann wirds nur so ein kurzer; Sorry! Trotzdem muss hier mal erwähnt werden, dass meine <a href="http://www.netbeans.com/">lieblings-IDE NetBeans in der Version 6.9</a> erschienen ist. Eingebaut wurde u.a. Support fürs Zend Framework. Getestet hab ichs noch nicht, obwohl ich seit der ersten Beta alle Versionen direkt installiert habe. </p>
<p>Wer NetBeans noch nicht kennt, sollte sich die IDE unbedingt mal ansehen. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=290</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doctrine 2 Beta 1</title>
		<link>http://www.oelerich.org/?p=278</link>
		<comments>http://www.oelerich.org/?p=278#comments</comments>
		<pubDate>Wed, 28 Apr 2010 07:11:27 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[doctrine 2]]></category>
		<category><![CDATA[doctrine 2 beta 1]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=278</guid>
		<description><![CDATA[Da haben sie es doch endlich geschafft, die Beta 1 vom Doctrine ORM 2 zu releasen, mit gut 1-2 Monaten Verspätung. Naja. Ich werde am Wochenende in einem Projekt Doctrine updaten, und als Nebenprodukt fällt dann wohl eine Aktualisierung meiner Zend Framework Integrationsanleitung ab. Ich habe irgendwann übrigens angefangen, ein Shellscript zu schreiben, das die [...]]]></description>
			<content:encoded><![CDATA[<p>Da haben sie es doch endlich geschafft, die Beta 1 vom <a href="http://www.doctrine-project.com">Doctrine ORM 2</a> zu releasen, mit gut 1-2 Monaten Verspätung. Naja. Ich werde am Wochenende in einem Projekt Doctrine updaten, und als Nebenprodukt fällt dann wohl eine Aktualisierung meiner <a href="http://framework.zend.com">Zend Framework</a> Integrationsanleitung ab.</p>
<p>Ich habe irgendwann übrigens angefangen, ein Shellscript zu schreiben, das die jeweils aktuellste Version des Zend Frameworks und von Doctrine aus den Repositories herunterlädt, in die passenden Verzeichnisse kopiert und anschließend die erforderlichen Dateien zur Integration von Doctrine ins ZF aus einem google code Projekt holt. So eine Art <strong>Zend Framework + Doctrine Application creator</strong>. Vielleicht kommt da bald mal was zum Testen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=278</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Captcha_Image unsicher&#8230;</title>
		<link>http://www.oelerich.org/?p=266</link>
		<comments>http://www.oelerich.org/?p=266#comments</comments>
		<pubDate>Thu, 08 Apr 2010 13:29:45 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[Zend_Captcha_Image]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=266</guid>
		<description><![CDATA[Gestern habe ich das erste mal überhaupt ein Captcha einbinden müssen, und habe (natürlich) den Zend_Captcha Adapter verwendet. Das Implementieren von Zend_Captcha_Image war recht einfach und das Ergebnis sah auch gar nicht übel aus &#8211; ungefähr so: Nunja, heute morgen hatten sich zwei neue Spambots registriert. Das hat mich sehr geärgert, sollte so ein Feature [...]]]></description>
			<content:encoded><![CDATA[<p>Gestern habe ich das erste mal überhaupt ein Captcha einbinden müssen, und habe (natürlich) den Zend_Captcha Adapter verwendet. Das Implementieren von Zend_Captcha_Image war recht einfach und das Ergebnis sah auch gar nicht übel aus &#8211; ungefähr so:<br />
<img src="http://www.oelerich.org/wp-content/uploads/2010/04/captcha.png" alt="" title="captcha" width="180" height="50" class="aligncenter size-full wp-image-267" /><br />
Nunja, heute morgen hatten sich zwei neue Spambots registriert. Das hat mich sehr geärgert, sollte so ein Feature des Zend Frameworks doch wenigstens ordentlich funktionieren.<br />
<span id="more-266"></span><br />
Einen kleinen Workaround habe ich eingebaut, den poste ich gleich noch. Das Captcha Wort wird rückwärts abgefragt. Die Info, dass es auch rückwärts eingegeben werden muss, sollte natürlich gut sichtbar und zur Sicherheit als Bild vorhanden sein. </p>
<p>Hier nun mein Form-Element welches den Captcha Input umdreht sowie der zugehörige Filter:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'captcha'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'captcha'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'captcha'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'captcha'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Image'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'filters'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> StringReverse<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> StringReverse implements Zend_Filter_Interface
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> filter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$value</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'input'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strrev</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'input'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=266</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doctrine 2 &#8211; Speichern von Verknüpfungen</title>
		<link>http://www.oelerich.org/?p=259</link>
		<comments>http://www.oelerich.org/?p=259#comments</comments>
		<pubDate>Mon, 22 Mar 2010 19:39:09 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[doctrine 2]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=259</guid>
		<description><![CDATA[Im Moment das heißeste Thema hier im Blog (wenn &#8220;heiß&#8221; auch stark übertrieben wäre), ist noch immer Doctrine 2. Ich hatte mich vor einiger Zeit entschieden, die neue Version des Propel-Konkurrenten für ein Projekt zu verwenden. Zwar befindet sich die Software noch im alpha Stadium, (die Beta wird laut der aktualisierten Roadmap mit zwei Wochen [...]]]></description>
			<content:encoded><![CDATA[<p>Im Moment das heißeste Thema hier im Blog (wenn &#8220;heiß&#8221; auch stark übertrieben wäre), ist noch immer <a href="http://www.doctrine-project.org">Doctrine 2</a>. Ich hatte mich vor einiger Zeit entschieden, die neue Version des Propel-Konkurrenten für ein Projekt zu verwenden. Zwar befindet sich die Software noch im alpha Stadium, (die Beta wird laut der aktualisierten Roadmap mit zwei Wochen Verspätung erscheinen) ich konnte bisher aber keine Bugs feststellen &#8211; lediglich einige Verbesserungswünsche und Unzulänglichkeiten. </p>
<p>Eine davon möchte ich hier besprechen.<br />
<span id="more-259"></span><br />
Ich habe in dem besagten Projekt eine Menge Formulare, die eine Menge Tabellen füllen, die mit einer Menge Verknüpfungen versehen sind. Beim Abschicken eines Formulares, übermittele ich lediglich die ID, wenn ich eine 1:1 oder 1:n Beziehung festlegen will.<br />
Bevor mein Model in der Datenbank gespeichert wird, wird jedes Feld der Tabelle lediglich durch eine Klassenvariable repräsentiert. Mein Wunsch: Ich speichere die ID in der Variable, der EntityManager erkennt das, kennt außerdem die Verknüpfung, zählt 1 und 1 zusammen und speichert die ID in der Tabelle. Dazu kann er mir gleich das zugehörige Model liefern. Leider klappt das nicht. Der EntityManager will ein Objekt in der Variable haben, schnappt sich dessen ID und speichert diese dann.<br />
Eine elegante Lösung habe ich bisher nicht gefunden, ohne am EntityManager rumzuwerkeln. </p>
<p>Hier trotzdem mal mein Ansatz:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * @Entity
 * @Table(name=&quot;model1&quot;)
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> Model1 <span style="color: #000000; font-weight: bold;">extends</span> BaseModel
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * @Column(name=&quot;id&quot;, type=&quot;integer&quot;)
     * @Id
     * @GeneratedValue(strategy=&quot;AUTO&quot;)
     */</span>
    protected <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @Column(name=&quot;name&quot;, type=&quot;string&quot;, length=255)
     */</span>
    protected <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @OneToOne(targetEntity=&quot;Model2&quot;)
     * @JoinColumns({
     *   @JoinColumn(name=&quot;model2_id&quot;, referencedColumnName=&quot;id&quot;, nullable=false)
     * })
     */</span>
    protected <span style="color: #000088;">$model2</span><span style="color: #339933;">;</span>
&nbsp;
    protected <span style="color: #000088;">$relationClasses</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'model2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Model2'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ein stinknormales Doctrine Model mit einer Verknüpfung zu <strong>Model2</strong>. Allerdings fällt euch sicher auf, dass die Klasse von einer <strong>BaseModel</strong> erbt. Außerdem gibt es die Variable <em>$relationClasses</em>, in welcher zu jeder Verknüpfung der Klassenname gesichert ist. </p>
<p>Meine Idee ist folgende: In der <strong>BaseModel</strong> gibt es eine <strong>from()</strong> Methode, welche ein Array mit Werten für das Entity akzeptiert. Stößt die Methode auf einen Arrayschlüssel, welcher auch in <em>$relationClasses</em> existiert, wird eine Instanz der zu verknüpfenden Klasse erstellt und statt der ID in der Variablen gesichert.</p>
<p>Die aktuelle BaseModel.php gibts eben auch noch, schauts euch selbst an:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/** @MappedSuperclass */</span>
<span style="color: #000000; font-weight: bold;">class</span> BaseModel <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * just in case...
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'this is not a string!!!'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * magic method which processes getFieldName() and setFieldName($value)
     * setFieldName() returns the object
     *
     * @param string $method
     * @param array $args
     * @return mixed
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</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: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'get'</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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</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;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'set'</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>property_exists<span style="color: #009900;">&#40;</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</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: #009933; font-style: italic;">/**
     * transforms getCamelCaseFieldName to camelCaseFieldName
     *
     * @param string $methodname
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$methodname</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> lcfirst<span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$methodname</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</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: #009933; font-style: italic;">/**
     * fetches all rows of the database table
     * @return collection
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getAll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<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;">;</span>
        <span style="color: #000088;">$em</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$registry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entitymanager</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$em</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRepository</span><span style="color: #009900;">&#40;</span>get_called_class<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * finds the row with id $id. If it doesn't exist and $create is true,
     * it creates the object and returns it
     *
     * @param int $id
     * @param boolean $create
     * @return entityname
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> find<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$create</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$entityname</span> <span style="color: #339933;">=</span> get_called_class<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<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;">;</span>
        <span style="color: #000088;">$em</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$registry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entitymanager</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$match</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$em</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRepository</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entityname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$match</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$create</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$entityname</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * populates the object with values from $array, if it's keys are
     * valid table fields.
     *
     * @param array $array
     * @return $this
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> from<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</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;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</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: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">==</span>  <span style="color: #0000ff;">'NULL'</span> <span style="color: #339933;">||</span> <span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$setter</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'set'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">ucfirst</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <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: #004000;">relationClasses</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</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;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #990000;">call_user_func</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">relationClasses</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'::find'</span><span style="color: #339933;">,</span><span style="color: #000088;">$value</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: #000088;">$setter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$setter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=259</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gewinnen bei php hates me</title>
		<link>http://www.oelerich.org/?p=256</link>
		<comments>http://www.oelerich.org/?p=256#comments</comments>
		<pubDate>Mon, 22 Feb 2010 14:41:50 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[phphatesme]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=256</guid>
		<description><![CDATA[Mit dem Post hier nehme ich an dem Gewinnspiel von PHP hates me teil. Da es um Geschwindigkeit geht, spare ich mir jetzt einen sinnvollen Artikel darüber. Ich will ja das Zend Framework Poster bekommen!]]></description>
			<content:encoded><![CDATA[<p>Mit dem Post hier nehme ich an dem <a href="http://www.phphatesme.com/blog/allgemein/das-gewinnspiel-geht-los/trackback/">Gewinnspiel von PHP hates me</a> teil. Da es um Geschwindigkeit geht, spare ich mir jetzt einen sinnvollen Artikel darüber. Ich will ja das Zend Framework Poster bekommen!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=256</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Meine Superclass für Doctrine 2 Models</title>
		<link>http://www.oelerich.org/?p=249</link>
		<comments>http://www.oelerich.org/?p=249#comments</comments>
		<pubDate>Mon, 22 Feb 2010 09:03:56 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[doctrine 2]]></category>
		<category><![CDATA[Superclass]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=249</guid>
		<description><![CDATA[In einem neuen Projekt möchte ich gern Doctrine 2 verwenden, und habe schonmal etwas vorgearbeitet und mir eine Superclass für die Models erstellt. Doctrine 2 lässt es zu, Models von solch einer Superclass erben zu lassen, in welcher man beispielsweise Felder festlegen kann, die in jedem Model zur Verfügung stehen sollen. Meine Superclass füllt ein [...]]]></description>
			<content:encoded><![CDATA[<p>In einem neuen Projekt möchte ich gern Doctrine 2 verwenden, und habe schonmal etwas vorgearbeitet und mir eine Superclass für die Models erstellt. Doctrine 2 lässt es zu, Models von solch einer Superclass erben zu lassen, in welcher man beispielsweise Felder festlegen kann, die in jedem Model zur Verfügung stehen sollen. </p>
<p>Meine Superclass füllt ein paar Funktionslücken und ist mit folgenden nützlichen Methoden ausgestattet:</p>
<ul>
<li>Definiert die Felder <strong>created</strong> und <strong>updated</strong> (jeweils <em>DateTime</em>) und füllt sie entsprechend beim Erstellen und Updaten des Objektes. Wie in Doctrine 1: &#8220;act as timestampable&#8221;</li>
<li>Bietet eine <strong>Model::find($id)</strong> Methode, welche die gefundene Row oder sonst &#8220;null&#8221; zurückgibt. Wird <strong>Model::find($id, true)</strong> aufgerufen, wird ein neues Objekt erstellt und zurückgegeben, wenn $id nicht gefunden wurde. Nützlich, um zum Beispiel die Funktionen zum Erstellen und Bearbeiten von Zeilen nicht doppelt implementieren zu müssen</li>
<li><strong>$obj->from($array)</strong> erwartet ein array(&#8216;feldname&#8217;=>&#8217;neuer wert&#8217;,&#8230;) und füllt die Felder des Objektes entsprechend. Nützlich um viele Werte gleichzeitig zu setzen.</li>
<li><strong>$obj->getFieldName()</strong> und <strong>$obj->setFieldName($value)</strong> geben den Wert von field_name zurück, bzw. setzen ihn. Die setter Methode gibt das Objekt zurück, sodass Methodchaining à la <strong>$obj->setField1($val1)->setField2($val)</strong>&#8230; möglich ist. Die setter und getter unterstützen CamelCase. getCamelCaseString würde das Feld camel_case_string zurückgeben.</li>
</ul>
<p>Anwendung ist ganz einfach; <strong>class My_Model extends Model_Base {}</strong>. Außerdem muss in der Zend_Registry der EntityManager von Doctrine abgelegt werden, sodass</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<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;">;</span>
<span style="color: #000088;">$em</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$registry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entitymanager</span><span style="color: #339933;">;</span></pre></div></div>

<p>diesen holen kann! Das ginge auch über eine globale Variable oder sowas.</p>
<p>Hier endlich die Klasse zum Kopieren und Spielen:<br />
<span id="more-249"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/** @MappedSuperclass */</span>
<span style="color: #000000; font-weight: bold;">class</span> Model_Base <span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * @Column(type=&quot;datetime&quot;)
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$created</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @Column(type=&quot;datetime&quot;)
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$updated</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * set the updated and created fields to &quot;now&quot;
     */</span>
    <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>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">created</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updated</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DateTime<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;now&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @PreUpdate
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> updated<span style="color: #009900;">&#40;</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;">updated</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DateTime<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;now&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * just in case...
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'this is not a string!!!'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * magic method which processes getFieldName() and setFieldName($value)
     * setFieldName() returns the object
     *
     * @param string $method
     * @param array $args
     * @return mixed
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __call<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</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: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'get'</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: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</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;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'set'</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>property_exists<span style="color: #009900;">&#40;</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</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: #009933; font-style: italic;">/**
     * transforms getCamelCaseFieldName to camel_case_field_name
     *
     * @param string $methodname
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _getFieldName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$methodname</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$return</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/([A-Z])/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'_$1'</span><span style="color: #339933;">,</span><span style="color: #000088;">$methodname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$return</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</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: #009933; font-style: italic;">/**
     * fetches all rows of the database table
     * @return collection
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getAll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<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;">;</span>
        <span style="color: #000088;">$em</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$registry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entitymanager</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$em</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRepository</span><span style="color: #009900;">&#40;</span>get_called_class<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * finds the row with id $id. If it doesn't exist and $create is true,
     * it creates the object and returns it
     *
     * @param int $id
     * @param boolean $create
     * @return entityname
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> find<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$create</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$entityname</span> <span style="color: #339933;">=</span> get_called_class<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$registry</span> <span style="color: #339933;">=</span> Zend_Registry<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;">;</span>
        <span style="color: #000088;">$em</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$registry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entitymanager</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$match</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$em</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRepository</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entityname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$match</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$create</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$entityname</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * populates the object with values from $array, if it's keys are
     * valid table fields.
     *
     * @param array $array
     * @return $this
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> from<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</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;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$field</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>property_exists<span style="color: #009900;">&#40;</span><span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=249</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>So arbeiten also Hacker?</title>
		<link>http://www.oelerich.org/?p=246</link>
		<comments>http://www.oelerich.org/?p=246#comments</comments>
		<pubDate>Wed, 10 Feb 2010 15:52:14 +0000</pubDate>
		<dc:creator>Oli</dc:creator>
				<category><![CDATA[Allgemeines]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[hacker]]></category>

		<guid isPermaLink="false">http://www.oelerich.org/?p=246</guid>
		<description><![CDATA[Ich bin eben über heise security auf ein sehr nettes Video gestolpert, in welchem Chris Tarnovsky zeigt, wie er die Chips auf Sat-TV Smartcards geknackt hat: Hack a Sat-TV Smart Card Und ich dachte immer, zum Hacken reicht eine Shell mit Internetzugang&#8230;]]></description>
			<content:encoded><![CDATA[<p>Ich bin eben über <a href="http://www.heise.de/newsticker/meldung/Hacker-liest-Kryptoschluessel-aus-TPM-Chip-aus-926883.html">heise security</a> auf ein sehr nettes Video gestolpert, in welchem <strong>Chris Tarnovsky</strong> zeigt, wie er die Chips auf Sat-TV Smartcards geknackt hat: <a href="http://www.wired.com/video/hack-a-sattv-smart-card/1813637610">Hack a Sat-TV Smart Card</a></p>
<p>Und ich dachte immer, zum Hacken reicht eine Shell mit Internetzugang&#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://www.oelerich.org/?feed=rss2&amp;p=246</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
