Browse files

Added lazy loading fileset

  • Loading branch information...
1 parent 665ab78 commit 95bbae3a9ded8c9a07e9723e9eb4510afe4bbd80 @toxygene committed Nov 22, 2011
View
36 library/Pants/FileSet/Pattern.php
@@ -0,0 +1,36 @@
+<?php
+/**
+ *
+ */
+
+namespace Pants\Fileset;
+
+/**
+ *
+ */
+class Pattern
+{
+
+ /**
+ *
+ */
+ protected $_pattern;
+
+ /**
+ *
+ */
+ public function getPattern()
+ {
+ return $this->_pattern;
+ }
+
+ /**
+ *
+ */
+ public function setPattern($pattern)
+ {
+ $this->_pattern = $pattern;
+ return $this;
+ }
+
+}
View
60 library/Pants/LazyLoadedFileSet.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ *
+ */
+
+namespace Pants;
+
+use IteratorAggregate,
+ IteratorIterator,
+ Pants\Types;
+
+/**
+ *
+ */
+class LazyLoadedFileSet implements IteratorAggregate
+{
+
+ /**
+ * Constructor
+ *
+ * @param Types $types
+ * @param string $id
+ */
+ public function __construct(Types $types, $id)
+ {
+ $this->_types = $types;
+ $this->_id = $id;
+ }
+
+ /**
+ * Get the id
+ *
+ * @return string
+ */
+ public function getId()
+ {
+ return $this->_id;
+ }
+
+ /**
+ * Get the iterator
+ *
+ * @return IteratorIterator
+ */
+ public function getIterator()
+ {
+ return new IteratorIterator($this->getTypes()->{$this->getId()});
+ }
+
+ /**
+ * Get the types
+ *
+ * @return Types
+ */
+ public function getTypes()
+ {
+ return $this->_types;
+ }
+
+}
View
146 library/Pants/Task/FileSet.php
@@ -0,0 +1,146 @@
+<?php
+/**
+ * Pants
+ *
+ * Copyright (c) 2011, Justin Hendrickson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of its contributors may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @author Justin Hendrickson <justin.hendrickson@gmail.com>
+ */
+
+namespace Pants\Task;
+
+use Pants\BuildException,
+ Pants\FileSet as FileSetType,
+ Pants\FileSet\Pattern,
+ Pants\Task\AbstractTask,
+ StdClass;
+
+/**
+ * FileSet task
+ *
+ * @package Pants
+ * @subpackage Task
+ */
+class FileSet extends AbstractTask
+{
+
+ /**
+ * Base directory
+ * @var string
+ */
+ protected $_baseDirectory;
+
+ /**
+ * Id
+ * @var string
+ */
+ protected $_id;
+
+ /**
+ *
+ */
+ public function createInclude()
+ {
+ $include = new Pattern;
+ $this->_includes[] = $include;
+ return $include;
+ }
+
+ /**
+ * Execute a task
+ *
+ * @throws BuildException
+ */
+ public function execute()
+ {
+ if (!$this->getId()) {
+ throw new BuildException("No id set");
+ }
+
+ $fileSet = new FileSetType();
+
+ $fileSet->setBaseDirectory($this->getBaseDirectory());
+
+ $fileSet->setIncludes(array_map(
+ function($include) {
+ return $include->getPattern();
+ },
+ $this->_includes
+ ));
+
+ // TODO populate file set object
+
+ $this->getProject()
+ ->getTypes()
+ ->{$this->getId()} = $fileSet;
+ }
+
+ /**
+ * Get the base directory
+ *
+ * @return string
+ */
+ public function getBaseDirectory()
+ {
+ return $this->_baseDirectory;
+ }
+
+ /**
+ * Get the id
+ *
+ * @return string
+ */
+ public function getId()
+ {
+ return $this->_id;
+ }
+
+ /**
+ * Set the base directory
+ *
+ * @param string $baseDirectory
+ * @return FileSet
+ */
+ public function setBaseDirectory($baseDirectory)
+ {
+ $this->_baseDirectory = $baseDirectory;
+ return $this;
+ }
+
+ /**
+ * Set the id
+ *
+ * @param string $id
+ * @return FileSet
+ */
+ public function setId($id)
+ {
+ $this->_id = $id;
+ return $this;
+ }
+
+}
View
69 library/Pants/Task/FileSetable.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Pants
+ *
+ * Copyright (c) 2011, Justin Hendrickson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of its contributors may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @author Justin Hendrickson <justin.hendrickson@gmail.com>
+ */
+
+namespace Pants\Task;
+
+use Traversable;
+
+/**
+ * FileSet-able interface
+ *
+ * @package Pants
+ * @subpackage Task
+ */
+interface FileSetable
+{
+
+ /**
+ * Add a file set
+ *
+ * @param Traversable $fileSet
+ * @return FileSetable
+ */
+ public function addFileSet(Traversable $fileSet);
+
+ /**
+ * Create a file set
+ *
+ * @return FileSetable
+ */
+ public function createFileSet();
+
+ /**
+ * Get the file sets
+ *
+ * @return array
+ */
+ public function getFileSets();
+
+}
View
105 library/Pants/Types.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * Pants
+ *
+ * Copyright (c) 2011, Justin Hendrickson
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * The names of its contributors may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * @author Justin Hendrickson <justin.hendrickson@gmail.com>
+ */
+
+namespace Pants;
+
+use InvalidArgumentException;
+
+/**
+ * Types container
+ *
+ * @package Pants
+ */
+class Types
+{
+
+ /**
+ * Types
+ * @var array
+ */
+ protected $_types = array();
+
+ /**
+ * Get a type
+ *
+ * @param string $name
+ * @return mixed
+ * @throws InvalidArgumentException
+ */
+ public function __get($name)
+ {
+ if (!isset($this->$name)) {
+ throw new InvalidArgumentException("There is no type with the name of '{$name}'");
+ }
+
+ return $this->_types[$name];
+ }
+
+ /**
+ * Check if a type exists
+ *
+ * @param string $name
+ * @return boolean
+ */
+ public function __isset($name)
+ {
+ return isset($this->_types[$name]);
+ }
+
+ /**
+ * Set a type
+ *
+ * @param string $name
+ * @param mixed $type
+ */
+ public function __set($name, $type)
+ {
+ $this->_types[$name] = $type;
+ }
+
+ /**
+ * Unset a types
+ *
+ * @param string $name
+ * @throws InvalidArgumentException
+ */
+ public function __unset($name)
+ {
+ if (!isset($this->$name)) {
+ throw new InvalidArgumentException("There is no type with the name of '{$name}'");
+ }
+
+ unset($this->_types[$name]);
+ }
+
+}

0 comments on commit 95bbae3

Please sign in to comment.