summaryrefslogtreecommitdiffstats
path: root/vendor/dragonmantank/cron-expression/src/Cron/FieldFactory.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/dragonmantank/cron-expression/src/Cron/FieldFactory.php')
-rw-r--r--vendor/dragonmantank/cron-expression/src/Cron/FieldFactory.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/dragonmantank/cron-expression/src/Cron/FieldFactory.php b/vendor/dragonmantank/cron-expression/src/Cron/FieldFactory.php
new file mode 100644
index 0000000..545e4b8
--- /dev/null
+++ b/vendor/dragonmantank/cron-expression/src/Cron/FieldFactory.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Cron;
+
+use InvalidArgumentException;
+
+/**
+ * CRON field factory implementing a flyweight factory
+ * @link http://en.wikipedia.org/wiki/Cron
+ */
+class FieldFactory
+{
+ /**
+ * @var array Cache of instantiated fields
+ */
+ private $fields = array();
+
+ /**
+ * Get an instance of a field object for a cron expression position
+ *
+ * @param int $position CRON expression position value to retrieve
+ *
+ * @return FieldInterface
+ * @throws InvalidArgumentException if a position is not valid
+ */
+ public function getField($position)
+ {
+ if (!isset($this->fields[$position])) {
+ switch ($position) {
+ case 0:
+ $this->fields[$position] = new MinutesField();
+ break;
+ case 1:
+ $this->fields[$position] = new HoursField();
+ break;
+ case 2:
+ $this->fields[$position] = new DayOfMonthField();
+ break;
+ case 3:
+ $this->fields[$position] = new MonthField();
+ break;
+ case 4:
+ $this->fields[$position] = new DayOfWeekField();
+ break;
+ default:
+ throw new InvalidArgumentException(
+ ($position + 1) . ' is not a valid position'
+ );
+ }
+ }
+
+ return $this->fields[$position];
+ }
+}