PHP Directory


  • Upgrading Sylius the TDD Way: Exploring Behat

  • Upgrading Sylius the TDD Way: Exploring PhpSpec

    The post on developing and testing new Sylius features was an introduction to the three types of tests that are used in Sylius - PHPUnit, Phpspec and Behat.

    In this part, we'll extend some core classes to indicate color-coded inventory status. First, we'll deal with the back end part. In a followup post, we'll use Behat and test the visual changes. Please follow the instructions in the previous post to get a working instance up and running.

    Sylius logo

    Sylius has an excellent inventory management solution. However, there's always some room for a tweak or two. If you look at the list of products (admin/products) there's no information about available stock. Looking at the variants of a product, we see inventory data, whether it's tracked or not, and the number of total items in stock, if tracked. It would be nice to see that kind of information on the product listing page, too. In addition, the stock level is all or nothing - for example, a green label says "10 Available on hand" or red "0 Available on hand". How about something in-between, say a yellow label for "3 Available on hand" to indicate that stock is low? Then, the store admin can decide it's time to replenish.

    Extend ProductVariant and Product models

    We want to extend the behavior of both the ProductVariant and Product models provided by Sylius, so we can see extra information on stock availability when viewing products.

    Create a Bundle

    First, we create the src/AppBundle/AppBundle.php file and register it in app/AppKernel.php.

    // src/AppBundle/AppBundle.php
    namespace AppBundle;
    use Symfony\Component\HttpKernel\Bundle\Bundle;
    class AppBundle extends Bundle
    // app/AppKernel.php
    public function registerBundles()
        $bundles = [
            // ...
            new AppBundle\AppBundle(),

    Next, we inform the autoloader about the new bundle by adding it to the "autoload" section of composer.json.

    Continue reading %Upgrading Sylius the TDD Way: Exploring PhpSpec%

  • Functional Programming with Phunkie: Parser Combinators in PHP

    Phunkie is a library with functional structures for PHP. In this tutorial, Phunkie creator Marcello Duarte, head of training at Inviqa, explains how to create Parser combinators using the functional library. This post first appeared on the Inviqa blog, and was republished here with their permission.

    Phunkie logo

    Learning functional programming

    Functional programming really matters. Pure functions (or functions with no side effect) are the perfect units of behaviour because we can rely on them to build larger and more complex systems. The greatness of functional programming relies on this power of composability.

    That’s something I first came to believe back in the days of my licentiate degree on Computing for Management, during a semester in AI with Lisp. My course curriculum was mostly focused on C/C++, therefore I had to stay focused on where the skills demand was.

    Thankfully, I’ve been able to reignite my love of studying functional programming here at Inviqa where we’re delivering more and more projects based on Scala, the general purpose programming language.

    I’ve read "the red book" about three times (the Chiusano & Bjarnason one, not the Vaughn Vernon’s one). I took all the Martin Odersky’s Coursera courses, and I spent hours of my weekends watching videos and reading papers.

    And I set myself a challenge: to do with functional programming what I did when I was learning TDD and created PHPSpec (a BDD testing and design tool for PHP developers) to help me learn; I decided to write my own functional programming dialect in PHP. And so Phunkie was born!

    Now over to you. Learning functional programming means immersing yourself in a new paradigm, which can be challenging. It requires a totally different mindset for approaching problems.

    So, by the time you can use functional programming to solve real-world problems, you’ll have spent hours grasping the new thinking or getting clued-up on the theory.

    In this tutorial, my aim is to help fast-track your journey by going over my implementation of Hutton & Meijer’s Monadic Parser Combinators. Hopefully you will be able to see both the thinking and the usefulness of functional programming.

    And, by using Phunkie, you can eliminate the need to learn Haskell to understand the topic. All you should need is some familiarity with PHP.

    So let’s get started!

    Continue reading %Functional Programming with Phunkie: Parser Combinators in PHP%

  • PHP and immutability: objects and generalisation - part three

  • Atlas: A Data Mapper For Your Persistence Model

    Speaker: Paul M. Jones @pmjones Atlas lets you build an OO model of your SQL tables and relationships. You can use it at the start of your project for basic CRUD operations. As you begin to need simple behaviors in your application, you can add them to the Record and RecordSet persistence model objects. Finally, …

    The post Atlas: A Data Mapper For Your Persistence Model appeared first on Nomad PHP.

  • “A False Sense of Simplicity”

    These year-old posts from Piotr Solnica are about Ruby On Rails …

    … but the experiences related therein should be valuable to anyone using or building a full-stack PHP framework. (I can imagine it applying to CMSes as well.)

    Does this story from Piotr remind you of any framework-based project you’ve worked on in PHP?

    Once, I joined an existing project. It was a huuuuge app which was running an on-line shopping community website. Complicated sales model, complicated promotions, complicated product setups, coupons, user groups, messages – it had it all. I joined them to help ship a few new features. One of my early tasks was to … add a link to something on some page. It took me few days to add this stupid link. Why? The app was a big ball of complex domain logic scattered across multiple layers with view templates so complicated, it wasn’t even simple to find the right template where the link was supposed to be added. Since I needed some data in order to create that link, it wasn’t obvious how I should get it. There was a lack of internal application APIs and relying on ActiveRecord exclusively made it extremely difficult.

    I’ve consulted on projects like that more than once. Indeed, the posts might well have been subtitled “The Perils of Convenience-Oriented Development”:

    People are attracted by Rails because it gives you a false sense of simplicity, whereas what really happens is that complexity is being hidden by convenient interfaces.

    Read both of the posts, and see if you can relate. They just reinforce to me that this is what to expect when you embed your domain logic in your user interface logic.

    Remember: with server-side web-based applications, the user interface is the HTTP request and response. Any code that reads from the request, or that writes to the response, is part of the user interface. Putting your domain logic in the user interface is convenient to start with, but as soon as things become even a little bit complex, that “convenience” becomes a burden.

  • PHP 7.2 Release Date and Managers Being Chosen - 7 Minutes Lately in PHP podcast episode 82

    By Manuel Lemos
    PHP 7.2 development is reaching to the alpha stage in June, hopefully to have a final version released later this year. So for now the release managers are being chosen, so they can start preparing to work on each alpha, beta and release candidate version.

    This was one of the main topics discussed by Manuel Lemos and Arturs Sosins on the episode 82 of the Lately in PHP podcast.

    In this episode they also talked about other proposals for PHP cache keys for stream wrappers, serialized object validation with is_string, type variants, let range() return a generator, named parameters again, and removing the need for ; on the end of the line .

    They also commented on an article about promoting Open Source projects using data mining and business intelligence to boost SEO factors, and using OpenID Connect protocol to implement single sign-on social login systems.

    This article also contains a podcast summary as a text transcript and a 5 minute video of the summary.

    Listen to the podcast, or watch the hangout video, or read the transcript text to learn more about these interesting PHP topics.
  • Interview with Adam Englander

    The post Interview with Adam Englander appeared first on Voices of the ElePHPant.

  • What I Learned About Testing WhileWalking Uphill Both Ways In The Snow

    July US Presented by Chris Hartjes (@grmpyprogrammer) Date: July 20, 2017 Time: 20:00 CDT 18:00 PDT, 3:00 CEST (July 21), 2:00 BST (July 21) Not sure of the time in your area? Check it on Back when I was learning about how to test PHP code, I had to walk both ways uphill in …

    The post What I Learned About Testing While
    Walking Uphill Both Ways In The Snow
    appeared first on Nomad PHP.

  • How Privileged Are Programmers? Are You a John, Too?

    John was a developer. To be specific, he was a young, white, straight, young, self-taught developer. He wasn't rare, but he was special. John grew up with a couple parents, who paid for everything he needed. John regularly filled his belly, with the finest food his family could provide. John got every toy he asked for, once he learn that asking for 3 toys was a good way to get at least 1 toy.

    A spoiled child with many toys

    John got average grades, but it was ok because [according to mum]; "he's just bored of schooling, and too clever". He walked right out of high-school and into a programming job. The pay wasn't great; only enough for a small apartment and modest groceries [for one]. In time he'd earn more.

    Over the years, John quickly got bored of programming. He loved the thought of the career, but it was all so boring. He moved jobs every year or so, and only then when his idiot bosses stopped seeing how much he mattered to their company.

    Person leaving a job happily

    It was just as well, because most of the other developers he worked with were idiots too. Did they even know how to program? All they wanted to do was talk and ask questions and they weren't as interested in John's work as intelligent people should be. He did once work with a girl developer, though. She was so pretty for a programmer. I mean, if you can call CSS and html programming.

    Illustration of a female web designer

    I am angry.

    For the longest time, I was John. I thought every boring task beneath me, every other developer mediocre at best. I was my own hero, and my mom was right (albeit annoying) that I was brilliant. If only those around me could see this.

    Continue reading %How Privileged Are Programmers? Are You a John, Too?%

:: Our Favorites

Featured Sites Using PHP

>Atlanta Real Estate