Пример #1
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);
 }
Пример #2
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;
 }
Пример #3
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);
 }
Пример #4
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;
 }
Пример #5
0
 public function setUri(\apf\parser\Uri $uri = NULL)
 {
     \apf\Validator::emptyString($uri);
     $this->uri = $uri;
 }
Пример #6
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}";
 }