dracoblue.net

Mounting SSH/SFTP Remote Folders in Eclipse

If you are using windows as operating system and want to access files available on unix-based remote file systems, you have only limited amount of options. In case you are using Eclipse as development environment, we'll have a look at an alternative, which does not use samba-shares.

A nice option is the plugin

Target Management (RSE). It allows you to add any remote systems to the remote file system explorer.

Once RSE is installed, you are able to add a folder (like you did before) but link it to local or RSE location. Select RSE and choose the path on your remote system!

In Eclipse, open source by DracoBlue @ 2009-04-01 | 103 Words

Fixing compiling issues with magnet.c

Jan Kneschke maintains lighttpd and posted a simple FCGI for lua. This magnet.c should be easily compiled with

 gcc -Wall -O2 -g -o magnet magnet.c -llua5.1 -lfcgi -ldl -lm

This may not work if your lua-include is not in the path for compiling.

And you'll run into such error messages:

magnet.c:3:20: error: lualib.h: No such file or directory
magnet.c:4:21: error: lauxlib.h: No such file or directory
magnet.c:11: Error: expected »)« before »*« token
magnet.c:19: Error: expected »)« before »*« token
magnet.c:59: Error: expected »)« before »*« token

Since you may not be used to compiling, I think it might be good to post a reason for that and a solution.

The reason is, that lualib.h is not in include path. To add it specific folder for the compiling to the include path you may use the

-I /path/name/ parameter.

 gcc -Wall -O2 -g -o magnet magnet.c [strong]-I/usr/include/lua5.1/[/strong] -llua5.1 -lfcgi -ldl -lm
There are some distributions, where the -llua5.1 may not work and result in cannot find -llua5.1. In this cases try -llua instead.

Have fun compiling!

In Lua, open source by DracoBlue @ 2009-03-19 | 178 Words

Action/View/Module und Route in Agavi rausfinden

Für jedes Module, jede Action(+View) gibt es den ExecutionContainer (AgaviExecutionContainer). Wenn Du also das aktuelle Module, die ausgeführte Action oder den View rausfinden möchtest, machst Du das am einfachsten so:

$action = $this->getContext()->getActionName();
$view = $this->getContext()->getViewName();
$module = $container->getModuleName();

Aber was, wenn Du die "richtige" Action rausfinden möchtest? Die einzig wahre - für den Request? Das ist ein kleines bisschen schwieriger. Hier eine kurze Erklärung wie und warum das geht.

Wann immer man Agavi die Arbeit machen lässt (Umwandeln von Eingabedaten und dem eigentlichen Webbrowseraufruf des Users, in validierte Daten), passiert immer das gleiche. Es wird eine Action gestartet, der View für den passenden Outputtype ausgeführt und das Template gefüllt. Beim Erstellen eines Slots (z.B. aus der View herraus) wird wieder Validierung+Action+View für die Slot-Parameter ausgeführt.

Deshalb kann der echte die Request-Route nicht im ExecutionContainer gefunden werden, sondern irgendwo anders. Im Request.

$route_names = $this->getContext()->getRequest()->getAttribute(
					'matched_routes', 'org.agavi.routing'
				);

Die Variable $route_names enthalt dann ein Array mit allen Route-Namen:

array(
	'product.edit'
	// Die aktuelle Route heißt "product.edit"
	// in der routing.xml
)

Diese Information hilft uns indirekt um nun auf die Action zu kommen, welche eigentlich ausgeführt wurde. Da das WebRouting auch eine getRoute-Methode hat, welche nur einen route_name erwartet, können wir die Information nun einfach auslesen:

// wir wollen nur die erste route, deswegen
// im Stil list($first) = $array
[strong]list($route_name)[/strong] = $this->getContext()->getRequest()->getAttribute(
	'matched_routes', 'org.agavi.routing'
);

$route = $this->getContext()->getRouting()->getRoute($route_name);

Die neue $route-Variable beinhaltet nun alle Informationen über die Route. In unserem Fall ist aber nur spezielles wichtig.

