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

Nikola Posa:
Using Monolog with Zend Service Manager
Jun 16, 2017 @ 17:09:27

Nikola Posa has a new post to his site showing you how to can combine Monolog for logging with Zend Service Manager, a component from the Zend Framework, defining the logger as a service that can be easily used (and re-used) across an application.

Without any doubt, Monolog and Zend Service Manager are two libraries that are almost always found in the composer.json file require section of my projects. In case you didn't know, Monolog is a PSR-3 compliant logging library that allows you to save logs to various storage types and web services, while Zend Service Manager is a PSR-11 compliant dependency injection container and a service locator implementation that facilitates management of application dependencies.

In this post I'm gonna show you how the two can work together.

He starts with an example of configuring the ServiceManager instance with a factory dependency that manually creates the Monolog logger inline. While this works, it's not idea, mixing configuration and functionality. He shows how to refactor the same functionality into a factory class that performs the same function but isolates it from the configuration. He then takes this further and separates out the environment-specific configuration from the handling and, finally, shows the creation of a more general logging factory that allows the definition of different kinds of loggers based on the need.

tagged: monolog zendservicemanager component tutorial combine factory configuration

Link: http://blog.nikolaposa.in.rs/2017/06/12/using-monolog-with-zend-service-manager/

Hackernoon.com:
How to configure PHPStorm to use PHP-CS-Fixer
Apr 25, 2017 @ 15:47:46

On the Hackernoon site there's a recent tutorial showing you how to hook the PHP-CS-Fixer tool into PhpStorm for easy execution during development rather than after.

The PHPStorm IDE by JetBrains is probably one of my favorite editors. It has its flaws (constant indexing…) but overall its a great tool for me. However, my focus today is not on PHPStorm per say but rather how to add the awesome functionality of using project page. Depending on your platform you will need to make some decisions, namely how you configure the rules of PHP-CS-Fixer. I am currently on Windows but I will try to make sure these instructions work in both *nix and Windows environments.

He then walks you through some prerequisites (both pieces of software installed basically) and the decisions to make based on your platform. He then provides screenshots and descriptions showing where to go in the PhpStorm IDE to add the PHP-CS-Fixer as a new "Tool", the working directory to use and how to set up a keymap to execute the tool. He includes an example of the output when things are correctly configured and working together.

tagged: configure phpstorm phpcs phpcsfixer tool tutorial install combine setup ide

Link: https://hackernoon.com/how-to-configure-phpstorm-to-use-php-cs-fixer-1844991e521f

Loïc Faugeron:
The Ultimate Developer Guide to Symfony - Web Example
Mar 30, 2016 @ 15:50:17

In a previous post Loïc Faugeron showed you how to take all of the components he'd talked about so far and make a simple API endpoint. In this latest post he takes the same functionality and makes a web-facing example instead.

In this guide we've explored the main standalone libraries (also known as "Components") provided by Symfony to help us build applications: HTTP Kernel and HTTP Foundation, Event Dispatcher, Routing and YAML, Dependency Injection and Console. We've also seen how HttpKernel enabled reusable code with Bundles, and the different ways to organize our application tree directory.

Finally we've started to put all this knowledge in practice by creating a "fortune" project with an endpoint that allows us to submit new fortunes.

In this article, we're going to continue the "fortune" project by creating a page that lists all fortunes.

He goes through a similar process as before, but with a few changes to make it output a web page instead of API (JSON) results:

  • Create the Controller
  • Configure related routing
  • Create the logic to list all current fortunes
  • Putting the "wiring" in place to connect it to the database
  • Creating the view to output a simple page with the fortune list

It's that last step that's different, resulting in a simple (non-templated) page being output with HTML markup. He then refactors this to use Twig as the templating output layer, removing the output generation from the application logic.

tagged: ultimate developer guide symfony web example component combine tutorial

Link: https://gnugat.github.io/2016/03/30/ultimate-symfony-web-example.html

Loïc Faugeron:
The Ultimate Developer Guide to Symfony - API Example
Mar 25, 2016 @ 15:31:09

Loïc Faugeron has posted another article in his "Ultimate Developer Guide to Symfony" series today. In this new article he shares an API example making use of the knowledge gained from the other articles to create a simple project.

In this guide we've explored the main standalone libraries (also known as "Components") provided by Symfony to help us build applications: HTTP Kernel and HTTP Foundation, Event Dispatcher, Routing and YAML, Dependency Injection and Console.

We've also seen how HttpKernel enabled reusable code with Bundles, and the different ways to organize our application tree directory. In this article, we're going to put all this knowledge in practice by creating a "fortune" project with an endpoint that allows us to submit new fortunes.

