示例#1
0
 public function __call($method, $args)
 {
     if (!isset($this->data)) {
         throw new \Exception("data array not found on child class");
     }
     //Boolean is"Whatever" Call
     if (strtolower(substr($method, 0, 2)) == "is") {
         $attr = strtolower(substr($method, 2));
         foreach ($this->lazyData as $name => $value) {
             $name = strtolower($name);
             if (($name == "is{$attr}" || $name == "is_{$attr}") && $this->data[$name]["type"] == "boolean") {
                 return $value;
             }
         }
     }
     $method = strtolower($method);
     $isCallingSetterOrGetter = substr($method, 0, 3);
     if ($isCallingSetterOrGetter == "get" || $isCallingSetterOrGetter == "set") {
         $method = preg_replace("/\\W/", '', $method);
         $arg = strtolower($method);
         $arg = substr($arg, 3);
         if (!isset($this->data[$arg])) {
             throw new \Exception("No such attribute {$arg}");
         }
         if ($isCallingSetterOrGetter == "set") {
             return $this->lazyData[$arg] = \apf\Validator::metaValidate($args[0], $this->data[$arg]);
         }
         if ($this->data[$arg]["type"] == "date") {
             if (isset($args[0]) && $args[0] == "object") {
                 return $this->lazyData[$arg];
             }
             if (isset($this->data[$arg]["getfmt"])) {
                 return $this->lazyData[$arg]->format($this->data[$arg]["getfmt"]);
             }
         }
         if (isset($args[0])) {
             return \apf\Validator::metaValidate($this->lazyData[$arg], $this->data[$arg]);
         }
         return $this->lazyData[$arg];
     }
 }
示例#2
0
 public function fetch()
 {
     if (is_null($this->getUri())) {
         throw new \Exception("Can't get RSS content, no URI specified");
     }
     $file = tempnam(sys_get_temp_dir(), __CLASS__);
     $adapter = $this->getAdapter();
     //If adapter is of type eCurl
     if (is_a($this->getAdapter(), "\\apf\\http\\adapter\\Ecurl")) {
         $adapter->setCurlOption("FILE", $file);
         $adapter->setCurlOption("RETURNTRANSFER", FALSE);
         $adapter->connect();
         $file = new \apf\core\File($file);
         $content = $file->read();
     } else {
         $content = $adapter->connect();
         file_put_contents($content, $file);
     }
     $msg = "The given URI " . $this->getUri() . " has return no content!";
     \apf\Validator::emptyString($content, $msg);
     return new \apf\parser\feed\Rss($file);
 }
示例#3
0
 public function setXml(&$xml = NULL)
 {
     $msg = "Given XML has to be a path to a file, an XML string or a valid URL empty string given";
     \apf\Validator::emptyString($xml, $msg);
     $this->xml["set_calls"]++;
     $scheme = parse_url($xml, PHP_URL_SCHEME);
     $validSchemes = array("http", "ftp", "file", "https");
     if (is_file($xml) || $scheme == "file") {
         $this->xml["is_file"] = TRUE;
         $this->xml["data"] = new \apf\core\File($xml);
         return;
     }
     if (in_array($scheme, $validSchemes)) {
         //The private method "fetch" saves to a temporary file in the filesystem,
         //this is in case the programmer has given a URI as input instead of a file.
         $this->xml["data"] = $this->fetch($uri = $xml);
         $this->xml["is_file"] = TRUE;
         return;
     }
     //Else ... $xml is a string
     $this->xml["is_file"] = FALSE;
     $this->xml["data"] = $xml;
 }
示例#4
0
 public function setName($name = NULL)
 {
     if (is_object($name) && $name->TABLE_NAME) {
         $name = $name->TABLE_NAME;
     }
     \apf\Validator::emptyString($name, "Table name can't be empty");
     $pos = strpos($name, '.');
     if ($pos === FALSE) {
         $adapter = Adapter::getInstance($this->params);
         $this->schema = $adapter->getDatabaseName();
         $this->name = $name;
         return;
     }
     $this->schema = substr($name, 0, $pos);
     $this->name = substr($name, $pos + 1);
 }
示例#5
0
 public function setReadFunction($fName = NULL)
 {
     $fName = \apf\Validator::emptyString($fName);
     if (!function_exists($fName)) {
         throw new \Exception("Function provided (\"{$fName}\") for reading file {$this} does not exists!");
     }
     $this->_readFn = $fName;
 }
示例#6
0
 public function setUri(\apf\parser\Uri $uri = NULL)
 {
     \apf\Validator::emptyString($uri);
     $this->uri = $uri;
 }
示例#7
0
 public function addRequestHeader($name = NULL, $value = NULL)
 {
     \apf\Validator::emptyString($name, "Header name must be set in order to add a header");
     $this->_requestHeaders[] = "{$name}: {$value}";
 }
示例#8
0
 public function setMessages(array $messages = array())
 {
     if (!sizeof($messages)) {
         return;
     }
     $requiredKeys = array("msg", "status");
     foreach ($messages as &$message) {
         \apf\Validator::arrayKeys($requiredKeys, $message);
         $this->addMessage($message["msg"], $message["status"]);
     }
 }