PHPDeveloper.orghttp://www.phpdeveloper.org
Up-to-the Minute PHP News, views and communityen-usTue, 03 Mar 2015 14:33:02 -060030http://www.phpdeveloper.org/news/21880http://www.phpdeveloper.org/news/21880
The Web Mozarts blog has an interesting new post today that talks about using annotations in your PHP code to define the attributes in resulting XML that could be generated dynamically from your objects.

Annotations have become a popular mechanism in PHP to add metadata to your source code in a simple fashion. Their benefits are clear: They are easy to write and simple to understand. Editors offer increasing support for auto-completing and auto-importing annotations. But there are also various counter-arguments: Annotations are written in documentation blocks, which may be removed from packaged code. Also, they are coupled to the source code. Whenever an annotation is changed, the project needs to be rebuilt. This is desirable in some, but not in other cases.

They focus in on Symfony-based applications as a good base to work from (as they've pushed to have annotations work in the code for things like routing and data type definition). He starts with an example Doctrine class - a "best buddy" for Symfony as far as annotations go - and how the annotations define the different properties. He also includes an example of the XML output of the same definition generated through an "AnnotationReader" instance. He talks about having multiple XML documents representing one object with different annotations put in each, including the XML output. The post finishes with some advantages including the ease of validation by XML-friendly tools looking to interface with the application.

Link: http://webmozarts.com/2014/10/24/defining-php-annotations-in-xml/]]>Fri, 24 Oct 2014 11:10:53 -0500http://www.phpdeveloper.org/news/21541http://www.phpdeveloper.org/news/21541
In this new post to his site Thomas Weinert shows how to use the FluentDOM library (a PHP implementation of a Javascript library by the same name) when XML namespaces are involved.

FluentDOM 5 allows to register namespaces on the DOM document class. These are not the namespaces of a loaded document, but a definition of namespaces for your programming logic.

He compares it to both a PHP example, using the DOMXpath handling and a Javascript sample using its own xmlDocument functionality. Finally he compares these examples to the few lines of FluentDOM code to handle the same kind of evaluation. He wraps up the post with a brief mention of the "appendElement" function that wraps serveral operations in one for easy element additions.

Link: http://www.a-basketful-of-papayas.net/2014/08/fluentdom-5-xml-namespaces.html]]>Thu, 07 Aug 2014 10:50:22 -0500http://www.phpdeveloper.org/news/21051http://www.phpdeveloper.org/news/21051
On PHPBuilder.com today they have a new post showing different configuration patterns for getting localized settings into your applications. They show the use of INI files, PHP scripts, text files, XML data and a database call.

PHP is a cross platform language. It is a server based application so we must think about the configuration settings of the PHP software. There are various ways of creating configurable PHP applications. The configuration flexibility comes as a built in feature in PHP. But we must understand the requirement clearly before making an application configurable. This article explores different PHP configuration patterns and their implementation.

For each of the options mentioned, there's a brief description of what the method is, some of the common uses and a code example showing a basic implementation. The database pattern is the only one without a code example as the database interface varies widely from application to application.

Link: http://www.phpbuilder.com/articles/application-architecture/using-php-configuration-patterns-properly.html]]>Wed, 16 Apr 2014 11:52:11 -0500http://www.phpdeveloper.org/news/20473http://www.phpdeveloper.org/news/20473
On the tech.pro site there's a recent tutorial posted showing you a basic way to create an RSS feed using data coming from a database accessed via PDO.

Using an RSS feed on your website is a great way of letting your visitors, search engines or directories get a hand on your content. RSS feeds are common practice on most blog and CMS platforms including Wordpress, Joomla and evenly the newly released Ghost. If you're using a CMS or similar platform, the likelihood is that you don't need to implement an RSS feed yourself. [...] Below you've got the step-by-step process to create anything from the simple, standard-compliant RSS feed - up to the more advanced.

The tutorial shows you how to pull the data from a simple database table (SQL not provided, but pretty easy to figure out(, including example PDO connections for several database types. This data is then manually appended into an XML string to build out the RSS feed correctly. They also talk about implementing the Dublin Core metadata as a way for providing more information about the feed and its contents (including an image and category details).

Link: http://tech.pro/tutorial/1722/how-to-create-an-rss-feed-using-php-and-pdo]]>Wed, 04 Dec 2013 11:52:53 -0600http://www.phpdeveloper.org/news/20090http://www.phpdeveloper.org/news/20090
In a new post to his siteAdam Culp shares how he created an XML sitemap for his Zend Framework 2-based application as he made it (the SunshinePHP site) more SEO friendly.

I was pleasantly surprised to see the Navigation component of Zend Framework 2 includes a bunch of view helpers, including a Sitemap helper. So now I have an xml sitemap created by Zend Framework 2 that works hand in hand with the site navigation. However, the documentation was not complete as of this writing and caused me to do a bit of trial and error debugging to get it working. Below I will post how I got it working, in hopes it will help others.

The code to get it working is relatively simple - set it up in the module configuration, specify the navigation structure and add a route for the sitemap output. The view then accesses the navigation handling and calls a "sitemap" method to push the XML result out to the user.

Link: http://www.geekyboy.com/archives/770]]>Mon, 09 Sep 2013 11:15:09 -0500http://www.phpdeveloper.org/news/19358http://www.phpdeveloper.org/news/19358
In the latest post to her site, Lorna Mitchell walks you through the creation of a first Phing plugin, an extension to the popular PHP-based build tool.

I'm a huge fan of Phing and use it regularly for build and deployment tasks. Often, I'll ask about a plugin that I wish existed, and get a very courteous "patches welcome" from the nice people in the #phing channel on freenode. This has happened a few times, so I thought I should probably look at how to make a new phing plugin, this article shows you how to make the simplest thing I could think of: a simple "hello world" plugin.

She points you to the location to grab the latest version of the tool (the github repository) and how to define a configuration file for your test runs. Then she includes the sample code showing how to create the "HelloTask" plugin. It takes an input value of "name" and displays a greeting when executed. She shows the syntax for defining this in the XML build file and the sample result when executed.

]]>Mon, 25 Mar 2013 10:49:23 -0500http://www.phpdeveloper.org/news/19171http://www.phpdeveloper.org/news/19171
On PHPMaster.com today there's a new tutorial introducing you to SimpleXML, a handy bit of functionality included with the base PHP install to make working with XML (well, reading it) much simpler.

Parsing XML essentially means navigating through an XML document and returning the relevant data. An increasing number of web services return data in JSON format, but a large number still return XML, so you need to master parsing XML if you really want to consume the full breadth of APIs available. Using PHP's SimpleXML extension that was introduced back in PHP 5.0, working with XML is very easy to do. In this article I'll show you how.

He starts with some basic usage of the SimpleXML parsing, giving an example XML to parse, the resulting object and how to access the data inside it. There's also a bit about dealing with namespaces in the XML you're parsing and a more practical example - parsing the output of a YouTube feed to get links to various videos.

]]>Tue, 12 Feb 2013 12:48:34 -0600http://www.phpdeveloper.org/news/19128http://www.phpdeveloper.org/news/19128
Andrew Podner has a new post to his site today introducing you to Phing, a PHP-based build tool (designed after on Apache Ant) that makes automating builds of your applications easy.

