PHP Directory

Blogs

  • Building Testable Applications

  • Where are you? Implementing geolocation with GeoCoder PHP

    GeoCoder PHP

    The beauty of SitePoint, to me, is that you can get inspired to try something or be told about some cool project out there. The internet is simply too big for one person to scout out on their own. GeoCoder was one of those for me. I had never heard about it and came across it on the authors Trello board.

    I love working with maps and geographic information and I use (reverse) geocoding heavily for a project I did for a client; CableTracks. We actually use a paid service for this although not for everything. The paid results hold much more information than you get from free services. I found out that GeoCoder PHP actually is what I was missing for the integration of various services that we use.

    GeoCoder PHP provides: “an abstraction layer for geocoding manipulations”. The library is split into three parts: an HttpAdapter for doing requests, several geocoding Providers and various Formatter/Dumpers to do output formatting.

    Installation

    Installation of GeoCoder is most easily done using composer. Add the following to your composer.json:

    {
        "require": {
            "willdurand/geocoder": "@stable"
        }
    }

    Or get one of the archives from the GeoCoder PHP website.

    Continue reading %Where are you? Implementing geolocation with GeoCoder PHP%

  • When Rocks Falter

    I've never been a rock. I'm about as passionate as someone can be when I choose to do something. Unfortunately that means I tend to throw myself (my raw unadulterated self) at my interests. It's just who I am and who I've always been. This has positives and negatives associated with it (especially from a personal perspective).

    Throwing yourself at a passion has enormous benefits. You get a lot done, you can truly touch people's lives. You can really change the world. But you also take on a lot of risk. Putting yourself out there is the easiest way to get burned. When you're passionate, it's hard to not take things emotionally. It's hard to not care. After all, caring is where you draw your power from.

    I have always been held up by those that I knew were rocks. I always leaned on people who I know weren't just abiding a flight-of-fancy, but who could wear the tide. But what happens when you start to see those who you thought were rocks, falter...?

    Read more »
  • Usability: Anchors everywhere

    After adding clickable anchor links to every headline I longed for more: Make it possible to reference every paragraph and list item on my blog posts.

    Adding IDs

    The first step was adding an id attribute to every tag I wanted to link. Doing that manually is a pain, so I had to get it automated.

    My idea was to take the ID of the previous headline and add some counting suffix. For example, the first paragraph following a headline with id="foo" would get id="foo-p1". Prefixing the number with a letter (p for paragraph, h for heading, l for list item) is necessary to keep the IDs stable when regenerating them. Adding a new list item does for example not change the numbers of the paragraphs.

    The resulting code can be found in my pastebin: add ID attributes to all content tags of an xhtml page .

    Showing clickable links

    I followed the same pattern as before by adding empty anchor links at the end of a content tag:

    I gave the content tags a position: relative and the anchor link tags position: absolute so I could put them at a position relative to the content tag.

    Then they got a left position of -3ex and a padding of 3ex to keep them aligned to the content tag:

    *[id] {
        /* make anchor links positionable */
        position: relative;
    }
    
    /* show IDs for anchors */
    *[id]:hover > a.anchorlink:before {
        content: "\00B6";/* pilcrow */
        color: #888;
        font-size: smaller;
    }
    a.anchorlink {
        text-decoration: none;
        margin-left: 0.5em;
        font-size: smaller;
        position: absolute;
        top: 0px;
        left: -3ex;
        padding-right: 3ex;
        height: 100%;
    }

    Demo

  • Interview with Ross Tuck

    Twitter: @rosstuck

    Show Notes

  • In Defense Of Self-Publishing

    Back in 2009, I signed a contract to write a book. The book was published by php|architect, and was called The PHP Playbook. It was published in 2011. Being my first book, I assumed that going the route of a traditional publisher made sense, but after publishing a book this way, I opted for self-publishing […]
  • Educate, Don't Mediate

    Recently, there has been a spout of attention about how to deal with eval(base64_decode("blah")); style attacks. A number of posts about "The Dreaded eval(base64_decode()) - And how to protect your site and visitors" have appeared lately. They have been suggesting how to mitigate the attacks. This is downright bad.
    Read more »
  • Drupal 8 Hooks and the Symfony Event Dispatcher

    With the incorporation of many Symfony components into Drupal in its 8th version, we are seeing a shift away from many Drupalisms towards more modern PHP architectural decisions. For example, the both loved and hated hook system is getting slowly replaced. Plugins and annotations are taking away much of the need for info hooks and the Symfony Event Dispatcher component is replacing some of the invoked hooks. Although they remain strong in Drupal 8, it’s very possible that with Drupal 9 (or maybe 10) hooks will be completely removed.

    In this article we are going to primarily look at how the Symfony Event Dispatcher component works in Drupal. Additionally, we will see also how to invoke and then implement a hook in Drupal 8 to achieve similar goals as with the former.

    To follow along or to get quickly started, you can find all the code we work with here in this repository. You can just install the module and you are good to go. The version of Drupal 8 used is the first BETA release so it’s preferable to use that one to ensure compatibility. Alpha 15 should also work just fine. Let’s dive in.

    What is the Event Dispatcher component?

    A very good definition of the Event Dispatcher component can be found on the Symfony website:

    The EventDispatcher component provides tools that allow your application components to communicate with each other by dispatching events and listening to them.

    I recommend reading up on that documentation to better understand the principles behind the event dispatcher. You will get a good introduction to how it works in Symfony so we will not cover that here. Rather, we will see an example of how you can use it in Drupal 8.

    Continue reading %Drupal 8 Hooks and the Symfony Event Dispatcher%

  • From idea to production instantly

    I know you had it often: you had this crazy idea and worked out a quick prototype and want to share it with the world. So you start up your personal VMS or a VM in the cloud, push your code there and you're happy, all is working.

    But this prototype, just like all the other prototypes, grows into a heavily used and very important tool and before you know it you're pushing updates a couple of times a day to production. This still sounds familiar?

    And when you're really facing an important update of your code base, all of a sudden you need to spend additional attention to things like heartbleed, shellshock or any other important security exploit that requires immediate updates of all your servers and systems.

    Coming from a systems engineering role in the early days of the millennium this shouldn't be a problem for me, but I've got such a passion for development I don't care anymore about everything underneath my code. As long as things are running my way, I rather opt for a full platform as a service (PaaS) than for an infrastructure as a service (IaaS).

    What do I use? Microsoft Azure. Yes, I run most of my PHP on Windows, who would have thought that! The reason is simple. If I have my code on GitHub it takes me 5 minutes to create a new instance, hook up my GitHub account and have my application up-and-running in a cloud environment where I don't need to worry about the security of everything below my application. As long I've ensured my application is secured, I know I'm safe. Microsoft Azure will take care of all security below my application.

    And I love continuous delivery, so I hook up my Jenkins-CI to my GitHub repo, run my tests and other build steps before the code is merged into a release branch, the branch I hooked up to my Microsoft Azure account so the moment all build steps pass successfully, the code is pushed to production in one, swift transaction.

    I love being a developer and I hate spending time patching and updating the platforms that I need to support my applications. Microsoft Azure offers me an easy, affordable and stress-free environment to deploy and maintain my applications in a continuous way. Sign up for the free trial and try it yourself if you don't believe me.
    Come and see me at ZendCon where I will be talking about "the continuous PHP pipeline" where I go deeper into the whole flow from idea to production and beyond. And if needed, I will be able to do a live demo getting a scalable solution instantly without the hassle of maintenance. Yes, I love releasing code 5 minutes before I leave on a holiday. And I love you to experience it too.

  • Book Review: Practical Design Patterns in PHP

    This review of Brandon Savage’s Practical Design Patterns in PHP will include my own opinions and impressions about both the book, and the aspect of self-publishing.

    Design patterns are about common solutions to common problems.
    … they are concepts, not blueprints; ideas, not finished designs.
    … they add clarity to an otherwise difficult situation.
    - Brandon Savage, Practical Design Patterns in PHP

    Content

    Starting out on a lighter, introductory note, Brandon explains the need for frameworks, argues that OOP doesn’t mean just wrapping stuff in classes, and goes into detail on why design patterns appear to be difficult to learn. He then continues with a mild introduction into SOLID principles, and lays the groundwork for more advanced concepts. He explains why each SOLID rule is important and what it means. Given that SOLID is a well established software design principle, it’s only natural to compare it against every pattern that’s about to be explained in the book. Or, to be more precise, to assess how well each pattern respects the SOLID principles, while providing the developer with its intended functionality.

    If I express matters in Dreyfus model terminology, he claims the book is there to turn a novice into a competent level developer without subjecting them to advanced beginner mistakes when, in fact, such an approach to learning is not entirely possible - that’s just not how the human knowledge acquisition process works.

    Continue reading %Book Review: Practical Design Patterns in PHP%

:: Our Favorites

Featured Sites Using PHP

>Atlanta Real Estate