layh.com

Whatever...TYPO3...FLOW3...and more...

Using the TYPO3/FLOW3 Coding Guidlines with PHPStorm and PHP_CodeSniffer (Windows)

With the new release of PHPStorm 4 there is a CodeSniffer integrated. Since for us TYPO3 developers it doesn’t make much sense to us another coding standard than our own, here a short how-to for the usage of the TYPO3 Coding Guidlines in PHPStorm.

First thing, you have to install PHP and PHP_CodeSniffer on your machine. I had trouble with the CodeSniffer after installing it in C:\Programs (X86) so after uninstalling everything and installing it in C:\PHP the CodeSniffer started to work. Before you enter something in your IDE, verify that your CodeSniffer works by running

phpcs.bat --version

The expected result should be:

PHP_CodeSniffer version 1.3.3 (stable) by Squiz Pty Ltd. (http://www.squiz.net)

Next thing is to install the guidelines for TYPO3. For that, clone the repository on git.typo3.org to get the right standards:

git clone git://git.typo3.org/Teams/forge.typo3.org/hudson-helpers/tools/PHP_CodeSniffer.git

Now copy the folders FLOW3, TYPO3, TYPO3v4 to (in my example):

C:\PHP\PEAR\PHP\CodeSniffer\Standards

Update:

Another option is to get the TYPO3 Standards from pear.typo3.org. (Thx @ctrabold for the hint)

Open PHPStorm and go to the settings. Settings->Inspections

PHP CodeSniffer 300x137 Using the TYPO3/FLOW3 Coding Guidlines with PHPStorm and PHP CodeSniffer (Windows)

Select the path to the phpcs.bat file and click “Validate”. If everything works fine you should be able to select a Coding standard in the select box below.

Update:

If you work with TYPO3, select TYPO3v4, if you work with FLOW3, select the FLOW3 Standard. The TYPO3 folder contains the common Codesniffs.

Links:

TYPO3 Codesniffer page on forge: http://forge.typo3.org/projects/team-php_codesniffer/wiki/Using_the_TYPO3_Coding_Standard

PHP_CodeSniffer package on pear: http://pear.php.net/package/PHP_CodeSniffer/

PHP Download for Windows: http://windows.php.net/download/

PHP Codesniffer on forge: http://forge.typo3.org/projects/team-php_codesniffer/wiki/Folder_structure

And now: Have fun writing clean and good code icon wink Using the TYPO3/FLOW3 Coding Guidlines with PHPStorm and PHP CodeSniffer (Windows)

Marktkirche Wiesbaden – a small photo experiment

I always get bored on my way to my car in the morning so I started to make a picture of this church every morning. I don’t take this to serious, so I only take pictures when I have to go to work. This means in my vacation and during the weekend there are some pictures missing in this series. But as long as I have the same way every morning, I will continue to make this pictures and add them to the slideshow.

For now there are more than 30 pictures and the are all dated, so you can check on the weather on this days icon wink Marktkirche Wiesbaden   a small photo experiment

I started this end of October. I have no idea how long I will do this, but I think the more images there are, the more interesting is this experiment.

And now, have fun watching those pictures:

marktkirche wiesbaden Marktkirche Wiesbaden   a small photo experiment

FLOW3 – Using the same Layouts and Partials for different packages

I had the problem that I want to set up a web project that contains multiple packages. It did take me some time to figure how to handle this and I am still sure, that it is not the best way. The following is, what I want to achieve.

I have a base package and multiple sub packages. The base package should contain the layout file that is used for all the other packages as well. So this part was not that hard. There is a function called setLayoutPathAndFilename that can be triggered in the initializeView function. So I build a base controller that I use to extend my action controllers and voila, I have the same layout in all packages that extend this base controller.

This looks like follows:

/**
 * Abstract Controller for the FUGRM.Base package
 *
 * @FLOW3\Scope("singleton")
 */
class AbstractController extends \TYPO3\FLOW3\MVC\Controller\ActionController {

    public function initializeView(\TYPO3\FLOW3\MVC\View\ViewInterface $view) {
        $view->setLayoutPathAndFilename('../Packages/Application/FUGRM.Base/Resources/Private/Layouts/Index.html');
    }

}

And any other controller:

 

class IndexController extends \FUGRM\Base\Controller\AbstractController {
}

 

Now comes the second part. There is a partial inside my layout. The navigation. I will have the same navigation for all packages. Not that hard. I just do the same thing, that I did for the layout for the partial. Function has a different name here and what you do is not setting the file, but setting the partial root path. So now we have the navigation available in every package.

But what if one of the sub packages wants to use partials? It does not make sense putting this partials inside the base package. So what to do?

Solution for me was, to change the path to the partials root folder. The complete thing looks like follows:

/**
 * Abstract Controller for the FUGRM.Base package
 *
 * @FLOW3\Scope("singleton")
 */
class AbstractController extends \TYPO3\FLOW3\MVC\Controller\ActionController {

 public function initializeView(\TYPO3\FLOW3\MVC\View\ViewInterface $view) {
 $view->setLayoutPathAndFilename('../Packages/Application/FUGRM.Base/Resources/Private/Layouts/Index.html');
 $view->setPartialRootPath('../Packages/Application');
 }

}

Now we have the problem that all partials are search in Packages/Application, where of course are no partials at all. The solution for this is to use the full name for the partial.

For example:

<f:render partial="FUGRM.Base/Resources/Private/Partials/Navigation" />

This works for me for now. But I am looking forward for any other solution. Didn’t find anything in the documentation and looking into the source code of FLOW3/Fluid did not help much.

One last thing I just forgot. To make the css and js work in your subpackages, you have to add the package to the layout HTML file.

<link rel="stylesheet" href="{f:uri.resource(path: 'Css/Fonts.css', package: 'FUGRM.Base')}" type="text/css" media="all" />

Productivity with PHPStorm

Since there are a lot of people out there working with PHPStorm I thought I try to write an article about how I try to get the maximum productivity out of this IDE. Also I have the hope that there are some other people out there who have some good tips for me.

Here I just want to show my favorite shortcuts and I want to explain how I try to learn new shortcuts each day. This are just my favorite shortcuts. There are so many more like search for classes, methods and files, navigating between open editor windows. And more, and more, and more……

  1. Shortcuts
    1. QuickJump (Plugin)
      Just learned about this plugin some a day ago and since that, I am using it all the time. It is a really easy way to navigate from one piece of code to another. Check out http://plugins.intellij.net/plugin/?webide&id=6311 or take a look at the video on: http://johnlindquist.com/2011/09/12/intro-to-the-quickjump-plugin/
    2. KeyPromoter (Plugin)
      Good for learning short cuts. Each time you use the menu or the mouse for a function that is available via a shortcut, your IDE will tell you.
    3. Complete Statement (Ctrl+Shift+Enter)
      There is a really good auto-complete in PHPStorm. But if you use the auto-complete and call a function e.g., than you got stuck between your brackets where your entered your parameter from time to time. To leave the brackets and add the semicolon at the end of the call, press Ctrl+Shift+Enter
    4. Last edit location
      Edited some code and moved on to another part of the code to look something up? Now you to scroll back where you made your last change? You don’t need to, just hit Ctrl+Shift+Backspace to jump to your last edit location, even through multiple files.
    5. Bookmarks in your file
      This is interesting if you now that you have to work on two or more parts on your code and that you want to jump between this places. Set a bookmark and jump.
      Ctrl+Shift+<number> to set, Ctrl+<number> to jump there
  2. Search in each window directly
    There is a search function in all windows. For example, if you are in the structure view, and you now this function somewhere in t3lib_div, click anywhere in the structure view and start typing the name of the function you search. You can also open the structure view by using Alt+7
  3. LiveTemplates
    I use live templates mostly for fluid. I created live templates for the most common fluid snippets and if I have to add a form for example, I just use the shortcut for live templates and start tipping form and select my fluid form. Now I only have to enter the data like action and controller.
  4. FileTemplates
    I also added a couple of FileTemplates, mainly for Extbase and Fluid files that automatically set the correct namespace and author. I have some examples, perhaps they are out of date, on my web page: http://www.layh.com/work/flow3-fluid/flow3/file-templates-for-phpstorm.html

Also if you start up your IDE, you will get a Tip-of-the-day. Sometimes I think it is bullshit and I turn it of, but why not see this message ones a day and try to use this promoted shortcut throughout the day. There are some really useful tips.

There is a keyboard reference on the Jetbrains website: http://www.jetbrains.com/phpstorm/documentation/index.html . But for me, this document is way to much and written to small to have a short look. So I took the most important short cuts from this reference and added them to file, printed this out in large and put it on my desk to always have the shortcuts in front of me. From time to time I change this a little bit to learn some new shortcuts and to remove the shortcuts I already learned.

As an additional resource I can recommend the PHPStorm blog. They have some good tips from time to time. http://blog.jetbrains.com/webide/

Hope I could help someone to be more productive and to have more fun with your favorite IDE. I am also look forward to your comments and hints.

PHPStorm and TYPO3 code formatting

I was searching for the import function almost forever until I figured out how to use the TYPO3 code formatting xml file provided in the TYPO3 wiki.

So here is a short article how to import the file and where to find it.

  1. Download the xml file from: http://wiki.typo3.org/File:Standard.xml
  2. [optional] Open the xml file in the editor of your choice and change the schema name at the top of the file from Standard to something that is later more easy to identify in your IDE.
  3. Copy the file to your user-files for PHPStorm, depending on your system. In Windows7 it is in C:\\Users\\<username>\\.WebIde10\\config\\codestyles
  4. Restart your IDE if it is running, otherwise just start it.
  5. Go to: Settings -> Code Style
  6. If you copied the file to the correct place it should show up in the select box. If you choose the option at point 2 and renamed the schema, you will find it under the new name, otherwise it will be “Standard”
  7. Select it, press apply, enjoy clean code.

But remember, good code formatting alone does not make good code icon wink PHPStorm and TYPO3 code formatting

Hope I could help someone.

Update (thx @tolleiv):

For the Max OSX users – /Users//Library/Preferences/WebIDE10/codestyles

Your ideas wanted: twitcode.org round 2

twitcode 300x41 Your ideas wanted: twitcode.org round 2

It is a while ago since I last worked on my Twitcode project. The main reason for that was, that there have been so much changes in FLOW3 and that I wanted to wait for beta1 for the next bigger update. After the release of alpha15, what is, as far as I know, pretty close to beta1, I decided to start working based on the current master.

Besides all the stuff that has to be done to bring Twitcode up and running again on the current master, I also want to have some more features in the next release.

This is where your ideas are wanted. Currently the next steps for me will be to add a comment function on each snippet and to add a user profile, where you can set some notification settings for comments on you snippets.

Another idea is to add some kind of bookmarks where you can save your most favorite snippets.

And now you!! Tell me your ideas. What would be a nice feature? Add your comments here or add them as an issue in github:

https://github.com/tlayh/Twitcode/issues

Another gallery plugin for TYPO3 ??

I started a while ago because I did not found a gallery plugin that fits my needs. So I started to implement one, based on the AD Gallery.

I just wrapped an extbase extension around the AD Gallery and added the lightbox feature.

Currently I implemented the gallery only on two pages of my website. This should demonstrate how it looks like with a single gallery and with a set of galleries.

http://www.layh.com/bilder/dubai-2006.html

http://www.layh.com/bilder/snowboarden-0910.html

Take a look and let me know if it is worth continuing the work and make it more configurable and write the documentation required for the upload to the TER. You can find the source code here: https://gitorious.org/tl_adgallery/tl_adgallery

I know there are more than enough gallery plugins available in the TER, so leave me a note if you think I should push this to the TER.

FLOW3 – Getting Started – Writing your own validator

Some time ago I wrote a tutorial about a registration and a login. I thought it will be a good idea to force the user to use a strong password so here is a tutorial about writing a password validator for our registration. We have to change some things in our old registration but it will not take long.

Keep on reading here: PasswordValidator

 

FLOW3 – Getting Started Tutorial Updated.

Since there have been a lot of changes in #FLOW3 during the last days and I learned some new stuff at the #T3DD11 to I just updated my FLOW3 Tutorials to the current changes.

Until now I only updated the source code, I will rewrite the text as soon as I find the time.

The biggest new change is the usage of vendor namespaces. This means every package key is not only the package name but also contains the vendor namespace. For my example I added the vendor namespace Layh, so my new package key is Layh.Events.

Before this changes the namespace for my package started with \F3\Events\…. and has changed to \Layh\Events\… now. Also all FLOW3 namespaces have changed from \F3\FLOW3\… to \TYPO3\FLOW3\

Another change is that we don’t have any id’s anymore since everything is working with uuids now that are automatically created. So I also removed all id’s from my package.

The creation of a user account, where we had to generate a random string for the salted passwords has moved to the AccountFactory now and adding a new account is much more easy now.

That are the biggest changes. More to come soon……

The tutorial.

FLOW3 – Getting Started – Part nine and ten – Aspects and Settings

And there they are, two more parts for the tutorial are just finished and ready to launch. Big thanks to Michael Klapper for the help with the Aspects, learned something new for myself.

Working with settings

Aspects

Next parts will be writing your own Validator and writing TypeConverters. But it will take me until the weekend to finish it.