One of the things I have been focusing on lately is trying to to a better job of mechanizing and automating the process of building and deploying an application. The reason for this is pretty simple: applications just seem to keep getting more and more complicated and intricate as time goes on. [...] Phing is a "project build system" that helps developers manage repetitive tasks associated with preparation and deployment of applications. Phing uses XML based files to allow you the ability to customize the build process to the individual application.

He walks you through the Phing installation (from PEAR, note that you can install it via Composer now too) and how to set up your first project XML definition. He shows you how to add a "target" or step to the build with the basic example of running your app's PHPUnit tests. He also includes a list of other things Phing can do and work with including CodeSniffer checks, FTP handling, version control interfaces and automated documentation.

]]>Mon, 04 Feb 2013 09:08:16 -0600http://www.phpdeveloper.org/news/18402http://www.phpdeveloper.org/news/18402
PHPMaster.com is back with the third part of their series looking at Aspect Oriented Programming with the CodeIgniter framework. (Part 1, Part 2)

In the previous parts of the series we learned about AOP concepts and the need for using AOP in large scale projects and I introduced CodeIgniter's hooks as a convenient mechanism for creating AOP functionality from scratch. In this part I'll show you how to use both XML and comment-based techniques to create custom AOP functionality when a dedicated AOP framework is not available.

They start with the XML configuration that defines a few aspects and pointcuts for the application. This is then read in via the "applyBeforeAspects" and the aspects that should be executed first are extracted, loaded and run. Following this, they take the other approach - based on docblock comments - and pull in the comments (the @before and @after tags) and load/execute the aspects that way instead.

]]>Fri, 24 Aug 2012 11:56:29 -0500http://www.phpdeveloper.org/news/18207http://www.phpdeveloper.org/news/18207
Nikita Popov has posted a plea to developers and project maintainers alike to stop using XML for their configuration files in their PHP-based applications.

I recently tried using Phing (a PHP build system) to do some simple release automation. Just creating a PEAR package and doing a few string replacements here and there. The result? After several wasted hours I ended up using Phing only for PEAR packaging and doing everything else in a custom PHP build script. The reason? Phing uses XML files to configure what it should do during a build.

He advocates a more native solution - a PHP script that defines the configuration options as a part of an object that can be injected into the parts of your app without the need for external dependencies.