Anna FilinaConverting a Joined Resultset Into a Hierarchy (2.7.2015, 20:45 UTC)

I needed nested resultsets in some projects. I’ve seen a lot of StackOverflow chatter which essentially pointed people towards Doctrine or Propel ORMs, which was overkill when you didn’t want mapping or even model classes.

I built a very small function that will transform joined results into a hierarchy. This avoids using heavy ORMs if you just need this small feature. It’s 74 lines of code and really easy to use. Since it’s open source, feel free to improve it.

You’d give it a statement like this:

SELECT album.id AS albums__id, photo.id AS albums__photos__id
FROM album
LEFT JOIN photo ON photo.album_id = album.id;

and it will produce something this:

stdClass Object
    (
        [albums] => Array
            (
                [1] => stdClass Object
                    (
                        [id] => 1
                        [photos] => Array
                            (
                                [1] => stdClass Object
                                    (
                                        [id] => 1
                                    )
                            )
                    )
            )
    )

Optionally, you can replace stdClass by your own classes with just a single parameter.

It’s on my GitHub. All the documentation is there.

Link
Brandon SavageWhy we program (2.7.2015, 13:00 UTC)

As programmers, we don’t really make anything. Oh sure, we write code, design applications, and create open source libraries. Yet we so willingly refactor away our hard work, delete and close down apps, and at the end of the day, really have little tangible outcome from the work that we do. Unlike a furniture maker […]

The post Why we program appeared first on BrandonSavage.net.

Link
PHP ClassesMySQL Extension, Going, Going, almost Gone (2.7.2015, 08:06 UTC)
By Dave Smith
When the warnings change from "the extension may go away" to "the extension will go away", things just became serious. For some of us, the race is on to keep our projects from collapsing.

Read this article to learn about a method to analyze your PHP code and find functions and extensions that are being deprecated, as well a quick and easy solution to deal with the removal of the MySQL extension in PHP 7 or even sooner in your current hosting provider.
Link
Chuck BurgessCorrupted .git/config Files and Jenkins (1.7.2015, 21:27 UTC)
Link
SitePoint PHPCrawling and Searching Entire Domains with Diffbot (1.7.2015, 16:00 UTC)

In this tutorial, I’ll show you how to build a custom SitePoint search engine that far outdoes anything WordPress could ever put out. We’ll be using Diffbot as a service to extract structured data from SitePoint automatically, and this matching API client to do both the searching and crawling.

Diffbot logo

I’ll also be using my trusty Homestead Improved environment for a clean project, so I can experiment in a VM that’s dedicated to this project and this project alone.

What’s what?

To make a SitePoint search engine, we need to do the following:

  1. Build a Crawljob which will index and process the entire SitePoint.com domain and keep itself up to date with newly published content.
  2. Build a GUI for submitting search queries to the saved set produced by this crawljob. Searching is done via the Search API. We’ll do this in a followup post.

A Diffbot Crawljob does the following:

  1. It spiders a URL pattern for URLs. This does not mean processing - it means looking for links to process on all the pages it can find, starting from the domain you originally passed in as seed. For the difference between crawling and processing, see here.
  2. It processes the pages found on the spidered URLs with the designated API engine - for example, using Product API, it processes all products it found on Amazon.com and saves them into a structured database of items on offer.

Continue reading %Crawling and Searching Entire Domains with Diffbot%

Link
PHP ClassesOnline Boot Camp for Modernizing PHP Legacy Applications (1.7.2015, 04:01 UTC)
By Paul M. Jones
Over the years the recommended practices to develop PHP applications have evolved but applications developed in the past were not maintained and suffer with several problems for being what are usually called legacy applications.

Read this article to learn how you can participate in an online course to learn the best practices to modernize your legacy PHP applications.
Link
Nomad PHPProtected: NEPHP Logos (30.6.2015, 20:47 UTC)

There is no excerpt because this is a protected post.

The post Protected: NEPHP Logos appeared first on Nomad PHP.

Link
Paul M. JonesModernizing Serialized PHP Objects with class_alias() (30.6.2015, 14:14 UTC)

Several weeks ago, a correspondent presented a legacy situation that I’ve never had to deal with. He was working his way through Modernizing Legacy Applications in PHP, and realized the codebase was storing serialized PHP objects in a database. He couldn’t refactor the class names without seriously breaking the application.

I was carefully moving my classes to a PSR-0/4 structure when I found this. The application saves the output of serialize($shoppingCart) in a BLOB column, and unserializes it later to recreate the ShoppingCart object. The serialized object string looks like this:

O:12:"ShoppingCart":17:{s:13:"\00Basket\00items";a:25:{...}; ...}

See how the class name is embedded in the serialized string? If I rename the ShopppingCart class to PSR-0/4 namespace, then the old class won’t be found when the application tries to unserialize() the serialized representation. How can I begin refactoring this without breaking the whole application?

Before I was able to reply, my correspondent ended up changing the serialization strategy to use JSON, which was a rather large change. It ended up well, but it turns out there is a less intrusive solution: class_alias().

If you’re in a serialized situation, and you need to change a class name, you can use a class_alias() to point the old class name to the new one. (Call class_alias() early in execution, probably before you register your autoloader.) You can then rename and move the class according to PSR-0/4 rules, and PHP will handle the rest for you.

For example, if you renamed ShoppingCart to Domain\Orders\Cart, you might do this:

class_alias('ShoppingCart', 'Domain\Orders\Cart');

Now when you call unserialize($shoppingCart) to create an object, PHP will create it as an instance of Domain\Orders\Cart instead of ShoppingCart. Re-serialized representations of the recreated object will retain the new class name, not the old one: O:18:"Domain\Orders\Cart":....

As soon as there are no more serialized representations using the old class name, you can remove the class_alias() call entirely.


Afterword

Are you stuck with a legacy codebase? Are you having a hard time getting started on modernizing it? If so, I have put together an online weekend “boot camp” where we go through the entire modernization process, from basic prerequisities at the beginning to setting up a DI container at the end. After that end-to-end study of the steps involved, you should be able to jump-start your own modernizing project much more easily.

The 8-hour camp will combine lecture and “live” coding with examples. In particular, there will be plenty of opportunity for you to get answers specific to your own modernizing situation, and to chat with other attendees.

The two-day camp will be on Sat 11 July and Sun 12 July. Each day will run from 12 noon to 4pm (US Central Daylight), with time for breaks built in. That makes it 10am-2pm for Pacific time zone attendees, and 1-5pm for Eastern, which should be convenient for almost everyone.

With your ticket to attend the boot camp, you get:

  • Two days of online boot camp, four hours each
  • A review of the entire modernization process from beginning to end
  • A bonus recording of the camp
  • For $399

This might be the only time I lead this kind of boot camp, so get your ticket while there are still seats available!

Link
Cal EvansInterview with Sammy K. Powers (30.6.2015, 05:00 UTC) Link
PHP ClassesReview: Modernizing Legacy Applications In PHP (30.6.2015, 03:58 UTC)
Modernizing Legacy Applications In PHP
Title
Reviewer
Samuel Adeshina
Category
PHP books
Publisher
Leanpub
Author
Paul M. Jones
Summary
After going through this book, I discovered that it is not just apps that were built ‘over a decade ago’ that deserves to be called legacy applications.

Many of the apps we write today also have some of the bad features which makes them worthy to be termed a ‘legacy application’. I felt guilty, because I use a lot of these bad features in my day to day PHP development process, even when I claim I am developing object oriented applications and I believe I am not alone.

I strongly recommend this material to the PHP professionals out there, there are a lot of things we ‘claim’ and ‘think’ we are doing right, just read this book and see for yourself.

Code maintenance engineers from other spheres or areas of software development would also find this book very intrinsic, as it provides references and links to external materials that would help you learn and know more.

This book is a very bright light, that shows us a lot of places and instances where we get it all wrong when it comes to developing with PHP, and also provides how to make them right. Software Maintenance Engineers would find this book very useful, because it laid out a step by step, and chapter by chapter introduction into code maintenance and optimization.
Link
LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP