Skip to content

Commit 2f0014b

Browse files
committed
Merge pull request #11 from PHPOffice/develop
Update master branch from develop
2 parents 19a6e7d + 197c30d commit 2f0014b

23 files changed

+3220
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
unitTests/codeCoverage
2+
3+
/.project
4+
/.buildpath

.travis.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
language: php
2+
php:
3+
- 5.3.3
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
8+
before_script:
9+
## Composer
10+
- curl -s http://getcomposer.org/installer | php
11+
- php composer.phar install
12+
## PHP_CodeSniffer
13+
- pyrus install pear/PHP_CodeSniffer
14+
- phpenv rehash
15+
## PHP Copy/Paste Detector
16+
- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
17+
## PHP Mess Detector
18+
- pear config-set preferred_state beta
19+
- printf "\n" | pecl install imagick
20+
- pear channel-discover pear.phpmd.org
21+
- pear channel-discover pear.pdepend.org
22+
- pear install --alldeps phpmd/PHP_PMD
23+
- phpenv rehash
24+
## PHPLOC
25+
- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
26+
27+
script:
28+
## PHP_CodeSniffer
29+
- phpcs --standard=PSR1 Classes/
30+
- phpcs --standard=PSR2 Classes/
31+
## PHP Copy/Paste Detector
32+
- php phpcpd.phar --verbose Classes/
33+
## PHP Mess Detector
34+
- phpmd Classes/ text codesize,unusedcode,naming,design
35+
## PHPLOC
36+
- php phploc.phar Classes/
37+
38+
notifications:
39+
email:
40+

Classes/PHPProject.php

