예제 #1
1
 public function __construct(Torrent $torrent, $dir)
 {
     parent::__construct();
     $dir = realpath($dir);
     $dir = rtrim($dir, '/');
     if (!is_dir($dir)) {
         throw new Exception("Cannot find download directory '{$dir}'");
     }
     $this->torrent = $torrent;
     $this->dir = $dir;
     $this->myPeerID = sha1(time() . rand(), true);
     $this->pieceCache = new PieceCache($torrent, $dir);
     $this->lastFlush = time();
     $this->peers = array();
     $this->streams = array();
     $this->streamLookup = array();
     $this->trackers = array();
     $this->udp = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
     if (empty($this->udp)) {
         throw new Exception("Cannot create UDP socket");
     }
     foreach ($torrent->getTrackers() as $url) {
         $this->addTracker($url);
     }
 }
예제 #2
0
파일: View.php 프로젝트: pagon/core
 /**
  * Construct a view
  *
  * @param string $path
  * @param array  $data
  * @param array  $injectors
  * @throws \Exception
  * @return View
  */
 public function __construct($path, $data = array(), $injectors = array())
 {
     // Set dir for the view
     $injectors = array('data' => (array) $data, 'path' => $path) + $injectors + $this->injectors;
     // Set path
     $injectors['path'] = ltrim($path, '/');
     // If file exists?
     if (!is_file($injectors['dir'] . '/' . $injectors['path'])) {
         // Try to load file from absolute path
         if ($path[0] == '/' && is_file($path)) {
             $injectors['path'] = $path;
             $injectors['dir'] = '';
         } else {
             if ($injectors['app'] && ($_path = $injectors['app']->path($injectors['path']))) {
                 $injectors['path'] = $_path;
                 $injectors['dir'] = '';
             } else {
                 throw new \Exception('Template file is not exist: ' . $injectors['path']);
             }
         }
     }
     // Set data
     parent::__construct($injectors);
 }
예제 #3
0
파일: View.php 프로젝트: pagon/framework
 /**
  * Construct a view
  *
  * @param string $path
  * @param array  $data
  * @param array  $injectors
  * @throws \Exception
  * @return View
  */
 public function __construct($path, $data = array(), $injectors = array())
 {
     if (is_array($path)) {
         // Support View factory
         $this->injectors['data'] = $path;
         $this->compileDirectly = true;
     } else {
         // Set dir for the view
         $injectors = array('data' => (array) $data, 'path' => $path) + $injectors + array('dir' => (string) App::self()->get('views'), 'app' => App::self()) + $this->injectors;
         // Set path
         $injectors['path'] = ltrim($path, '/');
         // If file exists?
         if (!is_file($injectors['dir'] . '/' . $injectors['path'])) {
             // Try to load file from absolute path
             if ($path[0] == '/' && is_file($path)) {
                 $injectors['path'] = $path;
                 $injectors['dir'] = '';
             } else {
                 if (!empty($injectors['app']) && ($_path = $injectors['app']->path($injectors['path']))) {
                     $injectors['path'] = $_path;
                     $injectors['dir'] = '';
                 } else {
                     throw new \Exception('Template file is not exist: ' . $injectors['path']);
                 }
             }
         }
     }
     // Set data
     parent::__construct($injectors);
 }
예제 #4
0
 /**
  * Constructor
  * 
  * @param   IOLoop  $ioloop
  */
 public function __construct(IOLoop $ioloop)
 {
     parent::__construct();
     $this->iloop = $ioloop;
 }