/**
  * The only thing I need this for so far is the parser, but it may come in handy for the facade as well
  * @param string $name The name of the component to be created
  * @param array $properties The properties that should be contained in the component
  * @return qCal_Component The generated qCal_Component
  * @access public
  * @static
  */
 public static function factory($name, $properties = array())
 {
     if (empty($name)) {
         return false;
     }
     // capitalize
     $component = ucfirst(strtolower($name));
     $className = "qCal_Component_" . $component;
     $fileName = str_replace("_", DIRECTORY_SEPARATOR, $className) . ".php";
     qCal_Loader::loadFile($fileName);
     $class = new $className($properties);
     return $class;
 }
Exemplo n.º 2
0
 /**
  * Factory method generates the correct recur type based on the string it is passed: "yearly, weekly, etc."
  * @param string The frequency type of recurrence rule you want to generate
  * @param mixed The start date/time for the recurrence. Accepts anything qCal_Date accepts
  */
 public static function factory($freq, $start)
 {
     $freq = ucfirst(strtolower($freq));
     $className = "qCal_DateTime_Recur_" . $freq;
     $fileName = str_replace("_", DIRECTORY_SEPARATOR, $className) . ".php";
     qCal_Loader::loadFile($fileName);
     $class = new $className($start);
     return $class;
 }
Exemplo n.º 3
0
 /**
  * Generates a qCal_Property class based on property name, params, and value
  * which can come directly from an icalendar file
  * @todo I need a way to detect INVALID properties as they are being parsed. This
  * way there can be an option to NOT stop on errors. To just log and then continue.
  */
 public static function factory($name, $value, $params = array())
 {
     $className = self::getClassNameFromPropertyName($name);
     $fileName = str_replace("_", DIRECTORY_SEPARATOR, $className) . ".php";
     try {
         qCal_Loader::loadFile($fileName);
         $class = new $className($value, $params);
     } catch (qCal_Exception_InvalidFile $e) {
         // if there is no class available for this property, check if it is non-standard
         $xname = strtoupper(substr($name, 0, 2));
         // non-standard property
         if ($xname == "X-") {
             $class = new qCal_Property_NonStandard($value, $params, $name);
         } else {
             // if it's not a non-standard property, rethrow
             throw $e;
         }
     }
     return $class;
 }