News Feed
Sections




News Archive
feed this:

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

SitePoint PHP Blog:
How to Create a Laravel CSS-Minify Command
June 11, 2014 @ 14:58:31

The SitePoint PHP blog has a new post today from Tounes Rafie showing you how, in a Laravel framework based application, to create a minify command with the framework's "artisan" command.

In this article you'll learn how to use Laravel's Artisan command line tool, and how to create a customized command. Note that you need to be familiar with the Laravel framework to get the most of this article. In this tutorial we're going to build a command to minify our css assets.

He starts with a (very) brief look at what Laravel commands are and the options this articular one will include. Next up is the code you'll need to create the command, making use of Laravel's integration of the Symfony Console component. He shows how to register the command with the rest of the application and how to work with the options/arguments for the input. From there he shows how to run the command and how to make some other improvements including colorized output and more information on execution.

0 comments voice your opinion now!
css minify command laravel artisan framework tutorial

Link: http://www.sitepoint.com/create-laravel-css-minify-command

ServerGrove Blog:
Symfony2 components overview Process
April 18, 2014 @ 12:41:41

The ServerGrove blog has posted their latest Symfony2 component spotlight, this time focusing on the Process component.

The Symfony2 Process component, allows us to execute commands in sub-processes. [...] The Process component provides an object-oriented abstraction on top of proc_* functions to execute independent processes from PHP.

As with the other posts in the series, they walk you through the installations via Composer and some examples of its use. The post also shows the use of exit codes, working with long running processes and how to execute PHP code in the command. They also briefly look "under the hood" at how the component does what it does (on top of the proc_* functions).

0 comments voice your opinion now!
symfony2 component process external command overview

Link: http://blog.servergrove.com/2014/04/16/symfony2-components-overview-process/

Matthias Noback:
Test Symfony2 commands using the Process component and asynchronous assertions
March 24, 2014 @ 10:49:13

Matthias Noback has a new post today showing you how to test Symfony2 commands that use the Process component. More specifically, his tests revolve around the ones that use asynchronous assertions in the testing to remove weird behaviors that could be caused by multiple processes running them simultaneously.

Usually you would test a console command using the ConsoleTester class as described in the official Symfony documentation. But we can not use it in this case. We need to isolate the process in order for pcntl_fork() to work correctly, otherwise the PHPUnit test runner itself will be forked too, which will have the effect of running all the following unit tests twice (which can have very strange effects on the test results).

He shows how to use the Process component to start up a new process (the daemon) and check that the PID file exists. He includes an example of a "probe" to determine what processes are running and preventing them from stepping on each other.

0 comments voice your opinion now!
symfony2 command process component asynchronous assertion unittest phpunit

Link: http://php-and-symfony.matthiasnoback.nl/2014/03/test-symfony2-commands-using-the-process-component-and-asynchronous-assertions/

Rob Allen:
Global installation of PHP tools with Composer
December 23, 2013 @ 09:39:13

Rob Allen has a quick post today showing how to use Composer to globally install tools and libraries on your system.

The Composer package manager along with the Packagist repository site is quickly becoming the defacto PHP package management system. One feature I found out about recently is that you can install packages globally rather than locally into your project. I think that this is most useful for development tools, such as PHPUnit which are then available everywhere.

He includes the command syntax you'll need to do the global install, showing an example with the popular PHP unit testing tool PHPUnit. There's also a "global update" command you can use to update these packages (or add more) later on too.

0 comments voice your opinion now!
global install tools composer example command

Link: http://akrabat.com/php/global-installation-of-php-tools-with-composer/

SitePoint PHP Blog:
Command line PHP using Symfony Console
December 12, 2013 @ 10:34:15

The SitePoint blog has a new post from Daniel Gafitescu covering the use of the Symfony Console component to create command line PHP scripts quickly and easily.

As a PHP developer, you will often find yourself working with PHP in the command line. The first time I had to use it was because I would get the "Maximum execution time of 30 seconds exceeded" error on a shared server where you could not change the max_execution_time PHP setting. Nowadays building command line scripts is much easier than it used to be. If you search on Packagist you will find a lot of packages to work with the command line but the one that stands out and is the most commonly used is Symfony/Console.

He starts with what you'll need to add to your Composer configuration to pull in a development version (2.4.x-dev) of the component. With that installed, he sets up a base directory ("/app") and a basic skeleton for your application. For his first command, he creates a script that will calculate the fibonacci numbers between two given numbers. He shows how to work with the input and Output objects inside the script and the code for the finished command - including some screenshots of the output.

0 comments voice your opinion now!
command line cli symfony console tutorial

Link: http://www.sitepoint.com/command-line-php-using-symfony-console/

Matthias Noback:
Symfony2 Add a global option to console commands and generate a PID file
November 26, 2013 @ 14:06:11

Cal Evans has pointed out a post by Matthias Noback related to Cal's "Signaling PHP" book and an idea presented in one of the appendices - working with PID files as a global option. Mattias writes:

Recently I read the book Signaling PHP by Cal Evans. It's a short book, yet very affordable and it learned me a couple of things. First of all it explains about how you can "capture" a Ctrl+C on your long-running command and do some necessary cleanup work before actually terminating the application. In the appendix it also mentioned the interesting concept of a PID file. [...] In Appendix A of "Signaling PHP", Cal writes about a way to extend a Symfony command to automatically create such a PID file before executing its task, and to delete this file afterwards.

Mattias shares what he calls a "hack" to make it happen globally - using the eventing system built into the Symfony Console functionality and the "console.command" event. He creates a bundle to help with the reading/writing of the PID file and shows how to implement it as a part of the event handling. He does point out one problem with this method (that the "input" object isn't available) so he works around it with the "ArgvInput" component and some manual handling to grab the PID file location provided.

0 comments voice your opinion now!
symfony2 console option command pid file tutorial bundle

Link: http://php-and-symfony.matthiasnoback.nl/2013/11/symfony2-add-a-global-option-to-console-commands-and-generate-pid-file/

Liip Blog:
New in Symfony 2.4 Show logs in console
August 21, 2013 @ 10:53:44

On the Liip blog they've shared a new post from Tobias Schultze about a new feature that will be in the 2.4 release of the popular Symfony framework - the ability to show log messages in console output.

When you want to output text to the console you usually used the OutputInterface instance that is passed when your command gets executed. But there are two problems: it's cumbersome to print information depending on the verbosity settings and if the service you call also wants to give feedback you would need to pass on the $output. [...] To solve these [two problems] I thought it would be much easier to rely on the logger which is highly related. So I added integration between Symfonys Console Component and Symfonys logging library Monolog in PR #8167.

This gives you a new handler, the ConsoleHandler, that makes it easier to just write out based on console events instead of just appending to the output. It includes switches for verbosity levels too. He shows how to implement it in your application, configuring it through the YAML config both in the service and under the Monolog settings as a handler.

0 comments voice your opinion now!
symfony2 log console command component consolehandler monolog

Link: http://blog.liip.ch/archive/2013/08/20/new-in-symfony-2-4-show-logs-in-console.html

Cal Evans:
Managing the Verbosity of symfony's Command Object With a Trait
July 15, 2013 @ 12:29:39

In this new post to his site Cal Evans goes through a simple application he's created using the Symfony Command component and some of his gotchas along the way. He shows how, using a trait, he was able to control the output of the command more effectively.

Recently I came up with a project I needed to build. Honestly, it's one of those "not useful to anyone but me" kind of projects. I decided though that while I was at it, I wanted to learn something new. Since I've been a die-hard Zend guy since Zend Framework was 0.2, and more recently a Silex believer, I thought I would drop down a level form Silex and dig into symfony itself. This project is strictly a command line project. No API, no web interface, just a command and a few switches. Digging around I found SymfonyComponentConsoleCommandCommand so I decided to give it a try.

He goes through some of the work he did to pull in the needed packages and create his first command. He creates a "writeln" method to output to the console that contains his check for the verbosity level of the current command options (like "quiet" or "verbose"). He introduces the trait to add some additional handling to this output, making it easier to just drop in the "writeln" functionality in any command of his choosing.

0 comments voice your opinion now!
verbosity trait symfony command silex writeln

Link: http://blog.calevans.com/2013/07/10/managing-the-verbosity-of-symfonys-command-object-with-a-trait

PHPMaster.com:
Proc_Open Communicate with the Outside World
June 10, 2013 @ 09:43:01

On PHPMaster.com today there's a new tutorial from Timothy Boronczyk about using the proc_open function to kick off processes outside of PHP. It can be used to start up and manage (in a limited fashion) external process calls.

There are many ways we can interact with other applications from PHP and share data; there's web services, message queuing systems, sockets, temporary files, exec(), etc. Well, today I'd like to show you one approach in particular, proc_open(). The function spawns a new command but with open file pointers which can be used to send and receive data to achieve interprocess communication (IPC).

He starts off explaining one of the fundamental concepts behind working with processes - pipes, both anonymous and named. He then moves on to the use of proc_open and the three attributes it takes - command, pipes and references for output. He includes a more practical example showing it in use - a script that converts text with wiki markup into HTML output (via this tool).

0 comments voice your opinion now!
procopen tutorial processes command pipes

Link: http://phpmaster.com/proc-open-communicate-with-the-outside-world

Josh Adell's Blog:
Command Invoker Pattern with the Open/Closed Principle
January 16, 2012 @ 10:04:42

In a response to a recent post on DZone.com about the "Open/Closed Principle" Josh Adell has posted an example of a " flexible and extendable command invocation solution" implementing this SOLID idea.

Let's overcome some of these issues [with only being able to extend the invoker class and that the invoker needs to know how to create commands], and also make the code even more extensible. I'll use a simplified command invoker to demonstrate.

His code is included - the creation of a "Command" interface and two comments that implement it: "HelloCommand" and "PwdCommand", each with "register" and "execute" methods. His "Invoker" class then only needs to be told how to map these commands and the "register" is called as they're needed. You can find the full example code for this invocation example in this gist.

0 comments voice your opinion now!
command designpattern invoke open closed principle solid tutorial



Community Events





Don't see your event here?
Let us know!


development framework conference laravel list api introduction deployment developer series tips podcast interview code language release zendserver symfony community threedevsandamaybe

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework