<?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>php Archives - WATA Factory</title>
	<atom:link href="https://wata.es/de/tag/php-de/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Softwareentwicklung und KI</description>
	<lastBuildDate>Wed, 12 Mar 2025 08:00:00 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.5</generator>

<image>
	<url>https://wata.es/wp-content/uploads/2026/11/cropped-favicon-32x32.jpeg</url>
	<title>php Archives - WATA Factory</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>PHP und WordPress: Was du wissen musst (auch wenn du kein Entwickler bist)</title>
		<link>https://wata.es/de/php-und-wordpress-was-du-wissen-musst-auch-wenn-du-kein-entwickler-bist/</link>
		
		<dc:creator><![CDATA[Ralf Tenbrink]]></dc:creator>
		<pubDate>Wed, 12 Mar 2025 08:00:00 +0000</pubDate>
				<category><![CDATA[Neuigkeiten]]></category>
		<category><![CDATA[Technologie]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">https://wata.es/?p=11382</guid>

					<description><![CDATA[<p>Hey there, I’m one of the WordPress and PHP enthusiasts at WATA Factory. Over the years, I’ve watched WordPress evolve from a simple blogging platform into a powerhouse that can handle e-commerce sites, membership portals, media repositories, and so much more. If you’re curious about how WordPress works behind the scenes—or maybe you’re a designer [&#8230;]</p>
<p>The post <a href="https://wata.es/de/php-und-wordpress-was-du-wissen-musst-auch-wenn-du-kein-entwickler-bist/">PHP und WordPress: Was du wissen musst (auch wenn du kein Entwickler bist)</a> appeared first on <a href="https://wata.es/de/">WATA Factory</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Hey there, I’m one of the WordPress and PHP enthusiasts at WATA Factory. Over the years, I’ve watched WordPress evolve from a simple blogging platform into a powerhouse that can handle e-commerce sites, membership portals, media repositories, and so much more. If you’re curious about how WordPress works behind the scenes—or maybe you’re a designer or content manager wanting to flex your technical muscles—this post is for you!</p>

<span id="more-11382"></span>

<p class="wp-block-paragraph">In this article, I’ll walk you through why PHP is such a big deal in WordPress, how understanding the basics can help you (even if you’re not coding full-time), and offer some easy-to-grasp examples that’ll hopefully spark your interest in digging a little deeper. I’ll also sprinkle in a few handy links to some of our other blog posts on related topics so you can continue your learning journey. Let’s get started!</p>

<h2 class="wp-block-heading">1. A Quick Refresher: What’s WordPress?</h2>

<p class="wp-block-paragraph">WordPress is often described as a Content Management System (CMS). Essentially, it’s software that makes it easy to build and manage websites without needing a PhD in Computer Science. You can choose from thousands of themes, install plugins for practically any feature under the sun, and create pages and posts with minimal fuss.</p>

<ul class="wp-block-list">
<li><strong>For designers</strong>: This means you can focus on aesthetics, typography, and layout without wrestling with raw code day in and day out.</li>



<li><strong>For content managers</strong>: It means you can upload and schedule content effortlessly, keep track of your SEO best practices, and handle user permissions without getting lost in the weeds of database queries.</li>
</ul>

<p class="wp-block-paragraph">But behind all these user-friendly features is a powerful programming language called <strong>PHP</strong>. This is where things get interesting.</p>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<h2 class="wp-block-heading">2. PHP in a Nutshell</h2>

<p class="wp-block-paragraph">PHP (Hypertext Preprocessor) is a popular scripting language primarily used in web development. Think of it like the “brains” that process user requests, query databases, and determine what content to serve up in your browser.</p>

<h3 class="wp-block-heading">Why PHP Matters</h3>

<ul class="wp-block-list">
<li><strong>Server-Side Execution</strong>: While JavaScript usually runs in your browser, PHP does its work on the server. This means tasks like processing form submissions, interacting with databases, or generating dynamic content happen before the page even reaches your computer.</li>



<li><strong>Wide Adoption</strong>: PHP powers a significant portion of the web—WordPress being one of its most famous success stories. Its large community means it’s well-documented, regularly updated, and has a wide ecosystem of tools and frameworks.</li>



<li><strong>Easy to Learn, Hard to Master</strong>: PHP has a reputation for being relatively easy to pick up. However, truly mastering it (especially with modern frameworks and best practices) can take years.</li>
</ul>

<p class="wp-block-paragraph">At WATA Factory, we work on a broad range of PHP-based projects, from WordPress websites to custom applications using frameworks like Symfony and Laravel. If you’re curious about how we tackle modernization of older PHP projects, we’ve covered that in a <a href="https://wata.es/de/modernisierung-von-php-legacy-projekten-durch-symfony/">blog post about modernizing </a><a href="https://wata.es/de/modernisierung-von-php-legacy-projekten-durch-symfony/">PHP legacy projects with Symfony</a>—you can see how these different tools and frameworks all tie together in the broader PHP ecosystem.</p>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<h2 class="wp-block-heading">3. How PHP Powers WordPress</h2>

<p class="wp-block-paragraph">So, how exactly does PHP fit into WordPress? Here’s the simplified breakdown:</p>

<ol class="wp-block-list">
<li><strong>Core Files</strong>: WordPress itself is mostly written in PHP. Every time you install WordPress, you’re downloading a collection of PHP files that handle user logins, post creation, media uploading, and more.</li>



<li><strong>Themes</strong>: Your WordPress theme is also built using PHP. Those <code>.php</code> files you see in a theme folder (like <code>header.php</code>, <code>footer.php</code>, <code>functions.php</code>) determine your site’s layout and functionality.</li>



<li><strong>Plugins</strong>: Plugins extend WordPress, and guess what—they’re also primarily PHP-based. Whether it’s an SEO plugin, a security plugin, or a contact form plugin, there’s PHP code under the hood.</li>
</ol>

<p class="wp-block-paragraph">Each time someone visits your site, WordPress’s PHP files run on the server. They query the database (also typically MySQL or MariaDB, sometimes others), retrieve the right content, and package it into an HTML page that gets sent to the browser. For a deeper dive on databases, we have a new post about <a href="https://wata.es/de/nosql-datenbanken-eine-revolution-im-data-warehousing/">NoSQL Databases</a>—a bit more advanced, but it shows the variety of database solutions you might run into in modern web development.</p>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<h2 class="wp-block-heading">4. Why Non-Developers Should Care</h2>

<p class="wp-block-paragraph">You might be thinking, “I’m not a coder, so why should I bother with all this PHP talk?” Great question!</p>

<ul class="wp-block-list">
<li><strong>Better Collaboration</strong>: Understanding the fundamentals of how PHP works in WordPress can help you communicate more effectively with developers. If you know what’s happening behind the scenes, it’s easier to explain a design element or bug you’re seeing.</li>



<li><strong>Troubleshooting</strong>: Often, WordPress errors might be something as simple as a missing semicolon or conflicting plugin. If you can glance at PHP error logs or know how to disable a problematic plugin temporarily, you can solve issues faster.</li>



<li><strong>Site Performance</strong>: WordPress performance is heavily influenced by the efficiency of your PHP code. If you’re a content manager, you might not write code, but knowing that large images or heavy plugins affect PHP’s workload gives you insight into how to keep your site running smoothly.</li>



<li><strong>Security Awareness</strong>: A big part of WordPress security involves understanding how plugins and themes interact with PHP. If you’re aware of potential vulnerabilities, you’ll make smarter decisions about what to install and update.</li>
</ul>

<p class="wp-block-paragraph">Let’s say you’re a designer who wants to add a custom typeface or tweak the layout. You might dip into the <code>functions.php</code> file or install a plugin that modifies theme elements. Having a basic idea of the file structure and the role PHP plays helps you avoid inadvertently breaking something.</p>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<h2 class="wp-block-heading">5. A Tiny PHP Example</h2>

<p class="wp-block-paragraph">To keep things concrete, here’s a <em>very</em> short snippet of what a basic PHP function might look like in a WordPress theme’s <code>functions.php</code>:</p>

<pre class="wp-block-preformatted"><code>function watafactory_add_support() {</code>
<code>    </code><code>// This enables featured images in a WordPress theme</code>
<code>    </code><code>add_theme_support('post-thumbnails');</code>
<code>    </code><code>// This adds custom logo support</code>
<code>    </code><code>add_theme_support('custom-logo');</code>
<code>}</code>
<code>add_action('after_setup_theme', 'watafactory_add_support');</code></pre>

<ul class="wp-block-list">
<li><strong>What it does</strong>: This little snippet tells WordPress your theme supports featured images and custom logos.</li>



<li><strong>Why it matters</strong>: If you’re a designer or content manager, you might want to ensure your posts have eye-catching featured images, or that you can easily upload a custom site logo from the WordPress dashboard. Knowing where and how this is done in PHP means you can quickly tweak your theme.</li>
</ul>

<p class="wp-block-paragraph">Even if you don’t fully understand every function here, grasping the gist that “this code block registers new features so WordPress can use them” can be powerful.</p>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<h2 class="wp-block-heading">6. The Role of Plugins (and Why They’re PHP-Driven)</h2>

<p class="wp-block-paragraph">Plugins are essentially mini-applications (written in PHP) that integrate seamlessly with WordPress. If you’ve ever installed a form plugin like Contact Form 7 or an SEO plugin like Yoast, you’ve experienced how plugins can expand WordPress’s capabilities.</p>

<ul class="wp-block-list">
<li><strong>For Developers</strong>: Plugins offer an opportunity to build custom functionalities. If a client needs a special booking system or membership login, for example, we can code a plugin that fits right into WordPress’s existing structure.</li>



<li><strong>For Non-Developers</strong>: Installing a plugin is as easy as clicking “Add New,” but understanding that PHP is under the hood can help you pick reputable plugins. Plugins are “mini software,” so you want well-coded and frequently updated ones.</li>
</ul>

<p class="wp-block-paragraph">At WATA Factory, we’ve also explored more in-depth WordPress tweaks—like building custom blocks or hooking into WordPress’s REST API. If you want to expand your WordPress knowledge further, you might enjoy reading our <a href="https://wata.es/de/einfuehrung-in-wordpress-page-builder-2025/">Introduction to WordPress Page Builders</a> or our follow-up piece on <a href="https://wata.es/de/die-wichtigsten-funktionen-und-moeglichkeiten-des-fuehrenden-wordpress-page-builders-im-jahr-2024/">Core Features and Capabilities of the Leading WordPress Page Builder in 2024</a>. These articles can help you see how developers and designers leverage plugins or page builder solutions for rapid site creation.</p>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<h2 class="wp-block-heading">7. Themes: The Intersection of Design &amp; PHP</h2>

<p class="wp-block-paragraph">When you install a WordPress theme, you’re basically installing a collection of PHP templates that define how your site looks. Each page—like your blog posts, your homepage, or your contact page—has a corresponding PHP file that dictates its structure.</p>

<ul class="wp-block-list">
<li><strong>For Designers</strong>: This is where you live. Colors, fonts, imagery—this is your playground. However, behind every color and font choice is a snippet of PHP telling WordPress “hey, display the site title here” or “generate a list of recent blog posts there.”</li>



<li><strong>For Content Managers</strong>: Ever wonder how your blog post content ends up styled a certain way? That’s the theme’s PHP template at work. Basic familiarity with these template files can help you request changes from developers more precisely.</li>
</ul>

<p class="wp-block-paragraph">If you ever feel like taking a peek behind the curtain, you can open up a theme’s <code>header.php</code>, <code>single.php</code>, or <code>footer.php</code> files. They may look a bit confusing at first, but after a few glances, you’ll notice the pattern: HTML + some PHP snippets that dynamically pull in data like post titles, metadata, or your site’s navigation menu.</p>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<h2 class="wp-block-heading">8. Performance &amp; Security Considerations</h2>

<h3 class="wp-block-heading">Performance</h3>

<p class="wp-block-paragraph">A well-optimized WordPress site can load quickly and handle tons of traffic. A poorly optimized one can buckle under the pressure.</p>

<ul class="wp-block-list">
<li><strong>Caching</strong>: PHP code runs on the server each time a page is loaded. But caching plugins can store the finished HTML, reducing how often PHP files need to be executed. This means your site loads faster.</li>



<li><strong>Code Quality</strong>: Clean, well-structured PHP code is easier to maintain and runs more efficiently. If you have dozens of poorly-coded plugins, you’ll likely see performance hits.</li>
</ul>

<h3 class="wp-block-heading">Security</h3>

<p class="wp-block-paragraph">PHP’s flexibility is both a blessing and a curse. If not written securely, it can open up vulnerabilities.</p>

<ul class="wp-block-list">
<li><strong>Updates</strong>: WordPress regularly releases updates to patch security issues. The same goes for themes and plugins. Keeping them updated ensures you’re protected against known threats.</li>



<li><strong>Quality Plugins</strong>: Not all plugins are created equal. Some might be poorly coded and leave your site open to attacks. Always choose reputable plugins with good reviews and frequent updates.</li>
</ul>

<p class="wp-block-paragraph">For a broader sense of how we handle security and best practices in general, you might want to check out our <a href="https://wata.es/de/technologie/">Technology page</a>—it’s got more info on how we approach development and keep sites running securely at WATA Factory.</p>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<h2 class="wp-block-heading">9. Getting Comfortable with the Basics</h2>

<p class="wp-block-paragraph">Even if your main gig is design or content, you’ll benefit from learning just a smidge of PHP. Here are some beginner-friendly action items:</p>

<ol class="wp-block-list">
<li><strong>Tinker with a Local Environment</strong>: Set up a local WordPress install (using something like MAMP, WAMP, or Local by Flywheel). Poke around the theme files. Try adding a function or two to <code>functions.php</code>.</li>



<li><strong>Read &amp; Watch Tutorials</strong>: There are countless YouTube channels and blogs dedicated to WordPress theme development. Start small—like customizing your blog layout or adding a custom post type.</li>



<li><strong>Practice Safe Experimentation</strong>: If you decide to play with code on a live site, make sure you have a backup or a staging environment in place.</li>



<li><strong>Study Our Blog Posts</strong>: We frequently publish articles on everything from <a href="https://wata.es/de/einfuhrung-in-das-automatisierte-testing-mit-codeception-in-php-projekten/">automated testing in PHP projects</a> to advanced front-end frameworks. While not all of them are strictly about WordPress, they will help expand your understanding of modern PHP development practices.</li>
</ol>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<h2 class="wp-block-heading">10. Wrapping Up</h2>

<p class="wp-block-paragraph">Learning PHP basics is like finding the missing puzzle piece that lets you see the entire WordPress picture clearly. It’s not just for developers; having a grasp of what’s happening behind the scenes empowers designers, content managers, and site owners to make more informed decisions.</p>

<p class="wp-block-paragraph">I love that moment when our design team says, “We want this widget to appear here,” and, as a developer, I can open up <code>sidebar.php</code> or <code>functions.php</code> to show them exactly which lines of code handle that. There’s a sense of team synergy when non-developers feel confident enough to peek under the hood. You might not become a full-fledged PHP wizard overnight, but you’ll certainly be able to hold your own in a conversation about how WordPress is structured.</p>

<p class="wp-block-paragraph">And if you ever need help—from building custom themes and plugins to performing a site-wide performance audit—remember that we at WATA Factory have your back. Our <a href="https://wata.es/de/">main site</a> is a good starting point to see our services, and our <a href="https://wata.es/de/blog/">blog</a> is chock-full of insights on the latest in tech, including additional WordPress and PHP tips. Feel free to explore, leave a comment, or reach out if you’d like a deeper dive into any topic.</p>

<p class="wp-block-paragraph">So go ahead—pop open that <code>functions.php</code> file, install a test plugin, or read a few lines of code. You’d be surprised at how quickly the basics become second nature. WordPress might be user-friendly by design, but a small slice of PHP knowledge can make you unstoppable in the world of content management and site design.</p>

<p class="wp-block-paragraph"><strong>Happy WordPress-ing!</strong> If you have any questions or want to chat about all things PHP, don’t hesitate to reach out. We love hearing your thoughts and geek out on new challenges every day.</p>

<hr class="wp-block-separator has-alpha-channel-opacity"/>

<hr class="wp-block-separator has-alpha-channel-opacity"/>
<p>The post <a href="https://wata.es/de/php-und-wordpress-was-du-wissen-musst-auch-wenn-du-kein-entwickler-bist/">PHP und WordPress: Was du wissen musst (auch wenn du kein Entwickler bist)</a> appeared first on <a href="https://wata.es/de/">WATA Factory</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Arbeiten mit Enum-Typen in Symfony und PostgreSQL</title>
		<link>https://wata.es/de/arbeiten-mit-enum-typen-in-symfony-und-postgresql/</link>
		
		<dc:creator><![CDATA[Ángel Cardiel]]></dc:creator>
		<pubDate>Wed, 09 Nov 2022 10:49:42 +0000</pubDate>
				<category><![CDATA[Neuigkeiten]]></category>
		<category><![CDATA[Technologie]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>
		<guid isPermaLink="false">https://wata.es/?p=7614</guid>

					<description><![CDATA[<p>Manchmal benötigen wir eine Liste mit gültigen Werten für ein bestimmtes Feld in der Datenbank. Zu diesem Zweck können wir einen benutzerdefinierten Datentyp in Symfony erstellen und ihn in unseren Entity Mapping Definitionen verwenden. So können wir ihn auch für unsere Validierungen nutzen. Dies ist besonders hilfreich bei der Verwendung von PostgreSQL-ENUM-Typen. Dieses Verfahren ist [&#8230;]</p>
<p>The post <a href="https://wata.es/de/arbeiten-mit-enum-typen-in-symfony-und-postgresql/">Arbeiten mit Enum-Typen in Symfony und PostgreSQL</a> appeared first on <a href="https://wata.es/de/">WATA Factory</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Manchmal benötigen wir eine Liste mit gültigen Werten für ein bestimmtes Feld in der Datenbank. Zu diesem Zweck können wir einen benutzerdefinierten Datentyp in Symfony erstellen und ihn in unseren Entity Mapping Definitionen verwenden. So können wir ihn auch für unsere Validierungen nutzen. Dies ist besonders hilfreich bei der Verwendung von PostgreSQL-ENUM-Typen.</p>



<span id="more-7614"></span>



<p class="wp-block-paragraph">Dieses Verfahren ist für PHP-Versionen vor PHP 8.1 gedacht, die den nativen <a rel="noreferrer noopener" href="https://www.php.net/manual/es/language.enumerations.php" target="_blank">Enum</a>-Typ enthalten. Wir könnten die gleiche Lösung mit wenigen Änderungen mit Enums oder mit einem anderen bestehenden Ansatz behandeln. Viele Projekte verwenden jedoch immer noch PHP 8.0 oder älter und dieser Code ist immer noch nützlich für die Anpassung unserer Enum-Typen in PostgreSQL mit Doctrine und Symfony.</p>



<p class="wp-block-paragraph">Stell dir vor, du hast einen Typ appointment_status als Enum in deinem alten Datenbankschema wie folgt definiert. </p>



<pre id="block-9c147536-b016-40cc-9bc7-73da2af413b6" class="wp-block-preformatted">CREATE TYPE public.appointment_status AS ENUM
 ('Open', 'Invited', 'Assigned', 'Unassigned');</pre>



<p class="wp-block-paragraph">Und du verwendest diesen Typ in einer bestimmten Spalte: </p>



<pre class="wp-block-preformatted">CREATE TABLE IF NOT EXISTS public.appointment
  {
 id integer NOT NULL,
 status public.appointment_status NOT NULL DEFAULT 'Open'::public.appointment_status,
 comment character varying(500)
  }</pre>



<p class="wp-block-paragraph">In diesem Artikel erfahren wir also, wie man diese Art von Daten auf einfache Weise handhaben kann.</p>



<h2 class="wp-block-heading"><strong><strong>Erstellen eines abstrakten Enum-Typs</strong></strong></h2>



<p class="wp-block-paragraph">Der erste Schritt ist die Erstellung einer abstrakten Klasse für diese Art von Daten. Mit dieser Abstraktion können wir die Klasse für jedes Enum-Feld wiederverwenden. </p>



<pre class="wp-block-preformatted"><?php namespace App\Infrastructure\Persistence\Doctrine\DBAL; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; abstract class AbstractEnumType extends Type { protected string $schema = "public"; protected string $name; protected array $values = array(); public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { return $this-??>schema . ".\"" . $this-&gt;getName() . "\""; 
  }  
 
 public function convertToPHPValue($value, AbstractPlatform $platform) 
  {  
 return $value; 
  }  
 
 public function convertToDatabaseValue($value, AbstractPlatform $platform) 
  {  
 if (!in_array($value, $this-&gt;getValidValues())) { 
 throw new \InvalidArgumentException("Invalid '".$this-&gt;name."' value."); 
  }  
 return $value; 
  }  
 
 public function getName(): string 
  {  
 return $this-&gt;name; 
  }  
 
 public function requiresSQLCommentHint(AbstractPlatform $platform): bool 
  {  
 return true; 
  }  
 
 public function getValidValues(): array 
  {  
 return $this-&gt;values; 
  }  
 
}  
 </pre>



<h2 class="wp-block-heading"><strong>Erstellen des Enum-Typs</strong></h2>



<p class="wp-block-paragraph">Nun musst du den spezifischen Enum-Typ erstellen, der die abstrakte Klasse erweitert: </p>



<pre class="wp-block-preformatted"><?php namespace App\Infrastructure\Persistence\Doctrine\DBAL; class AppointmentStatusType extends AbstractEnumType { protected string $name = 'appointment_status'; protected array $values = []; protected static array $options = array( 'Open', 'Invited', 'Assigned', 'Unassigned' ); function __init() { $this-??>values = self::$options; 
  }  
 
 public function getValidValues(): array 
  {  
 return self::$options; 
  }  
}  
 </pre>



<p class="wp-block-paragraph"><strong>Tipp</strong>: Wenn die Liste zu lang ist, kannst du die Klasse in zwei Dateien aufteilen; die Logik auf der einen Seite und die Werte auf der anderen, so erhältst du besser wartbare Klassen </p>



<pre id="block-9c147536-b016-40cc-9bc7-73da2af413b6" class="wp-block-preformatted"><?php namespace App\Infrastructure\Persistence\Doctrine\DBAL; USE APP\Infrastructure\Persistence\Doctrine\DBAL\Enums\CitizenshipEnum; class EmployeeCitizenshipType extends AbstractEnumType { protected string $name = 'employee_citizenship'; protected array $values = []; function __init() { $this-??>values = CitizenshipEnum::getValues();
  }
 public function getValidValues(): array
  {
 return CitizenshipEnum::getValues();
  }
}
namespace App\Infrastructure\Persistence\Doctrine\DBAL\Enums;
class CitizenshipEnum
{
 protected static array $values = [
 'Ohne Angabe',
 'Afghanistan',
 'Algerien',
 'Andorra',
 'Angola',
 '[....]',
 'Vietnam',
 'Zentralafrikanische Republik',
 'Zypern',
 ];
 public static function getValues(): array
  {
 return self::$values;
  }
}</pre>



<h2 class="wp-block-heading"><strong><strong>Definieren als Typ in Doctrine</strong></strong></h2>



<p class="wp-block-paragraph">An diesem Punkt müssen wir Symfony mitteilen, dass wir einen neuen Datentyp haben. Das einzige, was noch aussteht, ist eine Map in Doctrine und wir müssen ihr sagen "Eh, dieser Datentyp ist etwas Besonderes!". Bearbeite die doctrine.yml und füge diese Zeilen hinzu: </p>



<pre class="wp-block-preformatted">doctrine: 
 dbal: 

 […] 
 mapping_types: 
 appointment_status: appointment_status 

 

 types: 
 appointment_status: App\..\AppointmentStatusType 

 </pre>



<h2 class="wp-block-heading"><strong><strong>Mapping Entität mit benutzerdefiniertem Datentyp</strong> </strong></h2>



<p class="wp-block-paragraph">Ja! Doctrine kennt jetzt die einzigen zulässigen Werte für den Status. In unserer XML-Datei für das Mapping von Entitäten können wir jetzt verwenden:</p>



<pre class="wp-block-preformatted">&lt;!-- status --&gt;
&lt;field name="status" type="appointment_status" column="status"&gt;
    &lt;options&gt;
        &lt;option name="default"&gt;Open&lt;/option&gt;
    &lt;/options&gt;
&lt;/field&gt; </pre>



<p class="wp-block-paragraph">In unserer Entitätsdatei müssen wir "string" verwenden und uns nicht um den Datentyp kümmern... Doctrine macht alles für uns: </p>



<pre class="wp-block-preformatted">private string $status; </pre>



<h2 class="wp-block-heading"><strong>Verwendung von Asserts zur Validierung von Eingaben</strong></h2>



<p class="wp-block-paragraph">Wenn wir nun eine Eingabe mit einem speziellen Datentyp validieren wollen, können wir diese Einschränkung mit Symfony/Validator verwenden. Dies ist nützlich für die Validierung von Formularen oder POST-Aufrufen.</p>



<pre class="wp-block-preformatted">status: 
  - NotBlank: ~ 
  - Choice: { callback: [ \[..]ProductStatusType, getValidValues] }  </pre>



<p class="wp-block-paragraph">Und Symfony prüft, ob der angegebene Wert in den zugelassenen Werten in unserem benutzerdefinierten Datentyp definiert ist.... Zauberei! ie Callback-Definition ruft die Methode getValidValues() auf und prüft, ob der angegebene Wert ein gültiger Wert ist. </p>



<p class="wp-block-paragraph">Symfony ist großartig! </p>
<p>The post <a href="https://wata.es/de/arbeiten-mit-enum-typen-in-symfony-und-postgresql/">Arbeiten mit Enum-Typen in Symfony und PostgreSQL</a> appeared first on <a href="https://wata.es/de/">WATA Factory</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
