PrivateBin\Persistence\ServerSalt::get PHP Method

get() public static method

get server salt
public static get ( ) : string
return string
    public static function get()
    {
        if (strlen(self::$_salt)) {
            return self::$_salt;
        }
        if (self::_exists(self::$_file)) {
            if (is_readable(self::getPath(self::$_file))) {
                $items = explode('|', file_get_contents(self::getPath(self::$_file)));
            }
            if (!isset($items) || !is_array($items) || count($items) != 3) {
                throw new Exception('unable to read file ' . self::getPath(self::$_file), 20);
            }
            self::$_salt = $items[1];
        } else {
            self::$_salt = self::generate();
            self::_store(self::$_file, '<?php /* |' . self::$_salt . '| */ ?>');
        }
        return self::$_salt;
    }

Usage Example

Example #1
0
 /**
  * Get paste data.
  *
  * @access public
  * @throws Exception
  * @return stdClass
  */
 public function get()
 {
     $data = $this->_store->read($this->getId());
     if ($data === false) {
         throw new Exception(PrivateBin::GENERIC_ERROR, 64);
     }
     // check if paste has expired and delete it if neccessary.
     if (property_exists($data->meta, 'expire_date')) {
         if ($data->meta->expire_date < time()) {
             $this->delete();
             throw new Exception(PrivateBin::GENERIC_ERROR, 63);
         }
         // We kindly provide the remaining time before expiration (in seconds)
         $data->meta->remaining_time = $data->meta->expire_date - time();
     }
     // set formatter for for the view.
     if (!property_exists($data->meta, 'formatter')) {
         // support < 0.21 syntax highlighting
         if (property_exists($data->meta, 'syntaxcoloring') && $data->meta->syntaxcoloring === true) {
             $data->meta->formatter = 'syntaxhighlighting';
         } else {
             $data->meta->formatter = $this->_conf->getKey('defaultformatter');
         }
     }
     // support old paste format with server wide salt
     if (!property_exists($data->meta, 'salt')) {
         $data->meta->salt = ServerSalt::get();
     }
     $data->comments = array_values($this->getComments());
     $data->comment_count = count($data->comments);
     $data->comment_offset = 0;
     $data->{'@context'} = 'js/paste.jsonld';
     $this->_data = $data;
     return $this->_data;
 }
All Usage Examples Of PrivateBin\Persistence\ServerSalt::get