Example #1
0
 /**
  * tries to get Connection to Smart Card
  * @return Connection|false if connection was established, then returns Connection object, otherwise false
  */
 public function getConnection()
 {
     if ($this->connection && $this->connection->getStatus()) {
         return $this->connection;
     } else {
         if ($this->connection && !$this->connection->getStatus()) {
             if (is_callable($this->onDisconnect)) {
                 call_user_func($this->onDisconnect, $this->connection);
             }
             $this->connection = null;
         }
     }
     if ($connection = scard_connect($this->context->getSContext(), $this->readerName)) {
         $this->connection = new Connection($this, $connection);
         if (is_callable($this->onConnect)) {
             call_user_func($this->onConnect, $this->connection);
         }
         return $this->connection;
     }
     return false;
 }