Blog
2007 09 posts (10)
Ordering: Ascending Descending
1. Namespaces already in PHP 5.3
2007-09-29 16:35:28 by Martynas Jusevičius
As some people have already reported, PHP 5.3 has namespace support already submitted to its codebase. This is great news, since PHP was really lacking this feature.
2. DIY tips: Inheriting Resources
2007-09-24 18:08:08 by Martynas Jusevičius
Often you have a situation where many Resources have to share the same properties and/or behavior. For example, all Resources in a backend administration application should deny access to users that are not logged on.
A nice and simple solution is to create a parent Resource for the whole application and let all the specific backend Resources to inherit it.
Here is an example. BackEndResource is a general Resource for the whole backend application:
class BackEndResource extends BaseBackEndResource
{
public function doGet(Request $request, Response $response)
{
$view = parent::doGet($request, $response);
if ($request->getSession()->getAttribute("user") instanceof GuestUser) $view = new ForbiddenView($this);
return $view;
}
}Other backend Resources inherit it:
class AdminResource extends BackEndResource
{
public function doGet(Request $request, Response $response)
{
$view = null;
$parent = parent::doGet($request, $response);
if ($parent != null) $view = $parent;
else $view = new AdminView($this);
return $view;
}
}If a user is accessing AdminResource or any other backend Resource and is not logged on (i. e. user object in the session is an instance of GuestUser), ForbiddenView is displayed with an appropriate message. Otherwise, AdminView is displayed as normally.
In such a way a single line of code allows you to control access to the whole application.
3. Open-source PHP profiler
2007-09-18 20:57:33 by Martynas Jusevičius
We were looking for a simple open-source PHP profiler, without any fancy IDEs like Zend bundled together. After a little search, we found one: Xdebug, debugger and profiler tool for PHP. It installs as a PHP extension. When you execute your scripts, it simply writes debug information into a file. You can later open and analyze it with a special viewer: KCachegrind for Linux or WinCacheGrind for Windows.
4. How to Publish Linked Data on the Web
2007-09-14 18:21:36 by Martynas Jusevičius
We came across a great read by Ch. Bizer, R. Cyganiak, T. Heath: How to Publish Linked Data on the Web. In a nice and simple manner it describes the basic things you need to know before implementing some practical Semantic Web applications. The abstract goes like this:
This document provides a tutorial on how to publish Linked Data on the Web. After a general overview of the concept of Linked Data, we describe several practical recipes for publishing information as Linked Data on the Web.
5. Escaped slash bug in Apache
2007-09-13 20:23:30 by Martynas Jusevičius
We encoutered an apparently 6-year-old bug in Apache, which might as well be a security feature
: it treats escaped (URL-encoded) slashes (which become %2F) as normal slashes / in a URL and returns 404 Not Found if such a URL is requested. It does not even come to PHP.
UPDATE: Fortunately, it seems that it actually is a security feature and there is Apache's AllowEncodedSlashes directive to turn it off. There is also a hack by Frédérick Giasson.
6. DIY tips: XSLT template modes
2007-09-10 11:09:33 by Martynas Jusevičius
Working with Views, sometimes you need the same kind of objects rendered in different ways, depending on the situation. For example, you might want to be able to display an array of products as a list as well as a table. That means each product item should be rendered either as a list item or as a table row.
As you define templates for product items in XSLT, you need a way to differentiate between the two kinds. Here is where template modes come in handy. You can define templates with the same match but different modes, and choose the mode later when applying them. That is excatly what we need — product item templates with list and table modes:
<xsl:template match="Product" mode="list">
<li>
<a href="{@resource}{$query-string}">
<xsl:value-of select="Title"/> (<xsl:value-of select="@price"/>)
</a>
</li>
</xsl:template>
<xsl:template match="Product" mode="table">
<tr>
<td>
<xsl:value-of select="@code"/>
</td>
<td>
<a href="{@resource}{$query-string}">
<xsl:value-of select="Title"/>
</a>
</td>
<td>
<xsl:value-of select="@price"/>
</td>
</tr>
</xsl:template>They can be applied as follows:
<ul>
<xsl:apply-templates select="/Products/Product" mode="list"/>
</ul>
<tbody>
<xsl:apply-templates select="/Products/Product" mode="table"/>
</tbody>7. OOXML drama
2007-09-07 18:00:44 by Martynas Jusevičius
This week, there was a lot attention to ISO (International Standards Organization) as it voted whether to approve Microsoft's OOXML (Open Office XML) format as a standard for office applications. To make it happen, 75% of ISO members countries had to vote for.
There is already one standard for that — ODF (OpenDocument Format), which is favored by the open-source community. There were a lot of debates and objections as to whether another standard is necessary, especially given that it is built on Microsoft's proprietary format. Moreover, there has been controversy about Microsoft pushing the national standard bodies to approve OOXML. Swedish vote in favor of Microsoft's format was invalidated for that reason.
This time, ISO has not approved OOXML on a fast-track basis. However, Microsoft will get another try after it reviews the comments submitted by ISO member countries, most likely in February 2008.
8. Developers do not get GET
2007-09-04 15:32:12 by Martynas Jusevičius
It is becoming a worrying trend that developers (even those of the more popular services and frameworks) do not know or respect semantics of the HTTP protocol:
All of these examples are proposing URLs such as /users/delete/1 or /posts/add for editing or deleting resources via the HTTP GET method. While they probably pretend to be RESTful, they are in fact breaking HTTP and REST semantics. HTPP 1.1: Method Definitions states that GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe".
and that GET is idempotent. In other words, sending GET request should not change server state.
UPDATE: Not Ruby on Rails itself, only a tutorial on it.
9. Website speed test
2007-09-02 23:07:26 by Martynas Jusevičius
While working on database query optimizations with Propel, we got an idea to check how our website compares with others in terms of loading speed.
According to Website Speed Test tool, it is doing pretty well (even without running the latest version of the DIY Framework): the front page currently is 20.54 KB and takes 0.44 seconds to load, resulting in average 0.02 seconds per KB.
How does your website compare? Server location of course makes a difference. According to VisualRoute, seems like our is located in Dallas, TX, USA.
10. Propel 1.3
2007-09-01 20:49:12 by Martynas Jusevičius
Version 1.3 of Propel (a popular and very useful ORM tool) is in the works, currently released as beta. We believe it should bring substantial improvements and we are going to switch to it sooner or later. Upgrading will involve several things:
- New PHP minimum requirements
- Use of PDO instead of Creole
- New DSN format for build and runtime properties
- New transaction API
- Some method signature changes
- 'mysqli' adapter is obsolete & has been removed
- New SPL autoload integration
Fore more information check the Upgrading Guide.
Ordering: Ascending Descending
