baseDir = $baseDir; } public function create( $server, $identity, $objClass, $objId ) { do { $token = bin2hex( random_bytes(16) ); $path = "{$this->baseDir}/tokens/access/{$token}"; } while ( file_exists( $path ) ); $content = yaml_emit([ 'server' => $server, 'identity' => $identity, 'object_class' => $objClass, 'object_id' => $objId, ]); $dir = dirname( $path ); if ( ! is_dir( $dir ) ){ mkdir( $dir, 0750, TRUE ); } if ( ! file_put_contents( $path, $content ) ){ return FALSE; } $path = "{$this->baseDir}/tokens/access/objects/{$server}/{$objClass}/{$objId}"; $dir = dirname( $path ); if ( ! is_dir( $dir ) ){ mkdir( $dir, 0750, TRUE ); } file_put_contents( $path, $token ); return $token; } public function find( $server, $objClass, $objId ) { $path = "{$this->baseDir}/tokens/access/objects/{$server}/{$objClass}/{$objId}"; if ( ! file_exists( $path ) ){ return FALSE; } return trim( file_get_contents( $path ) ); } public function get( $token ) { if ( ! $token ){ return FALSE; } $path = "{$this->baseDir}/tokens/access/{$token}"; if ( ! file_exists( $path ) ){ return FALSE; } return yaml_parse( file_get_contents( $path ) ); } } // end of file pas_access_tokens.class.php