He starts by creating the project (via Composer's create-project command), sets up a basic routing configuration and installs PHPUnit for testing. He then shows the creation of the controller - test first - to handle the "fortune" endpoint requests. He then comes back in and adds in some logic around the submission including matching tests. This is then refactored further to use Doctrine to insert the contents into a database. Additional code is provided showing how to "wire it all together" and create the database structure. The entire post takes the TDD approach so tests for all submission functionality are included.

tagged: ultimate developer guide symfony api example component combine tutorial

Link: https://gnugat.github.io/2016/03/24/ultimate-symfony-api-example.html

Matthew Turland:
PHPUnit + XHProf = BOOM!
Oct 14, 2015 @ 14:38:22

Matthew Turland has a post to his site sharing his experience with the PHPUnit and XHProf combination...and the unfortunate result that made every test fail.

I ran into an issue recently while trying to run PHPUnit tests in an environment using XHProf. Google didn’t prove to be much help, so I thought I’d document the problem and solution here for posterity.

When I ran my tests, each failed with the same cryptic error and no backtrace: "Attempted to serialize unserializable builtin class PDO" The cause was the culmination of two rather unfortunate circumstances.

He shares the two problems that causes this issue - one being XHProf's use of globals (where its PDO connection is stored) and the other is the @backupGlobals setting in PHPUnit that's enabled by default. This makes PHPUnit to try to backup that PDO connection by serializing it but can't, hence the failure. He points out a pull request that aims to fix the issue but recommends disabling the globals backup for the time being if you don't have a need for it.

tagged: phpunit xhprof combine globals pdo error backup

Link: http://matthewturland.com/2015/10/13/phpunit-xhprof-boom/

Codeception Blog:
The Locator Class
Sep 27, 2012 @ 14:50:34

The Codeception blog (a BDD testing tool) has a new post on using their Locator class to create more complex tests based on XPath or CSS selectors.

In the latest Codeception 1.1.4 new Locator class was introduced. Basically it should simplify your life in writing complex XPath or CSS locators. Right now it has minimal, yet useful functionality.

The post shows how to combine more than one item for location with either a tag, CSS-based or XPath-based selector. It also shows how to use the "tabindex" method to simulate the movement through a page using the "Tab" key. Finally, there's a quick piece of code showing how to locate an item based on the "href" value. For more information on using Codeception, check out their documentation or the project's main site.

tagged: locator class css xpath combine tab href

Link:

Script-Tutorials.com:
Watermark processing on images using PHP and GD
Sep 09, 2011 @ 17:36:06

On the Script-Tutorials blog today there's a new tutorial posted showing you how to easily add watermarks to your images dynamically, either as a part of a cache generation or on upload.

I will show you how to use GD library. And, main task today is adding watermark to image and generate result as PNG image into browser. We will using PHP and GD library. This is nice library to work with images at server side. Also (as additional tasks) I will draw little frame over image and will draw some text. Between, you can use this method (of adding watermarks in realtime) to protect original photos.

Full code for the script is included in the post, showing the combining of two images into the one finished product. The code is also available for download if you'd like to get hacking right away.

tagged: watermark image gd combine tutorial

Link:

Gonzalo Ayuso's Blog:
Speed up page page load combining javascript files with PHP
Feb 21, 2011 @ 19:01:54

Gonzalo Ayuso has a handy performance tip for getting that little bit extra speed from your page load times - combining Javascript with PHP files.

One of the golden rules when we want a high performance web site is minimize the HTTP requests. Normally we have several JavaScript files within our projects. It’s a very good practice to combine all our JavaScript files into an only one file. [...] But if your project is alive and you are changing it, it's helpful to spare your JavaScript files between several files. [...] So we need to choose between high performance and development comfort.

He includes a quick script that runs through your javascript directory (recursively), grabs all of the javascript content from each, combines and minifies them to serve gzip compressed out to the browser.

tagged: javascript tutorial combine minify gzip page load performance

Link:

Noupe.com:
20 Useful PHP + jQuery Components & Tuts for Everyday Project
Apr 07, 2009 @ 17:56:16

Noupe.com has posted a list of twenty useful PHP and jQuery components (and tutorials) that could be useful in everyday projects:

When you combine some neat functionality courtesy of PHP with the cleverness of jQuery you can produce some pretty neat effects. In an effort to help you take it up a notch, we’d like to share some methods for helping your site anticipate a user’s next move.

Included in the list are components/tutorials like:

See the full post for even more great PHP+jQuery information.

tagged: jquery component tutorial list project combine backend frontend

Link:

PHPImpact Blog:
Server-side Marker Clustering with PHP and Google Maps
Feb 27, 2009 @ 16:25:14

On the PHP::Impact blog Federico Cargnelutti points out a PHP library that lets you do clustering on Google Maps. What's clustering?

As maps get busier, marker clustering is likely to be needed. Marker clustering is a technique by which several points of interest can be represented by a single icon when they’re close to one another.

The tool, created by Mike Tuupola, lets you break up the map into cells and place points inside them. When there's more than one point in a general area, an extra icon is created to reference those points together (cleaning up the map and preventing you from having lot of little Google Maps markers cluttering up your map. Mike also has a blog post about the library showing it in a bit more detail.

tagged: server clustering mark googlemaps miketuupola library combine

Link:


Trending Topics: