PHP Classes

File: src/symlinks.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   CMS Airship   src/symlinks.php   Download  
File: src/symlinks.php
Role: Example script
Content type: text/plain
Description: Example script
Class: CMS Airship
Content management system with security features
Author: By
Last change: Merge remote-tracking branch 'origin/master'
Date: 7 years ago
Size: 1,667 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

use
Airship\Engine\{
   
Gadgets,
   
State
};
use
ParagonIE\ConstantTime\Binary;

/**
 * @global array $active The active cabin configuration
 * @const string CABIN_DIR
 * @global State $state
 */

// Let's make sure we populate the symlinks
if (\is_dir(CABIN_DIR . '/public')) {
   
$link = ROOT . '/public/static/' . $active['name'];
    if (!\
is_link($link)) {
       
// Remove copies, we only allow symlinks in static
       
if (\is_dir($link)) {
            \
rmdir($link);
        } elseif (\
file_exists($link)) {
            \
unlink($link);
        }
       
       
// Create a symlink from public/static/* to Cabin/*/public
        /** @noinspection PhpUsageOfSilenceOperatorInspection */
       
@\symlink(
           
CABIN_DIR . '/public',
           
ROOT . '/public/static/' . $active['name']
        );
    }
}

// Let's load the default cargo modules
if (\is_dir(CABIN_DIR.'/View/cargo')) {
   
$cargoCacheFile = ROOT.'/tmp/cache/cargo-'.$active['name'].'.cache.json';
    if (\
file_exists($cargoCacheFile)) {
       
$data = Airship\loadJSON($cargoCacheFile);
       
$state->cargo = $data;
    } else {
       
$dir = \getcwd();
        \
chdir(CABIN_DIR . '/View');
        foreach (\
Airship\list_all_files('cargo', 'twig') as $cargo) {
           
$idx = \str_replace(
                [
'__', '/'],
                [
'', '__'],
               
Binary::safeSubstr($cargo, 6, -5)
            );
           
Gadgets::loadCargo($idx, $cargo);
        }
        \
chdir($dir);
       
       
// Store the cache file
       
\Airship\saveJSON(
           
$cargoCacheFile,
           
$state->cargo
       
);
    }
}