f::write PHP Method

write() static public method

Creates a new file
static public write ( string $file, mixed $content, boolean $append = false ) : boolean
$file string The path for the new file
$content mixed Either a string or an array. Arrays will be converted to JSON.
$append boolean true: append the content to an exisiting file if available. false: overwrite.
return boolean
    static function write($file, $content, $append = false)
    {
        if (is_array($content)) {
            $content = a::json($content);
        }
        $mode = $append ? FILE_APPEND : false;
        $write = @file_put_contents($file, $content, $mode);
        @chmod($file, 0666);
        return $write;
    }

Usage Example

Example #1
0
 public static function combine($type, $files, $compress = false)
 {
     $root = panel::instance()->roots()->assets() . DS . $type;
     $cache = new Media($root . DS . 'panel.' . $type);
     $media = new Collection(array_map(function ($file) use($root) {
         return new Media($root . DS . str_replace('/', DS, $file));
     }, $files));
     // get the max modification date
     $modified = max($media->pluck('modified'));
     if (is_writable($root) and (!$cache->exists() or $cache->modified() < $modified)) {
         $cache->remove();
         $content = '';
         foreach ($media as $asset) {
             $content .= $asset->read() . PHP_EOL;
         }
         if ($compress) {
             $content = static::compress($content);
         }
         f::write($root . DS . 'panel.' . $type, $content);
     }
     if ($cache->exists()) {
         return $type(panel()->urls()->{$type}() . '/panel.' . $type . '?v=' . panel()->version());
     }
     return $type(array_map(function ($item) use($type) {
         return 'panel/assets/' . $type . '/' . $item;
     }, $files));
 }
All Usage Examples Of f::write