Pop\File\File::write PHP Метод

write() публичный Метод

Write data to a file.
public write ( string $data, boolean $append = false ) : File
$data string
$append boolean
Результат File
    public function write($data, $append = false)
    {
        // If the file is to be appended.
        if ($append) {
            if (null === $this->output && file_exists($this->fullpath)) {
                $this->output = file_get_contents($this->fullpath);
            }
            $this->output .= $data;
            //Else, overwrite the file contents.
        } else {
            $this->output = $data;
        }
        return $this;
    }

Usage Example

Пример #1
0
         if (!file_exists($argv[2])) {
             echo Install::cliError(2);
             // Else, check if the output file ends in '.php'
         } else {
             if (strtolower(substr($argv[3], -4)) != '.php') {
                 echo Install::cliError(3);
                 // Else, generate the class map file
             } else {
                 echo 'Generating class map file \'' . $argv[3] . '\' from source folder \'' . $argv[2] . '\'' . PHP_EOL;
                 Classmap::generate($argv[2], $argv[3]);
                 // Add project to the bootstrap file
                 $input = Install::cliInput('Add classmap to the bootstrap file? (Y/N) ');
                 if ($input == 'y') {
                     $location = Install::getBootstrap();
                     $bootstrap = new File($location . '/bootstrap.php');
                     $bootstrap->write("\$autoloader->loadClassMap('" . addslashes(realpath($argv[3])) . "');" . PHP_EOL . PHP_EOL, true)->save();
                 }
                 echo 'Done.' . PHP_EOL . PHP_EOL;
             }
         }
     }
     // Else, install project
 } else {
     if ($argv[1] == '-i' || $argv[1] == '--install') {
         // Check if the project install file argument was passed
         if (empty($argv[2])) {
             echo Install::cliError(4);
             // Else, run the install process
         } else {
             echo 'Installing Project' . PHP_EOL;
             echo '------------------' . PHP_EOL;
All Usage Examples Of Pop\File\File::write