atelierspierrot/library

View on GitHub
phpdoc/Library/Helper/File.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="robots" content="index, follow, all" />
    <title>Library\Helper\File | Library</title>

            <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="../../css/bootstrap-theme.min.css">
        <link rel="stylesheet" type="text/css" href="../../css/sami.css">
        <script src="../../js/jquery-1.11.1.min.js"></script>
        <script src="../../js/bootstrap.min.js"></script>
        <script src="../../js/typeahead.min.js"></script>
        <script src="../../sami.js"></script>
        <meta name="MobileOptimized" content="width">
        <meta name="HandheldFriendly" content="true">
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    
    
    </head>

    <body id="class" data-name="class:Library_Helper_File" data-root-path="../../">
            <div id="content">
        <div id="left-column">
                <div id="control-panel">
                <form id="search-form" action="../../search.html" method="GET">
            <span class="glyphicon glyphicon-search"></span>
            <input name="search"
                   class="typeahead form-control"
                   type="search"
                   placeholder="Search">
        </form>
    </div>

                <div id="api-tree"></div>

        </div>
        <div id="right-column">
                <nav id="site-nav" class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-elements">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="../../index.html">Library</a>
            </div>
            <div class="collapse navbar-collapse" id="navbar-elements">
                <ul class="nav navbar-nav">
                    <li><a href="../../classes.html">Classes</a></li>
                                            <li><a href="../../namespaces.html">Namespaces</a></li>
                                        <li><a href="../../interfaces.html">Interfaces</a></li>
                    <li><a href="../../traits.html">Traits</a></li>
                    <li><a href="../../doc-index.html">Index</a></li>
                    <li><a href="../../search.html">Search</a></li>
                </ul>
            </div>
        </div>
    </nav>

                        <div class="namespace-breadcrumbs">
            <ol class="breadcrumb">
                <li><span class="label label-default">class</span></li>
                                                            <li><a href="../../Library.html">Library</a></li>
                                        <li><a href="../../Library/Helper.html">Helper</a></li>
    
                <li>File</li>
            </ol>
        </div>
                <div id="page-content">
                
    <div class="page-header">
        <h1>File</h1>
    </div>

    <p>    class
    <strong>File</strong>
</p>

            <div class="description">
            <p>File helper</p>            <p>As for all helpers, all methods are statics.</p>

<p>For convenience, the best practice is to use:</p>

<pre><code>use Library\Helper\File as FileHelper;
</code></pre>
</p>        </div>
    
    
    
            <h2>Properties</h2>

            <table class="table table-condensed">
                    <tr>
                <td class="type" id="property_REPLACEMENT_FILENAMES_CHARS">
                    static                                                            
    
                </td>
                <td>$REPLACEMENT_FILENAMES_CHARS</td>
                <td class="last">List of characters replaced by a space in a file name to build a human readable string</td>
                <td></td>
            </tr>
                    <tr>
                <td class="type" id="property_FILESIZE_ORDERED_UNITS">
                    static                                                            
    
                </td>
                <td>$FILESIZE_ORDERED_UNITS</td>
                <td class="last">List of units to build the size field, ordered by 1024 operator on original size</td>
                <td></td>
            </tr>
            </table>

    
            <h2>Methods</h2>

            <div class="container-fluid underlined">
                    <div class="row">
                <div class="col-md-2 type">
                    static&nbsp;
    string
                </div>
                <div class="col-md-8 type">
                    <a href="#method_getUniqFilename">getUniqFilename</a>(
    string $filename = &#039;&#039;, 
    string $dir = null, 
    boolean $force_file = true, 
    string $extension = &#039;txt&#039;)
                                            <p>Returns a filename or directory that does not exist in the destination</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    static&nbsp;
    string
                </div>
                <div class="col-md-8 type">
                    <a href="#method_formatFilename">formatFilename</a>(
    string $filename = &#039;&#039;, 
    boolean $lowercase = false, 
    string $delimiter = &#039;-&#039;)
                                            <p>Formatting file names</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    static&nbsp;
    null|string
                </div>
                <div class="col-md-8 type">
                    <a href="#method_getExtension">getExtension</a>(
    string $filename = &#039;&#039;, 
    bool $dot = false)
                                            <p>Returns the extension of a file name</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    static&nbsp;
    string
                </div>
                <div class="col-md-8 type">
                    <a href="#method_getHumanReadableFilename">getHumanReadableFilename</a>(
    string $filename = &#039;&#039;)
                                            <p>Render a human readable string from a file name</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    static&nbsp;
    int
                </div>
                <div class="col-md-8 type">
                    <a href="#method_getTransformedFilesize">getTransformedFilesize</a>(
    float|int $size, 
    int $round = 3, 
    string $dec_delimiter = &#039;,&#039;)
                                            <p>Returns a formatted file size in bytes or derived unit</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    static&nbsp;
    bool
                </div>
                <div class="col-md-8 type">
                    <a href="#method_touch">touch</a>(
    string $file_path = null, 
    array $logs = array())
                                            <p>Create an empty file or touch an existing file</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    static&nbsp;
    bool
                </div>
                <div class="col-md-8 type">
                    <a href="#method_remove">remove</a>(
    string $file_path = null, 
    array $logs = array())
                                            <p>Remove a file if it exists</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    static&nbsp;
    bool
                </div>
                <div class="col-md-8 type">
                    <a href="#method_copy">copy</a>(
    string $file_path = null, 
    string $target_path = null, 
    bool $force = false, 
    array $logs = array())
                                            <p>Copy file <code>$file_path</code> if it exists to <code>$target_path</code></p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    static&nbsp;
    bool
                </div>
                <div class="col-md-8 type">
                    <a href="#method_write">write</a>(
    string $file_path = null, 
    string $content, 
    string $type = &#039;a&#039;, 
    bool $force = false, 
    array $logs = array())
                                            <p>Write a content in a file</p>                </div>
                <div class="col-md-2"></div>
            </div>
            </div>


        <h2>Details</h2>

            <div id="method-details">
                    <div class="method-item">
                    <h3 id="method_getUniqFilename">
        <div class="location">at line 51</div>
        <code>        static            
    string
    <strong>getUniqFilename</strong>(
    string $filename = &#039;&#039;, 
    string $dir = null, 
    boolean $force_file = true, 
    string $extension = &#039;txt&#039;)</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Returns a filename or directory that does not exist in the destination</p>                                </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$filename</td>
                <td>The name of the file or folder you want to create</td>
            </tr>
                    <tr>
                <td>
    string</td>
                <td>$dir</td>
                <td>The destination directory</td>
            </tr>
                    <tr>
                <td>
    boolean</td>
                <td>$force_file</td>
                <td>Should we force the creation of a file, adding an extension? (TRUE by default)</td>
            </tr>
                    <tr>
                <td>
    string</td>
                <td>$extension</td>
                <td>The extension to add in the case of a file</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    string</td>
            <td>The filename or directory, with a possible addition to be sure that it does not exist in the destination directory</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_formatFilename">
        <div class="location">at line 84</div>
        <code>        static            
    string
    <strong>formatFilename</strong>(
    string $filename = &#039;&#039;, 
    boolean $lowercase = false, 
    string $delimiter = &#039;-&#039;)</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Formatting file names</p>                                </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$filename</td>
                <td>The filename to format</td>
            </tr>
                    <tr>
                <td>
    boolean</td>
                <td>$lowercase</td>
                <td>Should we return the name un lowercase (FALSE by default)</td>
            </tr>
                    <tr>
                <td>
    string</td>
                <td>$delimiter</td>
                <td>The delimiter used for special chars substitution</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    string</td>
            <td>A filename valid on (almost) all systems</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_getExtension">
        <div class="location">at line 123</div>
        <code>        static            
    null|string
    <strong>getExtension</strong>(
    string $filename = &#039;&#039;, 
    bool $dot = false)</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Returns the extension of a file name</p>                    <p>It basically returns everything after last dot. No validation is done.</p>            </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$filename</td>
                <td>The file_name to work on</td>
            </tr>
                    <tr>
                <td>
    bool</td>
                <td>$dot</td>
                <td>
</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    null|string</td>
            <td>The extension if found, <code>null</code> otherwise</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_getHumanReadableFilename">
        <div class="location">at line 146</div>
        <code>        static            
    string
    <strong>getHumanReadableFilename</strong>(
    string $filename = &#039;&#039;)</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Render a human readable string from a file name</p>                    <p>The original file name is rebuilt striping the extension
and a set of commonly used separator characters in file or directories names.</p>            </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$filename</td>
                <td>The file_name to work on</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    string</td>
            <td>The resulting human readable file name</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_getTransformedFilesize">
        <div class="location">at line 174</div>
        <code>        static            
    int
    <strong>getTransformedFilesize</strong>(
    float|int $size, 
    int $round = 3, 
    string $dec_delimiter = &#039;,&#039;)</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Returns a formatted file size in bytes or derived unit</p>                    <p>This will return the size received transforming it to be readable, with the appropriate
unit chosen in <code>self::$FILESIZE_ORDERED_UNITS</code>.</p>            </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    float|int</td>
                <td>$size</td>
                <td>Refer to the size (in standard format given by the <code>stat()</code> function)</td>
            </tr>
                    <tr>
                <td>
    int</td>
                <td>$round</td>
                <td>The number of decimal places (default is 3)</td>
            </tr>
                    <tr>
                <td>
    string</td>
                <td>$dec_delimiter</td>
                <td>The decimal separator (default is a comma)</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    int</td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_touch">
        <div class="location">at line 204</div>
        <code>        static            
    bool
    <strong>touch</strong>(
    string $file_path = null, 
    array $logs = array())</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Create an empty file or touch an existing file</p>                                </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$file_path</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    array</td>
                <td>$logs</td>
                <td>Logs registry passed by reference</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    bool</td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_remove">
        <div class="location">at line 231</div>
        <code>        static            
    bool
    <strong>remove</strong>(
    string $file_path = null, 
    array $logs = array())</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Remove a file if it exists</p>                                </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$file_path</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    array</td>
                <td>$logs</td>
                <td>Logs registry passed by reference</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    bool</td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_copy">
        <div class="location">at line 258</div>
        <code>        static            
    bool
    <strong>copy</strong>(
    string $file_path = null, 
    string $target_path = null, 
    bool $force = false, 
    array $logs = array())</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Copy file <code>$file_path</code> if it exists to <code>$target_path</code></p>                                </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$file_path</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    string</td>
                <td>$target_path</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    bool</td>
                <td>$force</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    array</td>
                <td>$logs</td>
                <td>Logs registry passed by reference</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    bool</td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_write">
        <div class="location">at line 295</div>
        <code>        static            
    bool
    <strong>write</strong>(
    string $file_path = null, 
    string $content, 
    string $type = &#039;a&#039;, 
    bool $force = false, 
    array $logs = array())</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Write a content in a file</p>                                </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$file_path</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    string</td>
                <td>$content</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    string</td>
                <td>$type</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    bool</td>
                <td>$force</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    array</td>
                <td>$logs</td>
                <td>
</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    bool</td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
            </div>

    
            </div>
                <div id="footer">
        Generated by <a href="http://sami.sensiolabs.org/">Sami, the API Documentation Generator</a>.
    </div>

        </div>
    </div>
    </body>

</html>