Examples5.8 Feature showcase: Accessing class internaat 2010-08-30 in Examples, 5.8-SERIES by friebe The XP Framework's 5.8-SERIES contains a feature that will allow the reflection API to access private and protected members. Of course, just because you can, doesn't mean you should, as this does allow you to break the encapsulation principle.On the other side, this feature comes in handy for serialization mechanisms, as well as for reflection-based factory or delegation patterns. (more) Generics of primitivesat 2010-08-10 in Examples, 5.8-SERIES by friebeLike in C# (and unlike Java), primitives can be used as components of generics in the 5.8-SERIES. Given a vector util.collections.Vector<string>, the following applies: // OK Primitives can also be used in other generic collections types, e.g. Set and Map implementations as well as Stack and Queue. Fluent XML with the XP Frameworkat 2010-06-22 in Examples by friebeTo create an XML tree programmatically, the XP Framework has offered the xml.Tree class since its beginning in 2001. Recently, we've added a fluent interface to it, allowing for the following: $t= create(new Tree())->withRoot(create(new Node('book')) Merging XAR filesat 2010-01-30 in Examples by kieselWith the 5.7.7-RELEASE there has a nitfy small feature been added to the xar command: merging multiple XAR files. XAR files are the archives in which XP Framework applications can ship their classes and/or resource files in a way comparable to Java`s .jar-files. Combining multiple xar files into one can be handy one the one hand, because you can merge all dependencies and the application itself into one single file and only have to provide the one. On the other hand, for applications where startup or I/O performance is a concern, it can be useful: each xar file involved in an application comes with a startup time penalty - the file must be opened, the index must be read before the first file can be retrieved. Here, a single file instead of many files mean increased startup performance and less I/O calls of an application. This is how it works:
Reading gzip'ed websitesat 2010-01-08 in Examples by friebeTo reduce bandwidth some servers have their content zipped using solutions such as Apache's mod_deflate. This is done only if the Accept-Encoding request header contains the string gzip. Combining the XP Framework's peer.http API with the new io.streams.GzDecompressingInputStream one can accomplish this compression: $conn= new HttpConnection($args[0]); Compressing dataat 2010-01-06 in Examples by friebe The possibly easiest way to compress data in PHP is to use the string-in, string-out functions such as gzdeflate or bzcompress. For small number of bytes being passed in, this is fast and convenient, but it doesn't do well when working with large files, for example:FileUtil::setContents(In one test I ran here, this piece of code used roughly 50MB peaks to compress a 26 MB input file. As of 5.7.7, the XP Framework will provide compressing output streams enabling you to compress one chunk at a time and saving more than 90% of memory: $is= $in->getInputStream();Sure, this is more code, but it constantly uses not more than 0.5 MB while running. If you now have a look at the new io.streams.StreamTransfer class you can simplify the above code even more (and still save the memory). Type duplication in xpcli injectionsat 2009-10-14 in Examples, Announcements by friebeIt's just become another bit easier to write command line classes in the XP framework ("xpclis"). When using the @inject annotation you no longer have to specify the type parameter if you use a so-called "type hint" - so instead of writing the following: #[@inject(type= 'rdbms.DBConnection', name= 'caffeine')]...you can now omit the type part - it will be inferred from the first parameter's type: #[@inject(name= 'caffeine')] New xml.Node::withChild() methodat 2009-09-21 in Examples by friebeTo easily create XML documents, the xml.Node class has been extended with a new withChild() method complementing addChild(). In contrast to the latter, withChild() returns the node the child was added to instead of the added child. (more) Unified runners in the webat 2009-08-11 in Examples, Editorial, Announcements by kieselThe XP framework had offered developers the power of an easy class loading setup via the new XP runners that are delivered with every release since several releases now. These runners have proven themselves very useful in day-to-day business, so we're working on porting them to the web! With the so-called web-runners these new cool and useful features will become available for you:
(more) Redirecting console outputat 2009-07-12 in Examples by friebeTo capture output written by any of the PHP functions the ouput control functions can be used (ob_start(), ob_get_contents() and friends). These functions do not affect the output made by the util.cmd.Console class as this writes directly to the standard out and error streams. To redirect these, you can use the following: // Save original stream in variable, change output stream to $stream This can be useful in unittests, when running command line applications inside a web container or inside GUIs, or whatever other usecase you can invent |
|