Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthias Noback:
Objects should be constructed in one go
Jul 17, 2018 @ 14:21:04

In a new post to his site Matthias Noback makes an interesting suggestion about working with objects in PHP: that they should all be made in one, and only one, place.

Consider the following rule: "When you create an object, it should be complete, consistent and valid in one go."

It is derived from the more general principle that it should not be possible for an object to exist in an inconsistent state. I think this is a very important rule, one that will gradually lead everyone from the swamps of those dreaded "anemic" domain models. However, the question still remains: what does all of this mean?

He shares an example of an object (GeoLocation) that can be created with only the latitude value but points out that this leaves it in an invalid state. He updates this example to show a more complete implementation, one that prevents an object with partial setup from happening. He then talks about the aggregation of child entities and a "paper" metaphor. This metaphor - imagining a "paper purchase order" - helps him wrap his head around the structure of the objects and how they interact.

tagged: object creation construct child aggregate tutorial

Link: https://matthiasnoback.nl/2018/07/objects-should-be-constructed-in-one-go/

php[architect]:
Artisanal: Project Creation
May 18, 2017 @ 16:59:12

On the php[architect] site they've shared an article originally from the May 2016 issue of the magazine by Joe Ferguson: Artisanal: Project Creation (also released as a free PDF).

Every developer has a set way of starting a new project. Most frameworks have a linear path to getting started, and Laravel is no exception. With a few commands, you can quickly get started configuring routes, writing controllers, and saving data in a database.

In the article Joe walks you through the tools and commands that come with the Laravel framework to make getting up and running quickly easier. He covers tools available for both the backend and frontend functionality as well as testing (mentioning Dusk), routing, middleware groups and database functionality.

tagged: phparchitect magazine free article project creation laravel artisan

Link: https://www.phparch.com/2017/05/artisanal-project-creation/

NetTuts.com:
How to Create a Laravel Helper
Apr 21, 2017 @ 20:15:28

On the NetTuts.com site there's a new tutorial from author Sajal Soni showing you how to create a custom Laravel helper, a set of helper functions that can be used through out the entire application.

Laravel includes a variety of global "helper" PHP functions. Many of these functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient. So, basically, helpers in Laravel are built-in utility functions that you can call from anywhere within your application. If they hadn't been provided by the core framework, you might have ended up developing your own helper classes.

Although the core provides a variety of helpers already, there’s always a chance that you’ll need your own and would like to develop one so you don’t have to repeat the same code here and there, thus enforcing better maintainability. You'll learn how to create a custom Laravel helper in this tutorial.

They start by talking about some of the current helpers and the functionality they relate to (arrays, paths, strings, etc). It then goes into the creation of the custom helper including the skeleton of the code layout, where to place them and how to load them into the application via a service provider.

tagged: custom laravel helper function creation tutorial

Link: https://code.tutsplus.com/tutorials/how-to-create-a-laravel-helper--cms-28537

TutsPlus.com:
Programming With Yii2: Routing and URL Creation
Dec 13, 2016 @ 18:15:02

The TutsPlus.com site has posted the next article in their "Programming with Yii2" series, this time focusing on the routing and URL creation in the application and how the requests get to the intended functionality (in controllers).

In today's tutorial, I'll review routing and URL creation in Yii. When a browser request arrives at your Yii application's index.php file, it must be parsed to determine which controller and method to call. That's routing. The reverse process of linking to parts of your application is URL creation, which is best done programmatically.

Yii provides a lot of flexibility in managing routing and generating links. Follow me as I review the basics.

He starts with a bit of background on the URL manager that comes built in to the Yii2 framework and how the routes are defined. He then starts in by defining some of the desired routes for the application and how to set them up in the main configuration file (including defaults). The tutorial also includes configuration examples of "pretty URLs", and outputting custom URLs using the "Url" helper.

tagged: programming yii2 series routing url creation tutorial

Link: https://code.tutsplus.com/tutorials/programming-with-yii2-routing-and-url-creation--cms-26869

Leanpub.com:
Updates to Pricing on New Books
Oct 06, 2016 @ 14:19:49

While not directly related to PHP and its community, several potential technical book authors out there will probably be affected by this. The popular publishing platform, Leanpub, has announced a change in their pricing to create new books with the service.

Leanpub is a powerful platform for serious authors. This platform is the combination of two things: a publishing workflow and a storefront. Leanpub is more than the sum of its parts, however – by combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks, it’s something different.

[...] Our workflow is flexible. Authors can use our simple in-browser editor or upload completed ebook files, but most choose to write their manuscripts on their own computers, using either plain text (formatted using Markdown or Markua markup) or Word documents. [...] Our storefront is an elegant way to sell in-progress or completed ebooks. [...] Our royalty rate is better than Amazon’s and Apple’s royalty rates for any book over $2.99, and it is far better than Amazon’s royalty rate for books over $10.

[...] Today we are changing the pricing of Leanpub. Until now, Leanpub has been totally free for authors to use. [...] Going forward, it will cost money to create a new Leanpub book. Here’s the cost: $99 per book.

Previously the only charges were a percentage of the sales for books on the storefront but moving forward, there will be a flat $99 USD cost for new books created wth the service (in addition to the same royalty rate as before). This helps to fund this great service and keep the level of quality authors have enjoyed so far. More details about the changes for new books and the "grandfathering" of current books can be found on this pricing page.

tagged: leanpub pricing book creation royalty publishing selfpublish

Link: https://leanpub.com/pricing

Paul Jones:
Framework Tradeoffs For Beginners: Product Creation vs Program Maintenance
Jan 22, 2014 @ 17:53:42

Paul Jones has shared some of his thoughts about framework tradeoffs in his latest post. In it he compares two perspectives about framework use for beginners - either the "get something out there" product approach or focusing on the the long term maintenance of the product.

Phil Sturgeon at his blog, writing about product creators who neither know nor care much about programming as a discipline. [...] Phil’s post focuses on the joyful, proud moments of creation that lead to business success, whether in terms of venture funding or continued sales. In this essay, I want to focus on what happens after that, when that initial creation passes into other hands to be maintained.

Paul talks about how frameworks can allow developers to work "beyond their level" and be more productive than they could be otherwise. He points out that this can create a beginner-level codebase that works "just enough" and then is usually passed off to more experienced developers to update, change and flat out fix issues.

From a financial standpoint, and perhaps even from an economic standpoint, it’s easy to see enabling-via-framework as a positive. Indeed, the product creator may justify his failures of good programming practice by substituting the product popularity and continued rounds of funding as a marker of success. [...] But from a programming practices standpoint, enabling-by-framework too often leads to pain and frustration on the part of the maintenance programmers, who are now saddled with the baggage of an amateur.
tagged: framework tradeoff beginner product creation maintenance

Link: http://paul-m-jones.com/archives/5890

Project:
Box - Making Creating PHARs Easier
Aug 24, 2012 @ 15:33:52

There's a new project on Github that wants to help making your phar archives for your PHP applications. The process is a little obtuse right now and Box wants to simplify it.

Box is a library and command line application for simplifying the PHAR creation process. [Features include] creating new PHARs with a simple configuration file, add and replace files in existing PHARs, extract existing PHARs, with option to cherry pick files and verify PHAR signatures.

The project is still relatively young but it looks like it's off to a good start. Phar files are a powerful tool to have in a PHP developer's arsenal but developing them can be a pain. Hopefully something like this can make life easier.

tagged: project phar build manage creation github

Link:

Michael Maclean's Blog:
Using Pango for PHP: a taster
Feb 22, 2011 @ 18:58:27

Michael Maclean has a new article today talking about the Pango graphics library and how it can be coupled with the Cairo PECL extension to more easily create better looking text in dynamic images.

The PECL/Cairo library is pretty good at drawing vector graphics (in our opinion, as the developers, at least!), but one thing it's not able to do by itself is draw text with mildly advanced layout. [...] That's because the developers of the Cairo library decided to let another more specialised library handle the job of text layout.

Michael has created a wrapper for Pango in PHP (github) and some sample code that can be used as a test to ensure it's all setup and working. He steps through each part of the image creation and describes what's happening and what each method is doing along the way.

tagged: pango image creation cairo text render tutorial

Link:

Joey Rivera's Blog:
Automate Db Model Creation with Zend_CodeGenerator_Php_Class
Dec 22, 2009 @ 14:33:06

On the Zend Developer Zone today there's a pointer to a new blog post from Joey Rivera about automating the creation of models in your Zend Framework application via the Zend_CodeGenerator_Php_Class.

This tool has to do a good bit of database manipulation so I've decided I'll build it in PHP using Zend Framework. I'll be using Zend_Db_Table_Abstract to communicate with the db tables from my project and I'll be creating a model for each table as well to store and manipulate data. I'll be working with lots of tables in the database and many have lots of fields.

Because the component lets you dynamically create PHP code, it can easily be used to create the model classes. Joey includes a link to the code you can use to add it into your own projects.

tagged: automate model creation zendframework class

Link:

NETTUTS.com:
How to Create a Wordpress Theme from Scratch: Part 2
Sep 18, 2008 @ 15:29:20

The NETTUTS site has posted the second part of their series looking at the creation of a custom WordPress template. This time they focus on expanding on the previous version, adding additional parts to the theme.

It's time for the good stuff now. We'll be adding the comments system, a sidebar with widgets and an archive for all the old posts. This will cover all that you need for a simple but well functioning WordPress theme, and hopefully you be able to apply this to all sorts of theming projects.

The give the code to create the sidebar (in their instance, an image from Flickr), handling the comments for each post and make the "archive" section to get to some of the older posts.

tagged: wordpress theme custom scratch tutorial creation

Link:


Trending Topics: