public function FileStorage::save

public FileStorage::save($name, $code)

Saves PHP code to storage.

Parameters

string $name: The virtual file name. Can be a relative path.

string $code: The PHP code to be saved.

Return value

bool TRUE if the save succeeded, FALSE if it failed.

Overrides PhpStorageInterface::save

File

core/lib/Drupal/Component/PhpStorage/FileStorage.php, line 49

Class

FileStorage
Stores the code as regular PHP files.

Namespace

Drupal\Component\PhpStorage

Code

public function save($name, $code) {
  $path = $this->getFullPath($name);
  $directory = dirname($path);
  if ($this->ensureDirectory($directory)) {
    $htaccess_path = $directory . '/.htaccess';
    if (!file_exists($htaccess_path) && file_put_contents($htaccess_path, static::htaccessLines())) {
      @chmod($htaccess_path, 0444);
    }
  }
  return (bool) file_put_contents($path, $code);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!PhpStorage!FileStorage.php/function/FileStorage::save/8.1.x