<?php
namespace ALPCAL\Storage;
/**
 * Handles creation of storage variables and making sure that the folders exists if first load.
 */

Class Folders
{
   protected $cacheDirsRoot = null;
   public $cacheDirs = array(
      'Months'=>null, // stores months for alpinecalendar fetches
      'Events'=>null, // stores events retrieved when clicking on an event in calendar
      'Etc'=>null,  // stores additional information such as categories
      'deleteMe'=>null,  // stores additional information such as categories
    );

	function __construct( $rootFolder )
	{
		// Set the cache directory values
		if (!$rootFolder) { throw new \Exception("Called Storage/Folders without setting root."); }
		$this->cacheDirsRoot = $rootFolder;
		foreach ( $this->cacheDirs as $k=>$v )
			{
			$this->cacheDirs[$k] = $this->cacheDirsRoot.$k.'/';
			}
		$this->verifyCacheDirs();
	}


	/**
	* Make sure that the folders exist, create if they do not.
	*/
	function verifyCacheDirs()
	{
		if (!file_exists($this->cacheDirsRoot))  {	mkdir($this->cacheDirsRoot, 0777, true);	}
		foreach ( $this->cacheDirs as $k=>$v )
			{
			if (!file_exists($v)) {	mkdir($v, 0777, true);	}
			}
	}

}
