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

Allan MacGregor:
Working with Psysh
April 14, 2014 @ 09:24:34

Allan MacGregor introduces you to Psych in his latest post today. Psysh is a runtime developer console, interactive debugger and REPL for PHP.

Psysh is actually more than a simple REPL it's also an interactive debugger; which means you can say goodbye to the endless barrage of var_dump() and die() statements. But do we really need another REPL for PHP, well honestly we could probably get by with the solutions currently available however Psysh has an extremely interesting Ace under the sleeve, it can also function as a realtime debugger.

He includes a few terminalcasts showing some of the commands Psysh offers from the expected output of variable value out to a handy link to the PHP documentation. An example of the useful object output is also included, enabling the showing of methods and properties.

0 comments voice your opinion now!
psysh repl debugger console documentation debugger

Link: http://coderoncode.com/2014/04/03/working-with-psysh.html

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/

Gonzalo Ayuso:
Sending automated emails with PHP, Swiftmailer and Twig
September 24, 2013 @ 11:40:57

Gonzalo Ayuso has posted a new tutorial today showing you how to combine PHP, Swiftmailer and Twig to send automated emails from your application.

My work as host is basically pick the place and encourage people to join to the Coding Dojo. One way of doing this (besides twitter buzz) is take my address book and send one bulk email to all of them inviting to join us. I don't like this kind of mails. They look like spam, so I prefer to send a personalized email. This email has a common part (the place location, the hour, the event description, ...) and the personalized part. I can do it manually, the list isn't so huge, but definitely that's not cool. Because of that I have done a little script to perform this operation.

His example extracts the information from a simple spreadsheet exported as a CSV file. He creates a simple Mailer class that uses Swiftmailer to do the actual sending. You pass in the Twig rendering object (Twig_Environment) that's used to render the email output. He includes a "Spammer" class that uses the Symfony EventDispatcher to send the email if everything works or an error email if something fails. He then drops it all into a Symfony Console command structure, defines several configuration settings in a "config.yml" and makes the script to execute the commands.

0 comments voice your opinion now!
email swiftmailer twig template tutorial symfony console eventdispatcher

Link: http://gonzalo123.com/2013/09/23/sending-automated-emails-with-php-swiftmailer-and-twig

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

Daniel Cousineau:
Using Symfony Console From Scratch
April 05, 2013 @ 12:46:43

Daniel Cousineau has posted a guide to using the Symfony Console component as a part of your application. It introduces you to some of the basics of using the component and has plenty of sample code to get you started.

CLI applications are extremely useful for many, if not most web projects. The Symfony framework even goes so far as to include an extensible CLI console used for everything from running cache cleanup/warmup tasks, to user account management. Many CLI scripts for web projects consist of just a static .php file which works fine but grow unweildy over time. Thankfully, the aforementioned Symfony Console component is released as a decoupled standalone that can be installed and setup easily and provide us with structure and organization (and some powerful features).

He walks you through the installation of the component via Composer and includes the code to make a simple CLI script using it. He shows how to make new commands (like his "TestCommand") and how to attach it to the application. He talks about output and input handling with arguments and options. He also shows an integration with an existing application with a base command class that helps to set up and configure the command objects that inherit it.

0 comments voice your opinion now!
symfony console tutorial introduction install usage

Link: http://dcousineau.com/blog/2013/03/28/using-symfony-console-from-scratch/

DZone.com:
The Wheel Symfony Console
March 13, 2013 @ 11:22:31

In this new post to DZone.com, Giorgio Sironi kicks off a series that looks at reusable components in the PHP development world. In this first post of that series he looks at the Symfony console component .

Symfony is one of the most popular open source PHP frameworks on the market. The Symfony Components, however, are loosely coupled projects that can be reused as a library outside of an application based on Symfony. The component this article explores is Console (symfony/console on Packagist and GitHub), dedicated to quickly build console applications.

He goes on to talk about some of the "pros" of using the component (including built-in argument/input handing and multiple "commands") and some of the "cons" of is use (including its size and some of the built-in features you can't really work around).

0 comments voice your opinion now!
symfony console reusable component pro con commandline


Zumba Engineering Blog:
Creating bash completion to your console application
August 21, 2012 @ 09:47:52

On the Zumba Engineering blog there's a new post showing you how to implement bash shell "autocomplete" with a special option for a second argument.

This weekend I saw the bash completion for CakePHP from Andy Dawson and had an idea to do the same for our service application, because we frequently forget the exactly job class or method name and add extra steps to verify these names before execute the job. I read his code, made some research and finally get our bash completion working fine.

In his case he wanted to see what things a module in the application had to offer, so he implemented a "__check__" argument that looked at the third argument and used reflection to get the methods allowed for it. Also included in the post is the bash alias you'll need to set up to get it working (and where to put it to make it cooperate).

0 comments voice your opinion now!
bash autocomplete console tutorial reflection


FuelPHP:
Oil Migrations, Tasks and Console (Screencast)
March 15, 2011 @ 11:31:39

Phil Sturgeon has put together a screencast showing off a few of the features of the Fuel PHP framework like migrations, tasks and the console the Oil tool provides.

In this video I'm going to be demonstrating migrations which I touched on in the last video but I felt I should go into them in more depth. Migrations [...] are essentially a way to stage changes for your database in a way that means the changes can be independent from the schema as a whole.

He walks you through the creation of a migration with the help of the Oil command line tool. The generated classes include "up" and "down" methods for the creation and rollback of your changes. He shows the process to create a simple task and how to use the built-in console to interactively work with the framework. You can find out more about Fuel on the Fuel documentation section of the project's site.

0 comments voice your opinion now!
fuelphp framework oil console commandline tasks migrations


Sasa Stamenkovic's Blog:
Building CLI Apps With Symfony Console Component
December 31, 2010 @ 00:33:58

Sasa Stamenkovic has submitted a new tutorial he's written up about how to build CLI applications in Symfony with the help of its console component.

When working with PHP, I usually use Zend Framework for my projects. It has nice code generation tool (Zend_Tool), MVC, forms, helpers and it's very flexible. But one aspect where Zend wasn't the best tool for the job is building CLI applications. [...] Symfony Console Component is still under development, and there is no good documentation yet. I managed to google out Fabien Potencier's slides from ConFoo 2010 conference where he mentioned the component and showed one simple example. But still, most of the time working with the component, I find myself reading its source code.

He creates a simple console calculator application that takes in two numbers and calculates the sum of the two numbers. He includes an addition to the "--help" menu. Complete code is included to build the CLI interface and to create the class it uses to make the calculation. He shows how to add new commands and a bit on how to test your new command. Complete source code is available on github.

0 comments voice your opinion now!
symfony console component commandline tutorial



Community Events





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


api deployment series laravel install introduction tips symfony podcast release zendserver library list framework update interview opinion community package language

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