$module = $route['opt']['module'];
$action = $route['opt']['action'];

Diese Methode sollte man wirklich

nur benutzen, wenn man einen universellen Slot hat, weöcher direkt in einer output_types.xml oder in verschiedenen Seiten benutzt wird und selbstständig und über das modul+action rausfinden kann, wo er eigentlich eingebunden ist.

In Agavi, open source, php by DracoBlue @ 2009-03-05 | 290 Words

Detect action/view/module and matched route in agavi

For each executed Module/Action(+View) there is an ExecutionContainer (AgaviExecutionContainer). So if you want to retrieve the current executed action, module or view, best is to do

$action = $this->getContext()->getActionName();
$view = $this->getContext()->getViewName();
$module = $container->getModuleName();

But what if you want to retrieve the "real" action, the one and only for the request? That's a little bit more difficult, so here a short introduction how to deal with that.

Whenever the routing of agavi does the work for you, by turning the input data and webbrowser call of a user, into a action and validated data, it triggers an action, executes the view for the outputtype and fills the template. But Slots can be used from the view and trigger then again validation+action+view for their parameters.

This is why the real request route can not be found in the execution container and must be found somewhere else. In the Request.

$route_names = $this->getContext()->getRequest()->getAttribute(
					'matched_routes', 'org.agavi.routing'
				);

The route_names is nothing but an array, for instance:

array(
	'product.edit'
	// because our current route is named "product.edit"
	// in routing.xml
)

This information does help us indirectly to determine the action, which got called! Since the WebRouting has also a getRoute-method, which expects just a route_name, we can retrieve the info now easily:

// we want to have just the first one,
// thatswhy list($first) = $array style
[strong]list($route_name)[/strong] = $this->getContext()->getRequest()->getAttribute(
	'matched_routes', 'org.agavi.routing'
);

$route = $this->getContext()->getRouting()->getRoute($route_name);

The new $route-Variable now holds an array of all information about the route. In our case, just some are interesting.

$module = $route['opt']['module'];
$action = $route['opt']['action'];

One really should use that

only in case of a default slot, which is used directly in the output_types.xml or used on serveral different pages and has to determine on its own and by using module+action where it's actually embedded.

In Agavi, open source, php by DracoBlue @ 2009-03-05 | 300 Words

PDT auto completion tips (for agavi)

In PDT (php development tools for eclipse) you are able to do auto completion (e.g. ctrl+space) on most of the classes, as long as they are defined properly or you have a proper php-doc set up. Check that tutorial, if you want to set up PDT.

Graste posted a snippet, which tells eclipse for the project (in this example it's agavi) that the variables (which are common for templates), like $template (or $ro, $rd and so on) are defined with correct type.

Here is a slightly modified autocomplete.php:

<?php
exit();
$slots = array();
$template = array(); // agavi 0.11 default
$t = array(); // agavi 1.0 default
$tm = new AgaviTranslationManager();
$ro = new AgaviWebRouting();
$rq = new AgaviWebRequest();
$ct = new AgaviController();
$us = new AgaviSecurityUser();
$rd = new AgaviWebRequestDataHolder();
?>

Just save that file to autocomplete.php in your project structure -> eclipse will use this classes as default, so you have neat auto completion even in agavi templates.

If you have return type for a function, and want the caller to be able to autocomplete: just use proper php-docs. For example, the following will give SomeClass-typed elements on a function test123:

/**
 * [strong]@return SomeClass[/strong]
 */
function test123() {
	/* ... */
}

If you just want autocomplete for a specific scope, you may use the following:

if (false) $instance = new [strong]SomeClass[/strong]();

or better

/* @var $instance [strong]SomeClass[/strong] */

and auto completion on $instance will work like if it was a SomeClass.

Got another tip? Feel free to add it in the comments!

In Agavi, Eclipse, PDT for Eclipse, open source, php by DracoBlue @ 2009-02-23 | 259 Words

Page 27 - Page 28 - Page 29