<?php

/**
 * Core
 *
 * @author Arkadiusz Rychlik <a.rychlik at eppe.com.pl>
 */
abstract class Rtn_Storage_Core {

	/**
	 * @param mixed $object
	 * @return Rtn_Storage
	 */
	final static function factory(&$object){
		return new static($object);
	}
	
	/**
	 * @var Redbe
	 */
	private $object;
	private $name;

	public function __construct(&$object) {
		$this->object = $object;
		$this->_setupName();
	}

	public function getPath() {
		return $this->setupDirectory(STORAGE_PATH . $this->name . DIRECTORY_SEPARATOR . $this->getObjectUniq() . DIRECTORY_SEPARATOR);
	}
	
	public function removeRootPart($path) {
		return str_replace(ROOT_PATH, '', $path);		
	}
	
	protected function setupDirectory($path) {
		if( !file_exists($path) ) {
			mkdir($path, 0775, true);
		}
		return $path;
	}

	public function getObjectUniq(){
		return $this->object->id;
	}
	
	protected function _setupName(){
		$this->name = str_replace('_Storage', '', get_class($this));
	}
	
}
