lithium\g11n\catalog\adapter\Memory

class

The Memory class is an adapter for reading and writing data during runtime.

Written data is stored in memory and lost after the end of the script execution. The adapter is also very useful for testing.

Source

class Memory extends \lithium\g11n\catalog\Adapter {

	/**
	 * Holds data during runtime.
	 *
	 * @var array
	 */
	protected $_data = [];

	/**
	 * Reads data.
	 *
	 * @param string $category A category.
	 * @param string $locale A locale identifier.
	 * @param string $scope The scope for the current operation.
	 * @return array
	 */
	public function read($category, $locale, $scope) {
		$scope = $scope ?: 'default';

		if (isset($this->_data[$scope][$category][$locale])) {
			return $this->_data[$scope][$category][$locale];
		}
	}

	/**
	 * Writes data.
	 *
	 * @param string $category A category.
	 * @param string $locale A locale identifier.
	 * @param string $scope The scope for the current operation.
	 * @param array $data The data to write.
	 * @return boolean
	 */
	public function write($category, $locale, $scope, array $data) {
		$scope = $scope ?: 'default';

		if (!isset($this->_data[$scope][$category][$locale])) {
			$this->_data[$scope][$category][$locale] = [];
		}
		foreach ($data as $item) {
			$this->_data[$scope][$category][$locale] = $this->_merge(
				$this->_data[$scope][$category][$locale],
				$this->_prepareForWrite($item)
			);
		}
		return true;
	}
}