<?xml version="1.0" encoding="UTF-8"?><feed
	xmlns="http://www.w3.org/2005/Atom"
	xmlns:thr="http://purl.org/syndication/thread/1.0"
	xml:lang="en-US"
	>
	<title type="text">PHP Magazine Network</title>
	<subtitle type="text"></subtitle>

	<updated>2023-03-23T14:08:33Z</updated>

	<link rel="alternate" type="text/html" href="https://phpmagazine.net" />
	<id>https://phpmagazine.net/feed/atom</id>
	<link rel="self" type="application/atom+xml" href="https://phpmagazine.net/feed/atom" />

	<generator uri="https://wordpress.org/" version="6.8.3">WordPress</generator>
	<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[Get Started with Laravel Volt: A Free Full Stack Laravel App with Livewire &#038; Alpine.js]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/get-started-with-laravel-volt-a-free-full-stack-laravel-app-with-livewire-alpine-js.html" />

		<id>https://phpmagazine.net/?p=10852</id>
		<updated>2023-03-21T15:20:05Z</updated>
		<published>2023-03-29T11:00:00Z</published>
		<category scheme="https://phpmagazine.net" term="Laravel" /><category scheme="https://phpmagazine.net" term="Alpine.js" /><category scheme="https://phpmagazine.net" term="authentication" /><category scheme="https://phpmagazine.net" term="Bootstrap 5" /><category scheme="https://phpmagazine.net" term="commercial projects" /><category scheme="https://phpmagazine.net" term="CRUD" /><category scheme="https://phpmagazine.net" term="dashboard" /><category scheme="https://phpmagazine.net" term="detailed documentation" /><category scheme="https://phpmagazine.net" term="example pages" /><category scheme="https://phpmagazine.net" term="Free" /><category scheme="https://phpmagazine.net" term="Gulp commands" /><category scheme="https://phpmagazine.net" term="Laravel Volt" /><category scheme="https://phpmagazine.net" term="lightweight plugins" /><category scheme="https://phpmagazine.net" term="Livewire" /><category scheme="https://phpmagazine.net" term="local environment setup" /><category scheme="https://phpmagazine.net" term="MIT License" /><category scheme="https://phpmagazine.net" term="SaaS files" /><category scheme="https://phpmagazine.net" term="UI components" /><category scheme="https://phpmagazine.net" term="user roles" />
		<summary type="html"><![CDATA[Laravel Volt is an admin dashboard template that offers a comprehensive design and development toolbox for personal and commercial projects. It comes with handcrafted UI elements tailored for Bootstrap 5 and an out-of-the-box Laravel backend. With Livewire integration, you can create dynamic interfaces without leaving your favorite framework. And when combined with Alpine.js, you have [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/get-started-with-laravel-volt-a-free-full-stack-laravel-app-with-livewire-alpine-js.html"><![CDATA[
<p>Laravel Volt is an admin dashboard template that offers a comprehensive design and development toolbox for personal and commercial projects. It comes with handcrafted UI elements tailored for Bootstrap 5 and an out-of-the-box Laravel backend. With Livewire integration, you can create dynamic interfaces without leaving your favorite framework. And when combined with Alpine.js, you have the perfect combo for your next big project.</p>



<p>In this article, we&#8217;ll provide a brief overview of Laravel Volt, its features, and a getting started guide to help you set up the project on your local development environment. </p>



<h2 class="wp-block-heading">Getting Started</h2>



<p>Before you start, ensure you have an Apache local environment with PHP and MySQL installed. You will also need to install Composer, a dependency manager for PHP.</p>



<ol class="wp-block-list">
<li>Download the project&#8217;s zip, then copy and paste the <code>volt-dashboard-master</code> folder into your projects folder. Rename the folder to your project&#8217;s name.</li>



<li>Ensure Node and Composer are locally installed.</li>



<li>Run the following commands to download all project dependencies:</li>
</ol>



<pre class="wp-block-prismatic-blocks"><code class="language-">composer install</code></pre>



<p>Now before running npm, and if you are running a new npm version I&#8217;ll recommend you doing some updates before and use gulp-dart-sass instead of gulp-sass</p>



<ol class="wp-block-list" start="2">
<li>Replace <code>&quot;gulp-sass&quot;: &quot;4.0.2&quot;</code> with <code>&quot;gulp-dart-sass&quot;: &quot;^1.0.2&quot;</code> in your <code>devDependencies</code> in your <code>package.json</code> file. The <code>gulp-dart-sass</code> package is a drop-in replacement for <code>gulp-sass</code> that uses the Dart Sass compiler, which is more compatible with newer Node.js versions.</li>



<li>Replace <code>&quot;node-sass&quot;: &quot;^6.0.0&quot;</code> with <code>&quot;sass&quot;: &quot;^1.43.4&quot;</code> in your <code>dependencies</code> in your <code>package.json</code> file.</li>



<li>Update your <code>scripts</code> section in <code>package.json</code> to replace <code>node-sass</code> with <code>sass</code>:</li>
</ol>



<pre class="wp-block-prismatic-blocks"><code class="language-">&quot;scripts&quot;: {
    &quot;scss&quot;: &quot;sass resources/scss:css&quot;,
    ...
}</code></pre>



<pre class="wp-block-prismatic-blocks"><code class="language-">npm install</code></pre>



<ol class="wp-block-list" start="4">
<li>To compile all the SCSS files under <code>resources/scss</code> into a single CSS file located in <code>public/css</code>, run the following command:</li>
</ol>



<pre class="wp-block-prismatic-blocks"><code class="language-">npm run scss</code></pre>



<ol class="wp-block-list" start="5">
<li>Copy <code>.env.example</code> to <code>.env</code> and update the configurations (mainly the database configuration).</li>



<li>In your terminal, run <code>php artisan key:generate</code>.</li>



<li>Run <code>php artisan migrate --seed</code> to create the database tables and seed them.</li>



<li>Run <code>php artisan storage:link</code> to create the storage symlink (if you&#8217;re using Vagrant with Homestead for development, remember to ssh into your virtual machine and run the command from there).</li>
</ol>



<h2 class="wp-block-heading">Usage</h2>



<p>To start testing the theme, register as a user or log in using one of the default users:</p>



<ul class="wp-block-list">
<li>admin type &#8211; admin@paper.com with the password &#8216;secret&#8217;</li>



<li>creator type &#8211; creator@paper.com with the password &#8216;secret&#8217;</li>



<li>member type &#8211; member@paper.com with the password &#8216;secret&#8217;</li>
</ul>



<p>Make sure to run the migrations and seeders for the above credentials to be available. Check the <a href="https://volt-pro-laravel-admin-dashboard.updivision.com/documentation/getting-started/overview/index.html">documentation </a>for more details about features and usage of the Laravel volt.</p>



<h2 class="wp-block-heading">Laravel Volt Pro Features</h2>



<p>Laravel Volt offers a plethora of features, including:</p>



<ul class="wp-block-list">
<li>100+ handcrafted UI components tailored for Bootstrap 5 with Vanilla JS</li>



<li>11 example pages to get you started</li>



<li>3 lightweight plugins: datepicker, notification, and charts library</li>



<li>SaaS files &amp; Gulp commands</li>



<li>Fully-functional authentication system, register and user profile editing features built with Laravel</li>



<li>Livewire &amp; Alpine.js integration</li>



<li>Free for peronal and commercial projects</li>
</ul>



<p>Laravel Volt pro edition cost $149, check out the <a href="https://themesberg.com/product/laravel/volt-pro">pro version of the Volt Laravel</a> admin dashboard template.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Laravel Volt is an interesting choice for developers looking for a feature-rich and easy-to-use admin dashboard template. With its vast array of UI components, example pages, and Laravel backend, it provides</p>
]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/get-started-with-laravel-volt-a-free-full-stack-laravel-app-with-livewire-alpine-js.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/get-started-with-laravel-volt-a-free-full-stack-laravel-app-with-livewire-alpine-js.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
		<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[Unleashing the Power of PHP Fibers: Boost Web Development with Efficient Coroutines]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/unleashing-the-power-of-php-fibers-boost-web-development-with-efficient-coroutines.html" />

		<id>https://phpmagazine.net/?p=10752</id>
		<updated>2023-03-17T04:44:38Z</updated>
		<published>2023-03-28T10:00:00Z</published>
		<category scheme="https://phpmagazine.net" term="Programming" /><category scheme="https://phpmagazine.net" term="lightweight coroutines" /><category scheme="https://phpmagazine.net" term="multi-threading" /><category scheme="https://phpmagazine.net" term="PHP Fibers" /><category scheme="https://phpmagazine.net" term="rate-limited API" /><category scheme="https://phpmagazine.net" term="resuming" /><category scheme="https://phpmagazine.net" term="suspending" /><category scheme="https://phpmagazine.net" term="Web development" />
		<summary type="html"><![CDATA[The ability to efficiently execute multiple tasks concurrently is a vital aspect of modern web development. While PHP has traditionally lacked built-in support for multi-threading, the introduction of fibers in PHP 8.1.0 offers a game-changing solution. Fibers are lightweight, full-stack coroutines that enable developers to suspend and resume function execution, simulating multi-threading behavior and enhancing [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/unleashing-the-power-of-php-fibers-boost-web-development-with-efficient-coroutines.html"><![CDATA[
<p>The ability to efficiently execute multiple tasks concurrently is a vital aspect of modern web development. While PHP has traditionally lacked built-in support for multi-threading, the introduction of fibers in PHP 8.1.0 offers a game-changing solution. Fibers are lightweight, full-stack coroutines that enable developers to suspend and resume function execution, simulating multi-threading behavior and enhancing the overall efficiency of web applications. In this article, we will delve into the essentials of PHP fibers, explore their usage, and demonstrate how they can significantly improve your web development projects.</p>



<p>In this article, we will explore the basics of PHP fibers and learn how to use them to improve the efficiency of our web development projects. We will cover everything from creating a fiber to more advanced features, so you can start leveraging the power of fibers in your own PHP projects.</p>



<p>Fibers are lightweight, full-stack coroutines that allow suspending the current execution of a function and resuming it later, which makes it possible to achieve multi-threading-like behavior. In this article, we will go over the basics of PHP fibers and how to use them.</p>



<h2 class="wp-block-heading">Creating a php fiber </h2>



<p>A fiber is created using the Fiber class. Here is an example of how to create a fiber that echoes a message:</p>



<pre class="wp-block-preformatted">phpCopy code<code>$fiber = new Fiber(function() {
    echo &quot;Hello from the fiber\n&quot;;
});

$fiber-&gt;start();
</code></pre>



<p>In this example, we create a new fiber by passing a callable function to the Fiber constructor. The function is not executed yet, but when we call the start() method, the function will be executed in a new fiber.</p>



<h2 class="wp-block-heading">Suspending and resuming a php fiber</h2>



<p>Fibers can be paused at any point using the Fiber::suspend() method. This method accepts an optional value that can be used to resume the fiber later. Here is an example of how to suspend and resume a fiber:</p>



<pre class="wp-block-preformatted">phpCopy code<code>$fiber = new Fiber(function() {
    echo &quot;Fiber started\n&quot;;
    Fiber::suspend(&quot;Value passed to resume\n&quot;);
    echo &quot;Fiber resumed\n&quot;;
});

$fiber-&gt;start();
echo &quot;Fiber suspended with value: &quot; . $fiber-&gt;getCurrentValue() . &quot;\n&quot;;
$fiber-&gt;resume();
</code></pre>



<p>In this example, we create a new fiber that echoes &#8220;Fiber started&#8221;, suspends itself using Fiber::suspend(), and echoes &#8220;Fiber resumed&#8221; when it is resumed. We start the fiber, and it prints &#8220;Fiber started&#8221;. We then get the current value of the fiber using getCurrentValue(), which should return null because the fiber is suspended. Finally, we resume the fiber, and it prints &#8220;Fiber resumed&#8221; and exits.</p>



<h2 class="wp-block-heading">Passing values to a php fiber </h2>



<p>When a fiber is started, it can accept an optional parameter that is passed to the callable function. Here is an example of how to pass a parameter to a fiber:</p>



<pre class="wp-block-preformatted">phpCopy code<code>$fiber = new Fiber(function($name) {
    echo &quot;Hello $name\n&quot;;
});

$fiber-&gt;start(&quot;John&quot;);
</code></pre>



<p>In this example, we create a new fiber that accepts a parameter called &#8220;name&#8221; and echoes &#8220;Hello $name&#8221;. We start the fiber with the parameter &#8220;John&#8221;, and it prints &#8220;Hello John&#8221;.</p>



<h2 class="wp-block-heading">Creating simple rate-limited API request system using PHP fibers</h2>



<p>In this example, we&#8217;ll create a simple rate-limited API request system using PHP fibers. We&#8217;ll be sending requests to an API with a limit of 5 requests per second. If the limit is reached, fibers will help us pause the execution until we can send the next request.</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">&lt;?php

use \Fiber;

class RateLimiter {
    private int $maxRequestsPerSecond;
    private float $lastRequestTime;
    private Fiber $limiter;

    public function __construct(int $maxRequestsPerSecond) {
        $this-&gt;maxRequestsPerSecond = $maxRequestsPerSecond;
        $this-&gt;lastRequestTime = microtime(true);

        $this-&gt;limiter = new Fiber(function () {
            while (true) {
                $currentTime = microtime(true);
                $timeSinceLastRequest = $currentTime - $this-&gt;lastRequestTime;

                if ($timeSinceLastRequest &lt; 1 / $this-&gt;maxRequestsPerSecond) {
                    usleep((int) ((1 / $this-&gt;maxRequestsPerSecond - $timeSinceLastRequest) * 1000000));
                }

                $this-&gt;lastRequestTime = microtime(true);
                Fiber::suspend();
            }
        });

        $this-&gt;limiter-&gt;start();
    }

    public function request(callable $apiCall) {
        $this-&gt;limiter-&gt;resume();
        return $apiCall();
    }
}

$rateLimiter = new RateLimiter(5);

$apiCall = function () {
    // Simulate an API call
    echo &quot;API request sent at &quot; . microtime(true) . PHP_EOL;
};

for ($i = 0; $i &lt; 10; $i++) {
    $rateLimiter-&gt;request($apiCall);
}
</code></pre>



<p>Running this example will give something like :</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">$ php rate-limiter-api.php
API request sent at 1678996902.2899
API request sent at 1678996902.4936
API request sent at 1678996902.6969
API request sent at 1678996902.8985
API request sent at 1678996903.1006
API request sent at 1678996903.3031
API request sent at 1678996903.5055
API request sent at 1678996903.7094
API request sent at 1678996903.9142
API request sent at 1678996904.116</code></pre>



<p>In this example, we have a <code>RateLimiter</code> class that takes the maximum number of requests per second as a parameter. It has a <code>request</code> method that takes a callable representing the API call. The rate limiter ensures that we don&#8217;t exceed the allowed number of requests per second by using fibers to pause the execution if necessary.</p>



<p>When the <code>RateLimiter</code> object is created, it starts a fiber that runs in an infinite loop. Inside the loop, it checks the time since the last request and sleeps if it&#8217;s too soon to send the next request. After sleeping, it updates the last request time and suspends the fiber.</p>



<p>When the <code>request</code> method is called, it resumes the fiber, which ensures we don&#8217;t exceed the rate limit. After the fiber is resumed, it calls the API function provided.</p>



<p>The example demonstrates how PHP fibers can be used to solve real-world problems like rate limiting in a simple and efficient manner.</p>



<h2 class="wp-block-heading">Conclusion </h2>



<p>In conclusion, fibers introduce a powerful and efficient mechanism for concurrent programming in PHP. This article provided an overview of PHP fibers, covering fundamental aspects like creating, suspending, and resuming fibers, as well as passing values to them. We also demonstrated a practical use case by implementing a rate-limited API request system. To further harness the potential of fibers, we encourage you to delve into the official documentation and experiment with this feature in your PHP projects.</p>
]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/unleashing-the-power-of-php-fibers-boost-web-development-with-efficient-coroutines.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/unleashing-the-power-of-php-fibers-boost-web-development-with-efficient-coroutines.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
		<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[Which Boring but Cheap Web Development Stack to Use in 2023?]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/which-boring-but-cheap-web-development-stack-to-use-in-2023.html" />

		<id>https://phpmagazine.net/?p=10638</id>
		<updated>2023-03-14T09:11:15Z</updated>
		<published>2023-03-27T09:00:00Z</published>
		<category scheme="https://phpmagazine.net" term="Emerging Trends" /><category scheme="https://phpmagazine.net" term=".Net" /><category scheme="https://phpmagazine.net" term="backend" /><category scheme="https://phpmagazine.net" term="Go" /><category scheme="https://phpmagazine.net" term="HAProxy" /><category scheme="https://phpmagazine.net" term="java" /><category scheme="https://phpmagazine.net" term="Jetty" /><category scheme="https://phpmagazine.net" term="Kotlin" /><category scheme="https://phpmagazine.net" term="laravel" /><category scheme="https://phpmagazine.net" term="MVP" /><category scheme="https://phpmagazine.net" term="PHP" /><category scheme="https://phpmagazine.net" term="Pocketbase" /><category scheme="https://phpmagazine.net" term="Postgres" /><category scheme="https://phpmagazine.net" term="Quarkus" /><category scheme="https://phpmagazine.net" term="Servlets" /><category scheme="https://phpmagazine.net" term="Web development" />
		<summary type="html"><![CDATA[In Hacker News alentred asked seeking advice for which technology stack to use for a web app MVP in 2023 &#8220;use boring technology &#8211; iterate fast &#8211; deploy with minimal cost for now&#8221;. He added &#8220;So, to your taste, what compares in 2023 to the romanticized experience of PHP in 2000s? Or should I just [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/which-boring-but-cheap-web-development-stack-to-use-in-2023.html"><![CDATA[
<p>In Hacker News <a href="https://news.ycombinator.com/item?id=35112481">alentred asked</a> seeking advice for which technology stack to use for a web app MVP in 2023 &#8220;use boring technology &#8211; iterate fast &#8211; deploy with minimal cost for now&#8221;. He added &#8220;So, to your taste, what compares in 2023 to the romanticized experience of PHP in 2000s? Or should I just &#8220;undust&#8221; my PHP and learn Laravel?&#8221;</p>



<p>Discussions mentioned having used Spring, Rails, Express, Django, Flask, and Elixir, but they found these frameworks too complex and expensive for their MVP&#8217;s needs. They also mentioned having used serverless frameworks like Zappa but found it immature. The original poster has vague memories of using PHP in the past and wants to know if there is a modern technology that compares to PHP&#8217;s simplicity and ease of deployment. </p>



<p>One developer suggested using Gunicorn, which is similar in setup to PHP and has a similar number of lines in the Nginx config file. PHP has the added advantage of allowing for shared hosting, which is a good option for beginners.</p>



<p>Another developer recommended using ASP on .net, which is mature and quick. But they also advised that if someone already knows PHP, then they should just use PHP, and Laravel is a great framework for it. Some developers prefer .Net or Java, as they provide stability and do not require frequent changes with the ever-changing ecosystem. </p>



<p>A developer warned that choosing the cheapest option may not always be the best decision, and suggested considering whatever technology you know best and whatever has the most batteries included. Other recommendations included Quarkus with Kotlin, Servlets without Spring, Ruby on Rails, and Go with Pocketbase. </p>



<p>Overall, there seems to be a consensus that sticking with what you know best is often the best option for quick iteration, and using a language with a large number of batteries included can help speed up development. However, some users caution that simplicity and cheapness may come at the expense of scalability and maintainability, and that it is important to choose a stack that can grow with the app if it becomes successful.</p>



<p>What do you think ?</p>
]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/which-boring-but-cheap-web-development-stack-to-use-in-2023.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/which-boring-but-cheap-web-development-stack-to-use-in-2023.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
		<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[Initializer for Laravel &#8211; A Visual Approach to Setting Up a New Laravel Project]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/initializer-for-laravel-a-visual-approach-to-setting-up-a-new-laravel-project.html" />

		<id>https://phpmagazine.net/?p=10646</id>
		<updated>2023-03-14T09:13:21Z</updated>
		<published>2023-03-24T16:30:00Z</published>
		<category scheme="https://phpmagazine.net" term="Laravel" /><category scheme="https://phpmagazine.net" term="automate installation" /><category scheme="https://phpmagazine.net" term="components" /><category scheme="https://phpmagazine.net" term="containers" /><category scheme="https://phpmagazine.net" term="customization options" /><category scheme="https://phpmagazine.net" term="customized" /><category scheme="https://phpmagazine.net" term="docker-compose.yml" /><category scheme="https://phpmagazine.net" term="Documentation" /><category scheme="https://phpmagazine.net" term="first-party packages" /><category scheme="https://phpmagazine.net" term="Initializer for Laravel" /><category scheme="https://phpmagazine.net" term="Laravel developers" /><category scheme="https://phpmagazine.net" term="Laravel Sail" /><category scheme="https://phpmagazine.net" term="new Laravel project" /><category scheme="https://phpmagazine.net" term="online form" /><category scheme="https://phpmagazine.net" term="redis" /><category scheme="https://phpmagazine.net" term="setting up" /><category scheme="https://phpmagazine.net" term="Spring Initialzr" /><category scheme="https://phpmagazine.net" term="User-friendly" /><category scheme="https://phpmagazine.net" term="visual approach" /><category scheme="https://phpmagazine.net" term="zip archive" />
		<summary type="html"><![CDATA[Initializer for Laravel is a tool that provides a visual, streamlined approach to setting up a new Laravel project. The tool offers an online form that allows users to select the components they want for their Laravel application. Once the form is filled out, users can download a zip archive that contains their customized Laravel [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/initializer-for-laravel-a-visual-approach-to-setting-up-a-new-laravel-project.html"><![CDATA[
<p>Initializer for Laravel is a tool that provides a visual, streamlined approach to setting up a new Laravel project. The tool offers an online form that allows users to select the components they want for their Laravel application. Once the form is filled out, users can download a zip archive that contains their customized Laravel application.</p>



<p>The tool leverages the power of containers to automate the installation of software components. For example, if a user selects Redis as a cache for their project, the tool will automatically enable the service in the generated docker-compose.yml file. When the application is initialized, Redis will be running on the user&#8217;s computer inside a container.</p>



<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" src="https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-1024x767.png" alt="" class="wp-image-10639" width="1024" height="767" srcset="https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-1024x767.png 1024w, https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-300x225.png 300w, https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-768x576.png 768w, https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-150x112.png 150w, https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-696x522.png 696w, https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-1068x800.png 1068w, https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-560x420.png 560w, https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-80x60.png 80w, https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel-265x198.png 265w, https://phpmagazine.net/wp-content/uploads/2023/03/initializer-for-laravel.png 1185w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Initializer for Laravel requires users to have Docker and docker-compose installed and running. However, the tool uses Laravel Sail and its services to make the setup as easy as possible. The Sail tag indicates that an option has a corresponding software component, which would normally need to be manually installed on the user&#8217;s system.</p>



<p>The tool offers a range of customization options for users, including the ability to include or exclude specific components, as well as links to more detailed documentation on each component.</p>



<p>Initializer for Laravel was inspired by the Spring Initialzr, which generates similar archives for applications using the Spring Framework. However, Initializer for Laravel focuses more closely on first-party packages.</p>



<p>Overall, Initializer for Laravel offers a user-friendly, efficient approach to setting up a new Laravel project. With its visual interface and powerful automation capabilities, it is a valuable tool for Laravel developers of all levels.</p>



<p>More information <a href="https://laravel.initializer.dev/">https://laravel.initializer.dev/</a></p>
]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/initializer-for-laravel-a-visual-approach-to-setting-up-a-new-laravel-project.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/initializer-for-laravel-a-visual-approach-to-setting-up-a-new-laravel-project.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
		<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[PHP Coding Puzzle 10  : Sudoku Game]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/php-coding-puzzle-10-sudoku-game.html" />

		<id>https://phpmagazine.net/?p=9975</id>
		<updated>2023-03-10T16:16:08Z</updated>
		<published>2023-03-24T13:30:00Z</published>
		<category scheme="https://phpmagazine.net" term="PHP Coding Puzzles" /><category scheme="https://phpmagazine.net" term="algorithm" /><category scheme="https://phpmagazine.net" term="Array" /><category scheme="https://phpmagazine.net" term="backtracking" /><category scheme="https://phpmagazine.net" term="constraint satisfaction" /><category scheme="https://phpmagazine.net" term="game" /><category scheme="https://phpmagazine.net" term="Logic" /><category scheme="https://phpmagazine.net" term="matrix" /><category scheme="https://phpmagazine.net" term="PHP" /><category scheme="https://phpmagazine.net" term="puzzle" /><category scheme="https://phpmagazine.net" term="recursion" /><category scheme="https://phpmagazine.net" term="Sudoku" />
		<summary type="html"><![CDATA[Welcome to the 10th PHP Coding Puzzle ! The Sudoku Game The objective of Sudoku is to fill a 9&#215;9 grid with numbers so that each row, column, and 3&#215;3 sub-grid (or &#8220;box&#8221;) contains all of the digits from 1 to 9. To solve a Sudoku puzzle, you need to use logic and deduction to [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/php-coding-puzzle-10-sudoku-game.html"><![CDATA[
<p>Welcome to the 10th PHP Coding Puzzle !</p>



<p><strong>The Sudoku Game</strong></p>



<p>The objective of Sudoku is to fill a 9&#215;9 grid with numbers so that each row, column, and 3&#215;3 sub-grid (or &#8220;box&#8221;) contains all of the digits from 1 to 9.</p>



<p>To solve a Sudoku puzzle, you need to use logic and deduction to determine the correct numbers to fill in each cell of the grid. The puzzle starts with some cells already filled in, and your job is to fill in the remaining cells correctly.</p>



<p>Here&#8217;s an example of a partially filled-in Sudoku grid:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">5 3 _ | _ 7 _ | _ _ _
6 _ _ | 1 9 5 | _ _ _
_ 9 8 | _ _ _ | _ 6 _
------+-------+------
8 _ _ | _ 6 _ | _ _ 3
4 _ _ | 8 _ 3 | _ _ 1
7 _ _ | _ 2 _ | _ _ 6
------+-------+------
_ 6 _ | _ _ _ | 2 8 _
_ _ _ | 4 1 9 | _ _ 5
_ _ _ | _ 8 _ | _ 7 9</code></pre>



<p>To solve this puzzle, you would start by looking for cells that can only be filled with one number based on the numbers already filled in on the same row, column, and box. For example, in the first row, the only possible number for the third cell is 1, because the numbers 2, 4, 6, 8, and 9 are already in that row.</p>



<p>Once you have filled in all the cells that can only have one possible number, you can start looking for cells that have only two possible numbers, and use deduction to determine which one is correct.</p>



<p>You continue this process of deduction until you have filled in all the cells in the grid correctly.</p>



<p>There are many variations of Sudoku puzzles, including different grid sizes, shapes, and numbers of starting cells. However, the basic rules and solving techniques are the same for all variations.</p>



<p>To play Sudoku, you can either use a printed puzzle book or an online Sudoku game. There are also many Sudoku solver programs available that can help you solve difficult puzzles.</p>



<p>The solution is already available in the next page <img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Feel free to share with us your solution here in comments or Github.</p>


]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/php-coding-puzzle-10-sudoku-game.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/php-coding-puzzle-10-sudoku-game.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
		<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[PHP Design Patterns Game : The Adapter Pattern]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/php-design-patterns-game-the-adapter-pattern.html" />

		<id>https://phpmagazine.net/?p=10001</id>
		<updated>2023-03-10T17:00:06Z</updated>
		<published>2023-03-24T10:30:00Z</published>
		<category scheme="https://phpmagazine.net" term="Design Patterns" /><category scheme="https://phpmagazine.net" term="Adaptee" /><category scheme="https://phpmagazine.net" term="Adapter Pattern" /><category scheme="https://phpmagazine.net" term="Bridge Pattern" /><category scheme="https://phpmagazine.net" term="Class diagram" /><category scheme="https://phpmagazine.net" term="Client code" /><category scheme="https://phpmagazine.net" term="Code reusability" /><category scheme="https://phpmagazine.net" term="Compatibility" /><category scheme="https://phpmagazine.net" term="Concrete Adapter" /><category scheme="https://phpmagazine.net" term="Design patterns" /><category scheme="https://phpmagazine.net" term="Interoperability" /><category scheme="https://phpmagazine.net" term="Legacy code" /><category scheme="https://phpmagazine.net" term="New features" /><category scheme="https://phpmagazine.net" term="Object-oriented programming" /><category scheme="https://phpmagazine.net" term="PHP" /><category scheme="https://phpmagazine.net" term="Structural Pattern" /><category scheme="https://phpmagazine.net" term="Target interface" /><category scheme="https://phpmagazine.net" term="Wrapper Pattern" />
		<summary type="html"><![CDATA[Welcome to our series of articles on PHP Design Patterns Games! In this article, we&#8217;ll be exploring the Adapter Pattern. This structural pattern allows incompatible interfaces to work together by wrapping the interface of an existing class with a new interface. The Adapter Pattern can be useful in situations where you want to reuse existing [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/php-design-patterns-game-the-adapter-pattern.html"><![CDATA[
<p>Welcome to our series of articles on PHP Design Patterns Games! In this article, we&#8217;ll be exploring the Adapter Pattern. This structural pattern allows incompatible interfaces to work together by wrapping the interface of an existing class with a new interface. The Adapter Pattern can be useful in situations where you want to reuse existing code, but its interface doesn&#8217;t match the requirements of your current project.</p>



<p>In the context of game development, the Adapter Pattern can be used to make different game systems work together seamlessly. For example, let&#8217;s say you want to integrate a third-party library for handling input in your game. However, the library&#8217;s interface doesn&#8217;t match the input system used in your game. You can use the Adapter Pattern to create a wrapper class that maps the library&#8217;s interface to your game&#8217;s input system.</p>



<p>In this article, we&#8217;ll demonstrate how to use the Adapter Pattern in PHP to create an adapter that allows a game to work with different types of controllers, such as keyboard and joystick controllers. By the end of this article, you&#8217;ll have a solid understanding of how to use the Adapter Pattern to make different interfaces work together in your games.</p>



<h2 class="wp-block-heading">Adapter Pattern</h2>



<p>The Adapter pattern is a structural design pattern that allows incompatible interfaces to work together. In a game context, this pattern could be used to adapt different types of game controllers to work with a game that only supports a specific type of controller interface.</p>



<p>Let&#8217;s say we have a Game class that expects a controller object that implements a Controller interface:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">interface Controller {
    public function up();
    public function down();
    public function left();
    public function right();
    public function action();
}

class Game {
    private $controller;

    public function __construct(Controller $controller) {
        $this-&gt;controller = $controller;
    }

    public function play() {
        $this-&gt;controller-&gt;up();
        $this-&gt;controller-&gt;down();
        $this-&gt;controller-&gt;left();
        $this-&gt;controller-&gt;right();
        $this-&gt;controller-&gt;action();
    }
}</code></pre>



<p>Now let&#8217;s say we have two different types of controllers: a KeyboardController that implements the Controller interface, and a GamepadController that has a different interface:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">class KeyboardController implements Controller {
    public function up() {
        echo &quot;KeyboardController: up\n&quot;;
    }

    public function down() {
        echo &quot;KeyboardController: down\n&quot;;
    }

    public function left() {
        echo &quot;KeyboardController: left\n&quot;;
    }

    public function right() {
        echo &quot;KeyboardController: right\n&quot;;
    }

    public function action() {
        echo &quot;KeyboardController: action\n&quot;;
    }
}

class GamepadController {
    public function dpadUp() {
        echo &quot;GamepadController: dpadUp\n&quot;;
    }

    public function dpadDown() {
        echo &quot;GamepadController: dpadDown\n&quot;;
    }

    public function dpadLeft() {
        echo &quot;GamepadController: dpadLeft\n&quot;;
    }

    public function dpadRight() {
        echo &quot;GamepadController: dpadRight\n&quot;;
    }

    public function buttonA() {
        echo &quot;GamepadController: buttonA\n&quot;;
    }

    public function buttonB() {
        echo &quot;GamepadController: buttonB\n&quot;;
    }
}</code></pre>



<p>Since the Game class expects a Controller interface, we need to adapt the GamepadController to work with it. We can do this by creating an adapter class that implements the Controller interface and has a GamepadController object as a member:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">class GamepadControllerAdapter implements Controller {
    private $gamepadController;

    public function __construct(GamepadController $gamepadController) {
        $this-&gt;gamepadController = $gamepadController;
    }

    public function up() {
        $this-&gt;gamepadController-&gt;dpadUp();
    }

    public function down() {
        $this-&gt;gamepadController-&gt;dpadDown();
    }

    public function left() {
        $this-&gt;gamepadController-&gt;dpadLeft();
    }

    public function right() {
        $this-&gt;gamepadController-&gt;dpadRight();
    }

    public function action() {
        $this-&gt;gamepadController-&gt;buttonA();
    }
}</code></pre>



<p>Now we can create a Game object with a KeyboardController and a Game object with a GamepadControllerAdapter:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">$keyboardController = new KeyboardController();
$game = new Game($keyboardController);
$game-&gt;play();

$gamepadController = new GamepadController();
$gamepadControllerAdapter = new GamepadControllerAdapter($gamepadController);
$game2 = new Game($gamepadControllerAdapter);
$game2-&gt;play();</code></pre>



<p>This example demonstrates how the Adapter pattern can be used to adapt an incompatible interface to work with an existing interface.</p>



<p>In conclusion, the Adapter pattern provides a flexible and powerful way to make different interfaces work together seamlessly. By encapsulating the interface of an existing object within an Adapter object, the Adapter pattern allows us to use that object with other objects that would otherwise be incompatible. This makes it possible to integrate different components and systems, even if they were not designed to work together. </p>



<p>The Adapter pattern helps to increase the flexibility and modularity of your code, making it easier to maintain and extend over time. By applying the Adapter pattern, you can improve the reusability and interoperability of your software, which can help to reduce development costs and increase productivity. Overall, the Adapter pattern is a valuable tool for any software developer who wants to create robust and scalable applications that can adapt to changing requirements and environments.</p>
]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/php-design-patterns-game-the-adapter-pattern.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/php-design-patterns-game-the-adapter-pattern.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
		<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[The Frameworkless Movement: A Revolutionary Idea or a Recipe for Disaster?]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/the-frameworkless-movement-a-revolutionary-idea-or-a-recipe-for-disaster.html" />

		<id>https://phpmagazine.net/?p=10607</id>
		<updated>2023-03-13T14:52:30Z</updated>
		<published>2023-03-23T15:30:00Z</published>
		<category scheme="https://phpmagazine.net" term="PHP Frameworks" /><category scheme="https://phpmagazine.net" term="Business goals" /><category scheme="https://phpmagazine.net" term="community" /><category scheme="https://phpmagazine.net" term="Context" /><category scheme="https://phpmagazine.net" term="Developer skills" /><category scheme="https://phpmagazine.net" term="Development choices" /><category scheme="https://phpmagazine.net" term="Discussion" /><category scheme="https://phpmagazine.net" term="Feedback" /><category scheme="https://phpmagazine.net" term="frameworks" /><category scheme="https://phpmagazine.net" term="Libraries" /><category scheme="https://phpmagazine.net" term="Manifesto" /><category scheme="https://phpmagazine.net" term="Non-functional requirements" /><category scheme="https://phpmagazine.net" term="Responsibly" /><category scheme="https://phpmagazine.net" term="technical debt" /><category scheme="https://phpmagazine.net" term="Tradeoffs" /><category scheme="https://phpmagazine.net" term="user experience" /><category scheme="https://phpmagazine.net" term="Vanilla language" />
		<summary type="html"><![CDATA[Hey, do you know that there is a Frameworkless Movement ? It is a community-driven movement that promotes the development of web applications without the use of a traditional web framework. It advocates for a simpler and more lightweight approach to building web applications, without sacrificing functionality or scalability. The Frameworkless Movement is a community [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/the-frameworkless-movement-a-revolutionary-idea-or-a-recipe-for-disaster.html"><![CDATA[
<p>Hey, do you know that there is a Frameworkless Movement ? It is a community-driven movement that promotes the development of web applications without the use of a traditional web framework. It advocates for a simpler and more lightweight approach to building web applications, without sacrificing functionality or scalability.</p>



<p>The Frameworkless Movement is a community of developers who advocate for developing applications without using frameworks, not because they hate frameworks, but because they perceive the misuse of frameworks as a lack of knowledge regarding technical debt and the availability of alternatives given by the vanilla language or by dedicated libraries. </p>



<p>The group believes that every time a team uses a framework, it takes a risk that the tool may not provide any value after some time and can represent a major roadblock to change. The movement emphasizes that non-functional requirements like deadline, lifespan, budget, usability, future business scenarios, and domain-specific constraints should be the primary decision drivers for the architectural choices as well as for the implementation roadmap.</p>



<p>The Frameworkless Movement believes that frameworks are powerful tools that can help anyone learn how to code. However, the movement emphasizes that developers should understand how frameworks work, including their strengths and constraints, to make the right choice of a framework. Frameworkless means that the technological decision-making should be given the right importance, and the choice to develop a project or a single feature without dependence on a framework is a real possibility. </p>



<p>The entire context where the software will be developed and used, including the developers&#8217; skills, should be taken into account when deciding whether or not to use a framework. Finally, Frameworkless means that developers should not assume that writing software is a responsibility that can be delegated elsewhere and depend on other software (a library, for example) to solve a specific problem.</p>



<p>The <a href="https://github.com/frameworkless-movement/manifesto">Frameworkless Movement&#8217;s manifesto</a> is published on their GitHub repository and is open to modifications resulting from community conversations. The movement encourages sharing the manifesto and adding resources to their awesome list. The group emphasizes that every technical decision, including the choice of a framework, should be made considering every aspect of the context the software &#8220;lives&#8221; in, and therefore, everyone who works on the project, including non-developers, should be involved in the discussion.</p>



<p>What do you think, Is using a framework a sign of laziness or a smart development choice? </p>



<p>More information about the Frameworkless Movement at <a href="https://www.frameworklessmovement.org/">https://www.frameworklessmovement.org/</a></p>
]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/the-frameworkless-movement-a-revolutionary-idea-or-a-recipe-for-disaster.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/the-frameworkless-movement-a-revolutionary-idea-or-a-recipe-for-disaster.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
		<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[Laravel 10.4 Released: Exciting New Features]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/laravel-10-4-released-exciting-new-features.html" />

		<id>https://phpmagazine.net/?p=10878</id>
		<updated>2023-03-23T14:08:33Z</updated>
		<published>2023-03-23T14:08:30Z</published>
		<category scheme="https://phpmagazine.net" term="Laravel" /><category scheme="https://phpmagazine.net" term="File::json() method" /><category scheme="https://phpmagazine.net" term="HasMany to HasOne relationships" /><category scheme="https://phpmagazine.net" term="Laravel 10.4" /><category scheme="https://phpmagazine.net" term="Macroable method" /><category scheme="https://phpmagazine.net" term="MorphMany to MorphOne" /><category scheme="https://phpmagazine.net" term="PaginationInformation" /><category scheme="https://phpmagazine.net" term="PHP framework" /><category scheme="https://phpmagazine.net" term="Unsupported media type assertion" />
		<summary type="html"><![CDATA[The Laravel team has unveiled Laravel 10.4, packed with new features and improvements for the renowned PHP framework. In this article, we&#8217;ll provide a brief overview of the major new features. Before: After: Before: After: Macroable method for paginationInformation: Laravel 10.4 now allows developers to define a macro for paginationInformation, making it possible to customize [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/laravel-10-4-released-exciting-new-features.html"><![CDATA[
<p>The Laravel team has unveiled Laravel 10.4, packed with new features and improvements for the renowned PHP framework. In this article, we&#8217;ll provide a brief overview of the major new features.</p>



<ol class="wp-block-list">
<li><strong>File::json() method</strong>: Laravel 10.4 introduces the File::json() method, streamlining the process of retrieving JSON encoded data from a file. This simplifies reading JSON data and decoding it.</li>
</ol>



<p>Before:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">$contents = File::get(&#039;sample.json&#039;);
$data = json_decode($contents, true);</code></pre>



<p>After:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">$data = File::json(&#039;sample.json&#039;);</code></pre>



<ol class="wp-block-list" start="2">
<li><strong>Unsupported media type assertion</strong>: A new assertion helper for the 415 Unsupported Media Type response status code has been added, enabling easier testing of unsupported media types in API responses.</li>
</ol>



<pre class="wp-block-prismatic-blocks"><code class="language-">$response-&gt;assertUnsupportedMediaType();</code></pre>



<ol class="wp-block-list" start="3">
<li><strong>Converting HasMany to HasOne relationships</strong>: Laravel 10.4 simplifies the process of defining multiple relationships in your models by enabling the conversion of HasMany relationships to HasOne relationships, and MorphMany to MorphOne.</li>
</ol>



<p>Before:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">class User extends Model
{
    public function logins(): HasMany {
        return $this-&gt;hasMany(Login::class, &#039;some_id&#039;, &#039;the_other_id&#039;);
    }
    public function latestLogin(): HasOne {
        return $this-&gt;hasOne(Login::class, &#039;some_id&#039;, &#039;the_other_id&#039;)-&gt;latestOfMany();
    }
}</code></pre>



<p>After:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">class User extends Model
{
    public function logins(): HasMany {
        return $this-&gt;hasMany(Login::class, &#039;some_id&#039;, &#039;the_other_id&#039;);
    }
    public function latestLogin(): HasOne {
        return $this-&gt;logins()-&gt;one()-&gt;latestOfMany();
    }
}</code></pre>



<p><strong>Macroable method for paginationInformation</strong>:</p>



<p>Laravel 10.4 now allows developers to define a macro for paginationInformation, making it possible to customize pagination information without the need to extend all resources as a base resource.</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">class ResourceCollectionMixin
{
    public function paginationInformation(): Closure
    {
        return fn ($request, $paginated, $default) =&gt; collect($default)-&gt;mapWithKeysRecursively(fn ($item, $key) =&gt; [Str::camel($key) =&gt; $item])-&gt;toArray();
    }
}</code></pre>



<p>These new features, along with numerous fixes and enhancements, make Laravel 10.4 a substantial update to the framework. To learn more about the changes in Laravel 10.4, consult the <a href="https://github.com/laravel/framework/blob/7046e9bd5f5957f12865a8326385aaa2a57ff067/CHANGELOG.md#v1040-2023-03-17">changelog </a>and the comprehensive list of new features and updates on GitHub.</p>
]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/laravel-10-4-released-exciting-new-features.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/laravel-10-4-released-exciting-new-features.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
		<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[PHP Coding Puzzle 9: Word Ladder]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/php-coding-puzzle-9-word-ladder.html" />

		<id>https://phpmagazine.net/?p=9973</id>
		<updated>2023-03-10T16:15:40Z</updated>
		<published>2023-03-23T12:30:00Z</published>
		<category scheme="https://phpmagazine.net" term="PHP Coding Puzzles" /><category scheme="https://phpmagazine.net" term="adjacency list" /><category scheme="https://phpmagazine.net" term="algorithm" /><category scheme="https://phpmagazine.net" term="breadth-first search" /><category scheme="https://phpmagazine.net" term="graph theory" /><category scheme="https://phpmagazine.net" term="PHP" /><category scheme="https://phpmagazine.net" term="word ladder" />
		<summary type="html"><![CDATA[Welcome to the 9th PHP Coding Puzzle ! Word Ladder Game Game Description Word Ladder is a word game in which two players try to transform one word into another by changing one letter at a time, with each intermediate step being a valid word. For example, to transform the word &#8220;CAT&#8221; into the word [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/php-coding-puzzle-9-word-ladder.html"><![CDATA[
<p>Welcome to the 9th PHP Coding Puzzle !</p>



<h2 class="wp-block-heading">Word Ladder Game</h2>



<h3 class="wp-block-heading">Game Description</h3>



<p>Word Ladder is a word game in which two players try to transform one word into another by changing one letter at a time, with each intermediate step being a valid word. For example, to transform the word &#8220;CAT&#8221; into the word &#8220;DOG&#8221;, one possible word ladder is:</p>



<p>CAT -&gt; COT -&gt; DOT -&gt; DOG</p>



<p>Players take turns making a move. On each move, a player can change one letter of the word to create a new valid word. The first player who successfully transforms the starting word into the ending word wins the game.</p>



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



<p>Write a PHP function called <code>wordLadder</code> that allows two players to play a game of Word Ladder. The function should take two parameters: the starting word and the ending word.</p>



<p>The function should prompt the first player for their move (the new word to create), validate the move (the new word should be one letter different from the previous word and should be a valid English word), display the current state of the game, and switch to the second player if the move is valid.</p>



<p>The function should continue the game until one player successfully transforms the starting word into the ending word or no valid move can be made. The function should return the winning player (&#8216;Player 1&#8217; or &#8216;Player 2&#8217;) or &#8216;Tie&#8217; if the game is a tie.</p>



<p>The function should use a dictionary file to validate words. You can download a dictionary file from <a href="http://www.gutenberg.org/ebooks/29765">http://www.gutenberg.org/ebooks/29765</a>.</p>



<h3 class="wp-block-heading">Example Usage</h3>



<pre class="wp-block-prismatic-blocks"><code class="language-">$result = wordLadder(&#039;CAT&#039;, &#039;DOG&#039;);
if ($result == &#039;Tie&#039;) {
  echo &quot;It&#039;s a tie!\n&quot;;
} else {
  echo &quot;$result wins!\n&quot;;
}</code></pre>



<h3 class="wp-block-heading">Example Output</h3>



<pre class="wp-block-prismatic-blocks"><code class="language-">Player 1&#039;s turn. Enter a word: COT
CAT -&gt; COT
Player 2&#039;s turn. Enter a word: DOT
CAT -&gt; COT -&gt; DOT
Player 1&#039;s turn. Enter a word: DOG
Invalid move. Please try again.
Player 1&#039;s turn. Enter a word: FOT
Invalid move. Please try again.
Player 1&#039;s turn. Enter a word: COG
CAT -&gt; COT -&gt; COG
Player 1 wins!</code></pre>



<p>The solution is already available in the next page <img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Feel free to share with us your solution here in comments or Github.</p>


]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/php-coding-puzzle-9-word-ladder.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/php-coding-puzzle-9-word-ladder.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
		<entry>
		<author>
			<name>Hatem Ben Yacoub</name>
							<uri>http://hbyconsusltancy.com</uri>
						</author>

		<title type="html"><![CDATA[PHP Design Patterns Game : The Strategy Pattern]]></title>
		<link rel="alternate" type="text/html" href="https://phpmagazine.net/2023/03/php-design-patterns-game-the-strategy-pattern.html" />

		<id>https://phpmagazine.net/?p=9999</id>
		<updated>2023-03-10T16:51:18Z</updated>
		<published>2023-03-23T09:30:00Z</published>
		<category scheme="https://phpmagazine.net" term="Design Patterns" /><category scheme="https://phpmagazine.net" term="Behavioral design pattern" /><category scheme="https://phpmagazine.net" term="code reuse" /><category scheme="https://phpmagazine.net" term="encapsulate a family of algorithms" /><category scheme="https://phpmagazine.net" term="interchangeable" /><category scheme="https://phpmagazine.net" term="Object-oriented programming" /><category scheme="https://phpmagazine.net" term="Polymorphism" /><category scheme="https://phpmagazine.net" term="strategy pattern" />
		<summary type="html"><![CDATA[Welcome to our new series of articles, PHP Design Patterns Games! In this article, we will explore the Strategy Pattern, which is a behavioral design pattern that enables an object, called the context, to change its behavior dynamically by selecting a suitable algorithm from a group of algorithms. This allows the context to vary its [&#8230;]]]></summary>

					<content type="html" xml:base="https://phpmagazine.net/2023/03/php-design-patterns-game-the-strategy-pattern.html"><![CDATA[
<p>Welcome to our new series of articles, PHP Design Patterns Games! In this article, we will explore the Strategy Pattern, which is a behavioral design pattern that enables an object, called the context, to change its behavior dynamically by selecting a suitable algorithm from a group of algorithms. This allows the context to vary its behavior without the need to change its implementation. We will demonstrate how to use the Strategy Pattern to implement different strategies in a game where the player can choose from different characters with different abilities.</p>



<h2 class="wp-block-heading">Strategy Pattern</h2>



<p>The Strategy pattern is a behavioral pattern that allows objects to change their behavior dynamically at runtime by encapsulating a family of algorithms and making them interchangeable. In other words, it enables the selection of an algorithm at runtime depending on the context.</p>



<p>Let&#8217;s consider a simple game where the player can choose from different characters with different abilities. For example, we have a knight, a wizard, and an archer. Each character has a unique set of abilities that can be used during the game.</p>



<p>To implement the Strategy pattern in this game, we can create an interface called <code>CharacterAbility</code> that defines a common method called <code>useAbility()</code>. This method will be implemented differently for each character class that we have. Here&#8217;s an example of the <code>CharacterAbility</code> interface:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">interface CharacterAbility {
    public function useAbility();
}</code></pre>



<p>Next, we can create different character classes, each implementing the <code>CharacterAbility</code> interface with their own implementation of the <code>useAbility()</code> method. For example, we can create the <code>Knight</code> class as follows:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">class Knight implements CharacterAbility {
    public function useAbility() {
        // Implement the knight&#039;s ability here
    }
}</code></pre>



<p>Similarly, we can create the <code>Wizard</code> and <code>Archer</code> classes with their own implementation of the <code>useAbility()</code> method.</p>



<p>Now, let&#8217;s say the player has selected a character, and we need to use their ability during the game. We can create a <code>Game</code> class that will receive the selected character as a parameter and use their ability during the game. However, we don&#8217;t want to hardcode the ability inside the <code>Game</code> class because we want to make it interchangeable. This is where the Strategy pattern comes in.</p>



<p>We can create another interface called <code>AbilityStrategy</code> that will define the <code>useAbility()</code> method, which takes the character object as a parameter. This interface will be implemented by different strategy classes, each representing a specific ability of the character. For example, we can create the <code>KnightAbilityStrategy</code> class as follows:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">class KnightAbilityStrategy implements AbilityStrategy {
    public function useAbility($character) {
        $character-&gt;useAbility(); // Use the knight&#039;s ability
    }
}</code></pre>



<p>Similarly, we can create the <code>WizardAbilityStrategy</code> and <code>ArcherAbilityStrategy</code> classes with their own implementation of the <code>useAbility()</code> method.</p>



<p>Finally, in the <code>Game</code> class, we can set the ability strategy based on the selected character. For example:</p>



<pre class="wp-block-prismatic-blocks"><code class="language-">class Game {
    private $abilityStrategy;
    
    public function setAbilityStrategy($character) {
        if ($character instanceof Knight) {
            $this-&gt;abilityStrategy = new KnightAbilityStrategy();
        } else if ($character instanceof Wizard) {
            $this-&gt;abilityStrategy = new WizardAbilityStrategy();
        } else if ($character instanceof Archer) {
            $this-&gt;abilityStrategy = new ArcherAbilityStrategy();
        }
    }
    
    public function useAbility() {
        $this-&gt;abilityStrategy-&gt;useAbility($character);
    }
}</code></pre>



<p>Now, whenever the player selects a character, we can set the ability strategy accordingly using the <code>setAbilityStrategy()</code> method, and the <code>useAbility()</code> method will call the correct ability based on the selected character. This way, we can make the abilities interchangeable without modifying the <code>Game</code> class.</p>



<p>In conclusion, the Strategy pattern allows us to encapsulate different algorithms or behaviors and make them interchangeable at runtime, without affecting the client code. This makes our code more flexible and maintainable, and it is particularly useful in games where different characters have different abilities that can be used in different contexts.</p>
]]></content>
		
					<link rel="replies" type="text/html" href="https://phpmagazine.net/2023/03/php-design-patterns-game-the-strategy-pattern.html#comments" thr:count="0" />
			<link rel="replies" type="application/atom+xml" href="https://phpmagazine.net/2023/03/php-design-patterns-game-the-strategy-pattern.html/feed/atom" thr:count="0" />
			<thr:total>0</thr:total>
			</entry>
	</feed>

<!-- plugin=object-cache-pro client=phpredis metric#hits=3542 metric#misses=10 metric#hit-ratio=99.7 metric#bytes=1564960 metric#prefetches=79 metric#store-reads=53 metric#store-writes=3 metric#store-hits=227 metric#store-misses=3 metric#sql-queries=1 metric#ms-total=350.80 metric#ms-cache=12.76 metric#ms-cache-avg=0.2320 metric#ms-cache-ratio=3.6 -->
