You are here

CertWriter.php in Lockr 4.x

Same filename and directory in other branches
  1. 8.4 src/CertWriter.php
  2. 8.3 src/CertWriter.php

Namespace

Drupal\lockr

File

src/CertWriter.php
View source
<?php

namespace Drupal\lockr;


/**
 * Utility class for handling writing certificates to the file system.
 */
class CertWriter {

  /**
   * Writes certs for the given environment.
   */
  public static function writeCerts($env, $texts) {
    $base = "private://lockr/{$env}";
    @mkdir($base, 0750, TRUE);
    $key_file = "{$base}/key.pem";
    $key_fp = fopen($key_file, 'w');
    fwrite($key_fp, $texts['key_text']);
    fclose($key_fp);
    chmod($key_file, 0640);
    $cert_file = "{$base}/crt.pem";
    $cert_fp = fopen($cert_file, 'w');
    fwrite($cert_fp, $texts['cert_text']);
    fclose($cert_fp);
    chmod($cert_file, 0640);
    $pair_file = "{$base}/pair.pem";
    $pair_fp = fopen($pair_file, 'w');
    fwrite($pair_fp, $texts['key_text']);
    fwrite($pair_fp, $texts['cert_text']);
    fclose($pair_fp);
    chmod($pair_file, 0640);
  }

}

Classes

Namesort descending Description
CertWriter Utility class for handling writing certificates to the file system.