Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
TrackedStorage
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 5
42
0.00% covered (danger)
0.00%
0 / 1
 spawnDirectory
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getSpawnedDirectoryIds
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 import
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getDirectoryById
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getInternalStorage
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 */
21
22namespace oat\taoDeliveryRdf\model;
23
24use tao_models_classes_service_FileStorage;
25use oat\tao\model\service\ServiceFileStorage;
26use Zend\ServiceManager\ServiceLocatorAwareInterface;
27use Zend\ServiceManager\ServiceLocatorAwareTrait;
28
29/**
30 * A wrapper of the filestorage that tracks added directories
31 *
32 * @access public
33 * @author Joel Bout, <joel@taotesting.com>
34 * @package taoDelivery
35
36 */
37class TrackedStorage implements ServiceFileStorage, ServiceLocatorAwareInterface
38{
39    use ServiceLocatorAwareTrait;
40
41    private $ids = [];
42
43    private $storage;
44
45    /**
46     * @param boolean $public
47     * @return \tao_models_classes_service_StorageDirectory
48     */
49    public function spawnDirectory($public = false)
50    {
51        $directory = $this->getInternalStorage()->spawnDirectory($public);
52        $this->ids[] = $directory->getId();
53        return $directory;
54    }
55
56    /**
57     * Returns the id used for this storage
58     * @return array
59     */
60    public function getSpawnedDirectoryIds()
61    {
62        return $this->ids;
63    }
64
65    /**
66     * {@inheritDoc}
67     * @see tao_models_classes_service_FileStorage::import()
68     */
69    public function import($id, $directoryPath)
70    {
71        $this->ids[] = $id;
72        return $this->getInternalStorage()->import($id, $directoryPath);
73    }
74
75    /**
76     * {@inheritDoc}
77     * @see tao_models_classes_service_FileStorage::getDirectoryById()
78     */
79    public function getDirectoryById($id)
80    {
81        return $this->getInternalStorage()->getDirectoryById($id);
82    }
83
84    /**
85     * @return ServiceFileStorage
86     */
87    protected function getInternalStorage()
88    {
89        if (is_null($this->storage)) {
90            $this->storage = $this->getServiceLocator()->get(ServiceFileStorage::SERVICE_ID);
91        }
92        return $this->storage;
93    }
94}