View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_View_Helper_FileSize
{zone-data}

{zone-data:proposer-list}
[Martin Hujer|mailto:mhujer@gmail.com]
{zone-data}

{zone-data:liaison}
[~freak]
{zone-data}

{zone-data:revision}
1.0 - 5th April 2008: Initial proposal.
1.1 - 1st July 2008: Almost finished proposal.
1.2 - 12th August 2010: Code and Unit Tests are working
{zone-data}

{zone-data:overview}
Zend_View_Helper_FileSize is a simple helper that formats any filesize in bytes to human readable string.
{zone-data}

{zone-data:references}
* [Mhujer_View_Helper_FileSize docs|http://code.google.com/p/zfextra/wiki/Mhujer_View_Helper_FileSize]
* [Zym_View_Helper_FileSize source|http://zym.googlecode.com/svn/trunk/incubator/library/Zym/View/Helper/FileSize.php]
* [Zym_View_Helper_FileSize test|http://zym.googlecode.com/svn/trunk/incubator/tests/Zym/View/Helper/FileSizeTest.php]

{zone-data}

{zone-data:requirements}
* This helper *will* correctly formats any filesize in bytes to human readable string.
{zone-data}

{zone-data:dependencies}
* Zend_Exception
* Zend_Registry (optional
* Zend_Locale (optional)
* Zend_Locale_Format (optional)
* Zend_Measure_Binary
* Zend_View_Exception

{zone-data}

{zone-data:operation}
...
{zone-data}

{zone-data:milestones}
* Milestone 1: Community and Zend review
{zone-data}

{zone-data:class-list}
* Zend_View_Helper_FileSize
{zone-data}

{zone-data:use-cases}
||UC-01||
{code}

echo $this->fileSize(1073741824);
//will print "1 GB"

echo $this->fileSize(1000000, 3);
//will print "976.563 kB"

echo $this->fileSize(1000000, 4);
//will print "976.5625 kB"
{code}

||UC-02 - set export units||
{code}
echo $this->fileSize(1024*1024*1024, null, null, 'MEGABYTE');
//will print "1024 MB"

echo $this->fileSize(1024*1024*1024, null, null, 'KILOBYTE');
//will print "1048576 kB"

echo $this->fileSize(1024*1024*1024, null, null, 'GIGABYTE');
//will print "1 GB"
{code}

||UC-03 - set the norm||
{code}
echo $this->fileSize(1024*1024);
//will print "1 MB"

echo $this->fileSize(1000*1000, null, 'si');
//will print "1 MB."

echo $this->fileSize(1024*1024, null, 'iec');
//will print "1 MiB"

{code}

{zone-data}

{zone-data:skeletons}
{code}
/**
* Formats filesize with specified precision
*
* @param integer $fileSize Filesize in bytes
* @param integer $precision Precision
* @param string $norm Which norm use - 'traditional' (1 KB = 2^10 B), 'si' (1 KB = 10^3 B), 'iec' (1 KiB = 2^10 B)
* @param string $type Defined export type
*/
public function fileSize($fileSize, $precision = 0, $norm = 'traditional', $type = null)
{
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>