Lines changed: 337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
1+
<?php
2+
/**
3+
* PHPProject
4+
*
5+
* Copyright (c) 2012 - 2012 PHPProject
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2.1 of the License, or (at your option) any later version.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* @category PHPProject
22+
* @package PHPProject
23+
* @copyright Copyright (c) 2012 - 2012 PHPProject (https://github.com/PHPOffice/PHPProject)
24+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25+
* @version ##VERSION##, ##DATE##
26+
*/
27+
28+
/** PHPProject root directory */
29+
if (!defined('PHPPROJECT_ROOT')) {
30+
define('PHPPROJECT_ROOT', dirname(__FILE__) . '/');
31+
require(PHPPROJECT_ROOT . 'PHPProject/Autoloader.php');
32+
}
33+
34+
/**
35+
* PHPProject
36+
*
37+
* @category PHPProject
38+
* @package PHPProject
39+
* @copyright Copyright (c) 2006 - 2012 PHPProject (https://github.com/PHPOffice/PHPProject)
40+
*/
41+
class PHPProject
42+
{
43+
/**
44+
* Document properties
45+
*
46+
* @var PHPProject_DocumentProperties
47+
*/
48+
private $_properties;
49+
50+
/**
51+
* Document informations
52+
*
53+
* @var PHPProject_DocumentInformations
54+
*/
55+
private $_informations;
56+
57+
/**
58+
* Collection of task objects
59+
*
60+
* @var PHPProject_Task[]
61+
*/
62+
private $_taskCollection = array();
63+
64+
/**
65+
* Collection of resource objects
66+
*
67+
* @var PHPProject_Resource[]
68+
*/
69+
private $_resourceCollection = array();
70+
71+
/**
72+
* Active task
73+
*
74+
* @var int
75+
*/
76+
private $_activeTaskIndex = 0;
77+
78+
/**
79+
* Active resource
80+
*
81+
* @var int
82+
*/
83+
private $_activeResourceIndex = 0;
84+
85+
/**
86+
* Create a new PHPProject
87+
*/
88+
public function __construct() {
89+
// Create document properties
90+
$this->_properties = new PHPProject_DocumentProperties();
91+
// Create document informations
92+
$this->_informations = new PHPProject_DocumentInformations();
93+
}
94+
95+
//===============================================
96+
// Document Properties
97+
//===============================================
98+
/**
99+
* Get properties
100+
*
101+
* @return PHPProject_DocumentProperties
102+
*/
103+
public function getProperties()
104+
{
105+
return $this->_properties;
106+
}
107+
108+
/**
109+
* Set properties
110+
*
111+
* @param PHPProject_DocumentProperties $pValue
112+
*/
113+
public function setProperties(PHPProject_DocumentProperties $pValue)
114+
{
115+
$this->_properties = $pValue;
116+
}
117+
118+
//===============================================
119+
// Document Informations
120+
//===============================================
121+
/**
122+
* Get informations
123+
*
124+
* @return PHPProject_DocumentInformations
125+
*/
126+
public function getInformations()
127+
{
128+
return $this->_informations;
129+
}
130+
131+
/**
132+
* Set informations
133+
*
134+
* @param PHPProject_DocumentProperties $pValue
135+
*/
136+
public function setInformations(PHPProject_DocumentInformations $pValue)
137+
{
138+
$this->_informations = $pValue;
139+
}
140+
141+
//===============================================
142+
// Resources
143+
//===============================================
144+
/**
145+
* Create a resource
146+
*
147+
* @return PHPProject_Resource
148+
* @throws Exception
149+
*/
150+
public function createResource() {
151+
$newRessource = new PHPProject_Resource($this, $this->getResourceCount());
152+
$this->_resourceCollection[] = $newRessource;
153+
$this->_activeResourceIndex = $this->getResourceCount() - 1;
154+
return $newRessource;
155+
}
156+
157+
/**
158+
* Get resource count
159+
*
160+
* @return int
161+
*/
162+
public function getResourceCount()
163+
{
164+
return count($this->_resourceCollection);
165+
}
166+
167+
/**
168+
* Get all resources
169+
*
170+
* @return PHPProject_Resource[]
171+
*/
172+
public function getAllResources(){
173+
return $this->_resourceCollection;
174+
}
175+
176+
/**
177+
* Get active resource
178+
*
179+
* @return PHPProject_Resource
180+
*/
181+
public function getActiveResource()
182+
{
183+
return $this->_resourceCollection[$this->_activeResourceIndex];
184+
}
185+
186+
/**
187+
* Get resource by index
188+
*
189+
* @param int $pIndex Resource index
190+
* @return PHPProject_Resource
191+
* @throws Exception
192+
*/
193+
public function getResource($pIndex = 0)
194+
{
195+
if ($pIndex > count($this->_resourceCollection) - 1) {
196+
throw new Exception('Resource index is out of bounds.');
197+
} else {
198+
return $this->_resourceCollection[$pIndex];
199+
}
200+
}
201+
202+
/**
203+
* Get active resource index
204+
*
205+
* @return int Active resource index
206+
*/
207+
private function getActiveResourceIndex()
208+
{
209+
return $this->$_activeResourceIndex;
210+
}
211+
212+
/**
213+
* Set active resource index
214+
*
215+
* @param int $pIndex Active resource index
216+
* @throws Exception
217+
* @return PHPProject_Resource
218+
*/
219+
private function setActiveResourceIndex($pIndex = 0)
220+
{
221+
if ($pIndex > count($this->_resourceCollection) - 1) {
222+
throw new Exception('Active resource index is out of bounds.');
223+
} else {
224+
$this->_activeResourceIndex = $pIndex;
225+
}
226+
return $this->getActiveResource();
227+
}
228+
229+
//===============================================
230+
// Tasks
231+
//===============================================
232+
/**
233+
* Create a task
234+
*
235+
* @return PHPProject_Task
236+
* @throws Exception
237+
*/
238+
public function createTask() {
239+
$newTask = new PHPProject_Task($this, $this->getTaskCount());
240+
$this->_taskCollection[] = $newTask;
241+
$this->_activeTaskIndex = $this->getTaskCount() - 1;
242+
return $newTask;
243+
}
244+
245+
/**
246+
* Get task count
247+
*
248+
* @return int
249+
*/
250+
public function getTaskCount()
251+
{
252+
return count($this->_taskCollection);
253+
}
254+
255+
/**
256+
* Get all tasks
257+
*
258+
* @return PHPProject_Task[]
259+
*/
260+
public function getAllTasks()
261+
{
262+
return $this->_taskCollection;
263+
}
264+
265+
/**
266+
* Get active task
267+
*
268+
* @return PHPProject_Task
269+
*/
270+
public function getActiveTask()
271+
{
272+
return $this->_taskCollection[$this->_activeTaskIndex];
273+
}
274+
275+
/**
276+
* Get task by index
277+
*
278+
* @param int $pIndex Task index
279+
* @return PHPProject_Task
280+
* @throws Exception
281+
*/
282+
public function getTask($pIndex = 0)
283+
{
284+
if ($pIndex > count($this->_taskCollection) - 1) {
285+
throw new Exception('Task index is out of bounds.');
286+
} else {
287+
return $this->_taskCollection[$pIndex];
288+
}
289+
}
290+
291+
/**
292+
* Remove task by index
293+
*
294+
* @param int $pIndex Active task index
295+
* @throws Exception
296+
*/
297+
public function removeTaskByIndex($pIndex = 0)
298+
{
299+
if ($pIndex > count($this->_taskCollection) - 1) {
300+
throw new Exception('Task index is out of bounds.');
301+
} else {
302+
array_splice($this->_taskCollection, $pIndex, 1);
303+
}
304+
// Adjust active sheet index if necessary
305+
if (($this->_activeTaskIndex >= $pIndex) &&
306+
($pIndex > count($this->_taskCollection) - 1)) {
307+
--$this->_activeTaskIndex;
308+
}
309+
}
310+
311+
/**
312+
* Get active task index
313+
*
314+
* @return int Active task index
315+
*/
316+
public function getActiveTaskIndex()
317+
{
318+
return $this->_activeTaskIndex;
319+
}
320+
321+
/**
322+
* Set active task index
323+
*
324+
* @param int $pIndex Active task index
325+
* @throws Exception
326+
* @return PHPProject_Task
327+
*/
328+
public function setActiveTaskIndex($pIndex = 0)
329+
{
330+
if ($pIndex > count($this->_taskCollection) - 1) {
331+
throw new Exception('Active task index is out of bounds.');
332+
} else {
333+
$this->_activeTaskIndex = $pIndex;
334+
}
335+
return $this->getActiveTask();
336+
}
337+
}

0 commit comments

Comments
 (0)