Monday, July 28, 2008
By thomasw at 00:08:38
Hy interested ones,
a new feature has been added within Zend Framework. it now supports the usage of an application wide locale. Anyone who is using I18N classes in his application will love this feature.
So what’s all about this new feature…. let’s look into details. Until Zend Framework 1.5 when you wanted to use several I18N aware classes you had to set the locale you wanted to use within all classes. This looked like this:
$locale = new Zend_Locale('en_US');
$date1 = new Zend_Date($locale);
$date2 = new Zend_Date($locale);
$currency = new Zend_Currency($locale);
When you use only one or two instances there is not much difference. But the more instances you use the more work you would have with the syntax. Looking at this in detail I thought why not simply set the locale once within your bootstrap and let the framework do the rest.
The solution was the usage of the registry. So let’s look at the same example and the difference in the usage:
$locale = new Zend_Locale('en_US');
Zend_Registry::set('Zend_Locale', $locale);
...
$date1 = new Zend_Date();
$date2 = new Zend_Date();
$currency = new Zend_Currency();
As you can notice now, you can forget about the locale as it’s automatically taken from the registry. This is a small and simple solution but it will solve you several headache. You can use this feature within the actual trunk or you have to wait until 1.6GA is released.
Have fun with it, anyway.
Greetings,
Thomas Weidner, I18N Team Leader, Zend Framework
Sunday, July 20, 2008
By thomasw at 22:56:00
Hy interested ones,
the new Zend_File_Transfer component is growing day for day.
As incredible new feature this component allows to use file validators.
These are necessary to increase security and allow to define rules for file uploads (and also downloads in future). So let’s see some examples to get a feeling:
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidators('Size', '50kB)
->setDestination('C:/uploads')
->receive();
What we’ve done so far is to limit all sent files to 50kB filesize. Any file which is uploaded and exceeds the size of 50kB will throw an exception we can catch.
The more rules we define the more secure our upload will be.
So which other validators are supported until now:
- Size: We already know this validator. He checks the filesize of single file. You can set a minimum and a maximum filesize.
- Count: You should set this validator to represent exactly the amount of files you expect. He has also a mimimum and a maximum filecount. If this validator throws an error you are probably having an attack. But you can also limit the number of files to receive with this validator.
- Extension: This validator checks for the extension of files. You can set multiple extensions to be checked. But remember that an evil user can manually change the extension so you should not rely only on the extension.
- FilesSize: This validator also checks for the size of files. But different to the Size validator it checks for the size of ALL files. You could for example define that a single file must not exceed 50kB. But all files in sum must not exceed 200kB.
- ImageSize: The ImageSize validator checks the size of given files when they are images. You can define a mimimum and a maximum image size for width and height.
So let’s see a full example of validators and a more secure upload:
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidators('Size', '250kB')
->addValidators('Count', 5)
->addValidators('FilesSize', '1MB')
->addValidators('Extension', 'gif, jpg, png')
->addValidators('ImageSize', array(10, 10, 1024, 768))
->setDestination('C:/uploads');
if (!$upload->isValid()) {
print_r($upload->getMessages());
die();
}
try {
$upload->receive();
} catch (Zend_File_Transfer_Exception $e) {
$e->getMessage();
}
So what we’ve created now is a fileupload for images.
Each imagefile can have 250kB maximum filesize. We allow in sum 5 images but all images im sum are not allowed to exceed 1MB. Additionally we allow gif, jpg and png files and define a imagesize of 10×10 up to 1024×768. All files are uploaded to ‘C:\uploads’.
As you see it’s not complicated to define a more secure upload then just using php’s move_uploaded_file.
Feel free to play around with this example.
If future there will be additional validators like MimeType and FileName.
Also filter will be added which allow you to change uploaded files on the fly before they are stored.
Filters could contain the automatic change of imagesize or changing textfiles to have a proper lineending and much more.
Greetings
Thomas, I18N Team Leader, Zend Framework
Sunday, March 2, 2008
By thomasw at 19:57:05
Hy framework users…
Most of you are already using Zend Translate. Until now the option for scanning a directory for translation files was only available when creating the instance.
I added this feature now also for the addTranslation() method, which means that you are now able to add new directories afterwards. This feature is handy when you are working with a modul based implementation and have also the translations seperated per module.
For those who did not know this feature for now is here a short description:
Instead of adding several translations manually it’s much more convinient to have them added automatically by only one method call.
Depreciated way:
$translate = new Zend_Translate('gettext', '/my/proj/lang/en/proj.mo', 'en');
$translate->addTranslation('/my/proj/lang/de/proj.mo', 'de');
$translate->addTranslation('/my/proj/lang/fr/proj.mo', 'fr');
As you see we have only added three languages… if you are working with seperated translation you will probably have not only one file per language but more.
So it would be better to have this done by Zend_Translate itself… see the following code:
$translate = new Zend_Translate('gettext', '/my/proj/lang/', 'en',
array('scan' => Zend_Translate::LOCALE_DIRECTORY));
So what is now hapening in the background:
Zend_Translate recognises a directory instead of a file.
With the ’scan’ option we said that the locale/language is written in the directory name.
Zend_Translate will now search all sub-directories within the lang directory and add all found translations.
It uses the directory name as locale if it fits…
So a file ‘/my/proj/lang/de/proj.mo’ would be added within the locale ‘de’ because this directory is recognised as german locale and so on… it doesn’t matter how deep the directory structure is, all subdirectories will be searched.
This works not only with gettext but also with any other adapter like TMX, Array, Csv and so on… the only thing which has to fit is the name of the directory.
But there is also another way to get the name of the locale. It can be written within the filename.
'/my/proj/lang/myfile_de.mo'
'/my/file/lang/myfile-de.mo'
'/my/file/lang/myfile.de.mo'
All of this three ways of naming files will be recognised translation for the locale ‘de’.
To use this way of naming you will only have to use the ’scan’ option with the Zend_Locale::LOCALE_FILENAME constant.
Have fun with the framework.
Greetings
Thomas
I18N Team Leader of the Zend Framework
Saturday, March 1, 2008
By thomasw at 17:28:48
For interested people I attached a small description of changes between 1.0.3 and 1.0.4 of Zend Framework which are related to the I18N core:
All classes:
* Failed autodetection no longer throws a exception (seen under Ubutu in past)
Zend_Date:
* Timezones now work even if the new DateTime extension is not present (seen under PHP < 5.2 and self compiled Linux version)
* added a note about the ISO year and real year formats as both are often switched by users which produces unexpected behaviour
Zend_Locale:
* setting a default locale is now supported, default is “en” but it can be set to anything else
* included the new CLDR 1.5.1 and reworked the data classes which adds several new informations to be available… f.e. timezone for region, currency for language and much much more
* added detection for @ locales (f.e. de_DE@euro)
Zend_TimeSync:
* added a new component to syncronise the server time when there is no service available
Zend_Validate:
* added support for localized dates for Zend_Validate_Date
Zend_View_Helper_Translate:
* added a new View Helper for allowing translations from within the view
Informations for the new ZF 1.5 will come soon
Greetings
Thomas, I18N Team Leader Zend Framwork
Sunday, January 20, 2008
By thomasw at 14:07:39
Hy Leute,
ich habe mit Simon Mundy zusammen etwas am PDO MSSQL Adapter gearbeitet. Wir sind auf einige Probleme und Lösungen gekommen die wir in den nächsten Tagen fertigstellen werden. Wenn wir fertig sind kann man sagen das MSSQL komplett und hoffentlich problemlos unterstützt werden wird.
Wir haben auch Unterstützung für Transactions integriert die bisher nicht vorhanden war. Getestet wurde alles gegen eine MSSQL EXPRESS 2005 und MSDE 2000 und sollte somit auch mit den höherwertigen Servervarianten MSSQL 2005 und MSSQL 2000 problemlos funktionieren.
Warscheinlich werden wir auch eine Hilfe in die Dokumentation integrieren wie MSSQL zum laufen gebracht werden kann. Im Prinzip steht alles im Netz, trotzdem ist es oft schwierig richtig an die Sache heranzugehen wenn man damit keine Erfahrung hat. Eine Art Kochrezept sollte helfen.
Grüße
Thomas alias BlackSheep
———————————————
Hy fellows,
I worked with Simon Mundy together on the PDO MSSQL adapter. We found some problems and solutions which we will finish in the next few days. When we are ready then we can say that MSSQL is complete and hopefully supported without any known problems.
We have also integrated support for transactions which were not available until now. We’ve tested against a MSSQL EXPRESS 2005 and MSDE 2000 which means that also the bigger server variants MSSSQL 2005 and MSSQL 2000 should work without problems.
Probably we will also integrate a help into the documentation on how MSSQL can be integrated. Principal all can be found in the net, sometimes it is however hard to find the right solution if there is no experience. A sort of cookbook should help.
Friday, January 18, 2008
By thomasw at 13:20:12
Die Dokumentation wurde von Müsli schnell nochmal mit einem Index versehen.
Anbei die aktualisierte Datei:
Zend Framework CHM Manual
Danke Müsli für die Mühe.
Grüße
Thomas
Wednesday, January 16, 2008
By thomasw at 23:23:41
Wie ich auch, haben viele von euch schon diverse Male mit Verärgerung festgestellt das die Doku im Zend Framework nur als Multi-HTML Seiten zum Download zur Verfügung steht. Um alles einfacher zu machen habe ich im ZF Forum angeregt das CHM Format auch als Download zur Verfügung zu stellen und habe ein deutsches und ein englisches CHM selbst erzeugt.
Hier findet Ihr die aktuellste deutsche Doku vom Trunk als CHM Datei
Solltet Ihr das bestehende Format verbessern mit Indezes oder Inhaltsverzeichnis, schickt mir einfach die verbesserte Version zurück. Ich kümmere mich dann um alles weitere.
Die betreffenden Dateien findet Ihr hier… *Projekt* *Index* und *TOC*