idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
13,600
private function prepareStatement ( Builder $ query , $ sql ) { $ connection = $ query -> getConnection ( ) ; $ pdo = $ connection -> getPdo ( ) ; return $ pdo -> prepare ( $ sql ) ; }
Get prepared statement .
13,601
private function bindValues ( & $ values , $ statement , $ parameter ) { $ count = count ( $ values ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { if ( is_object ( $ values [ $ i ] ) ) { if ( $ values [ $ i ] instanceof DateTime ) { $ values [ $ i ] = $ values [ $ i ] -> format ( 'Y-m-d H:i:s' ) ; } else { $ values [ $ i ] = ( string ) $ values [ $ i ] ; } } $ type = $ this -> getPdoType ( $ values [ $ i ] ) ; $ statement -> bindParam ( $ parameter , $ values [ $ i ] , $ type ) ; $ parameter ++ ; } return $ parameter ; }
Bind values to PDO statement .
13,602
public function saveLob ( Builder $ query , $ sql , array $ values , array $ binaries ) { $ id = 0 ; $ parameter = 0 ; $ statement = $ this -> prepareStatement ( $ query , $ sql ) ; $ parameter = $ this -> bindValues ( $ values , $ statement , $ parameter ) ; $ countBinary = count ( $ binaries ) ; for ( $ i = 0 ; $ i < $ countBinary ; $ i ++ ) { $ statement -> bindParam ( $ parameter , $ binaries [ $ i ] , PDO :: PARAM_LOB , - 1 ) ; $ parameter ++ ; } $ statement -> bindParam ( $ parameter , $ id , PDO :: PARAM_INT , 10 ) ; if ( ! $ statement -> execute ( ) ) { return false ; } return ( int ) $ id ; }
Save Query with Blob returning primary key value .
13,603
public function autoIncrement ( $ table , $ column , $ triggerName , $ sequenceName ) { if ( ! $ table || ! $ column || ! $ triggerName || ! $ sequenceName ) { return false ; } if ( $ this -> connection -> getConfig ( 'prefix_schema' ) ) { $ table = $ this -> connection -> getConfig ( 'prefix_schema' ) . '.' . $ table ; $ triggerName = $ this -> connection -> getConfig ( 'prefix_schema' ) . '.' . $ triggerName ; $ sequenceName = $ this -> connection -> getConfig ( 'prefix_schema' ) . '.' . $ sequenceName ; } $ table = $ this -> wrapValue ( $ table ) ; $ column = $ this -> wrapValue ( $ column ) ; return $ this -> connection -> statement ( " create trigger $triggerName before insert on {$table} for each row begin if :new.{$column} is null then select {$sequenceName}.nextval into :new.{$column} from dual; end if; end;" ) ; }
Function to create auto increment trigger for a table .
13,604
protected function wrapValue ( $ value ) { $ value = Str :: upper ( $ value ) ; return $ this -> isReserved ( $ value ) ? '"' . $ value . '"' : $ value ; }
Wrap value if reserved word .
13,605
protected function parseConfig ( array $ config ) { $ config = $ this -> setHost ( $ config ) ; $ config = $ this -> setPort ( $ config ) ; $ config = $ this -> setProtocol ( $ config ) ; $ config = $ this -> setServiceId ( $ config ) ; $ config = $ this -> setTNS ( $ config ) ; $ config = $ this -> setCharset ( $ config ) ; return $ config ; }
Parse configurations .
13,606
protected function setServiceId ( array $ config ) { $ config [ 'service' ] = empty ( $ config [ 'service_name' ] ) ? $ service_param = 'SID = ' . $ config [ 'database' ] : $ service_param = 'SERVICE_NAME = ' . $ config [ 'service_name' ] ; return $ config ; }
Set service id from config .
13,607
protected function checkMultipleHostDsn ( array $ config ) { $ host = is_array ( $ config [ 'host' ] ) ? $ config [ 'host' ] : explode ( ',' , $ config [ 'host' ] ) ; $ count = count ( $ host ) ; if ( $ count > 1 ) { $ address = '' ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ address .= '(ADDRESS = (PROTOCOL = ' . $ config [ 'protocol' ] . ')(HOST = ' . trim ( $ host [ $ i ] ) . ')(PORT = ' . $ config [ 'port' ] . '))' ; } $ config [ 'tns' ] = "(DESCRIPTION = {$address} (LOAD_BALANCE = yes) (FAILOVER = on) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = {$config['database']})))" ; } return $ config ; }
Set DSN host from config .
13,608
public function get ( $ propertyName ) { return isset ( $ this -> result [ $ propertyName ] ) ? $ this -> result [ $ propertyName ] [ 1 ] : null ; }
Returns the current value for a property .
13,609
public function get404Properties ( ) { $ result = [ ] ; foreach ( $ this -> result as $ propertyName => $ stuff ) { if ( 404 === $ stuff [ 0 ] ) { $ result [ ] = $ propertyName ; } } if ( ! $ result ) { $ result [ ] = '{http://sabredav.org/ns}idk' ; } return $ result ; }
Returns all propertynames that have a 404 status and thus don t have a value yet .
13,610
protected function sendSyncCollectionResponse ( $ syncToken , $ collectionUrl , array $ added , array $ modified , array $ deleted , array $ properties ) { $ fullPaths = [ ] ; foreach ( array_merge ( $ added , $ modified ) as $ item ) { $ fullPath = $ collectionUrl . '/' . $ item ; $ fullPaths [ ] = $ fullPath ; } $ responses = [ ] ; foreach ( $ this -> server -> getPropertiesForMultiplePaths ( $ fullPaths , $ properties ) as $ fullPath => $ props ) { $ responses [ ] = new DAV \ Xml \ Element \ Response ( $ fullPath , $ props ) ; } foreach ( $ deleted as $ item ) { $ fullPath = $ collectionUrl . '/' . $ item ; $ responses [ ] = new DAV \ Xml \ Element \ Response ( $ fullPath , [ ] , 404 ) ; } $ multiStatus = new DAV \ Xml \ Response \ MultiStatus ( $ responses , self :: SYNCTOKEN_PREFIX . $ syncToken ) ; $ this -> server -> httpResponse -> setStatus ( 207 ) ; $ this -> server -> httpResponse -> setHeader ( 'Content-Type' , 'application/xml; charset=utf-8' ) ; $ this -> server -> httpResponse -> setBody ( $ this -> server -> xml -> write ( '{DAV:}multistatus' , $ multiStatus , $ this -> server -> getBaseUri ( ) ) ) ; }
Sends the response to a sync - collection request .
13,611
public function propFind ( $ url , array $ properties , $ depth = 0 ) { $ dom = new \ DOMDocument ( '1.0' , 'UTF-8' ) ; $ dom -> formatOutput = true ; $ root = $ dom -> createElementNS ( 'DAV:' , 'd:propfind' ) ; $ prop = $ dom -> createElement ( 'd:prop' ) ; foreach ( $ properties as $ property ) { list ( $ namespace , $ elementName ) = \ Sabre \ Xml \ Service :: parseClarkNotation ( $ property ) ; if ( 'DAV:' === $ namespace ) { $ element = $ dom -> createElement ( 'd:' . $ elementName ) ; } else { $ element = $ dom -> createElementNS ( $ namespace , 'x:' . $ elementName ) ; } $ prop -> appendChild ( $ element ) ; } $ dom -> appendChild ( $ root ) -> appendChild ( $ prop ) ; $ body = $ dom -> saveXML ( ) ; $ url = $ this -> getAbsoluteUrl ( $ url ) ; $ request = new HTTP \ Request ( 'PROPFIND' , $ url , [ 'Depth' => $ depth , 'Content-Type' => 'application/xml' , ] , $ body ) ; $ response = $ this -> send ( $ request ) ; if ( ( int ) $ response -> getStatus ( ) >= 400 ) { throw new HTTP \ ClientHttpException ( $ response ) ; } $ result = $ this -> parseMultiStatus ( $ response -> getBodyAsString ( ) ) ; if ( 0 === $ depth ) { reset ( $ result ) ; $ result = current ( $ result ) ; return isset ( $ result [ 200 ] ) ? $ result [ 200 ] : [ ] ; } $ newResult = [ ] ; foreach ( $ result as $ href => $ statusList ) { $ newResult [ $ href ] = isset ( $ statusList [ 200 ] ) ? $ statusList [ 200 ] : [ ] ; } return $ newResult ; }
Does a PROPFIND request .
13,612
public function propPatch ( $ url , array $ properties ) { $ propPatch = new Xml \ Request \ PropPatch ( ) ; $ propPatch -> properties = $ properties ; $ xml = $ this -> xml -> write ( '{DAV:}propertyupdate' , $ propPatch ) ; $ url = $ this -> getAbsoluteUrl ( $ url ) ; $ request = new HTTP \ Request ( 'PROPPATCH' , $ url , [ 'Content-Type' => 'application/xml' , ] , $ xml ) ; $ response = $ this -> send ( $ request ) ; if ( $ response -> getStatus ( ) >= 400 ) { throw new HTTP \ ClientHttpException ( $ response ) ; } if ( 207 === $ response -> getStatus ( ) ) { $ result = $ this -> parseMultiStatus ( $ response -> getBodyAsString ( ) ) ; $ errorProperties = [ ] ; foreach ( $ result as $ href => $ statusList ) { foreach ( $ statusList as $ status => $ properties ) { if ( $ status >= 400 ) { foreach ( $ properties as $ propName => $ propValue ) { $ errorProperties [ ] = $ propName . ' (' . $ status . ')' ; } } } } if ( $ errorProperties ) { throw new HTTP \ ClientException ( 'PROPPATCH failed. The following properties errored: ' . implode ( ', ' , $ errorProperties ) ) ; } } return true ; }
Updates a list of properties on the server .
13,613
public function options ( ) { $ request = new HTTP \ Request ( 'OPTIONS' , $ this -> getAbsoluteUrl ( '' ) ) ; $ response = $ this -> send ( $ request ) ; $ dav = $ response -> getHeader ( 'Dav' ) ; if ( ! $ dav ) { return [ ] ; } $ features = explode ( ',' , $ dav ) ; foreach ( $ features as & $ v ) { $ v = trim ( $ v ) ; } return $ features ; }
Performs an HTTP options request .
13,614
public function request ( $ method , $ url = '' , $ body = null , array $ headers = [ ] ) { $ url = $ this -> getAbsoluteUrl ( $ url ) ; $ response = $ this -> send ( new HTTP \ Request ( $ method , $ url , $ headers , $ body ) ) ; return [ 'body' => $ response -> getBodyAsString ( ) , 'statusCode' => ( int ) $ response -> getStatus ( ) , 'headers' => array_change_key_case ( $ response -> getHeaders ( ) ) , ] ; }
Performs an actual HTTP request and returns the result .
13,615
public function parseMultiStatus ( $ body ) { $ multistatus = $ this -> xml -> expect ( '{DAV:}multistatus' , $ body ) ; $ result = [ ] ; foreach ( $ multistatus -> getResponses ( ) as $ response ) { $ result [ $ response -> getHref ( ) ] = $ response -> getResponseProperties ( ) ; } return $ result ; }
Parses a WebDAV multistatus response body .
13,616
public function getChild ( $ name ) { $ obj = $ this -> carddavBackend -> getCard ( $ this -> addressBookInfo [ 'id' ] , $ name ) ; if ( ! $ obj ) { throw new DAV \ Exception \ NotFound ( 'Card not found' ) ; } return new Card ( $ this -> carddavBackend , $ this -> addressBookInfo , $ obj ) ; }
Returns a card .
13,617
public function getChildren ( ) { $ objs = $ this -> carddavBackend -> getCards ( $ this -> addressBookInfo [ 'id' ] ) ; $ children = [ ] ; foreach ( $ objs as $ obj ) { $ obj [ 'acl' ] = $ this -> getChildACL ( ) ; $ children [ ] = new Card ( $ this -> carddavBackend , $ this -> addressBookInfo , $ obj ) ; } return $ children ; }
Returns the full list of cards .
13,618
public function getChild ( $ name ) { if ( 'inbox' === $ name && $ this -> caldavBackend instanceof Backend \ SchedulingSupport ) { return new Schedule \ Inbox ( $ this -> caldavBackend , $ this -> principalInfo [ 'uri' ] ) ; } if ( 'outbox' === $ name && $ this -> caldavBackend instanceof Backend \ SchedulingSupport ) { return new Schedule \ Outbox ( $ this -> principalInfo [ 'uri' ] ) ; } if ( 'notifications' === $ name && $ this -> caldavBackend instanceof Backend \ NotificationSupport ) { return new Notifications \ Collection ( $ this -> caldavBackend , $ this -> principalInfo [ 'uri' ] ) ; } foreach ( $ this -> caldavBackend -> getCalendarsForUser ( $ this -> principalInfo [ 'uri' ] ) as $ calendar ) { if ( $ calendar [ 'uri' ] === $ name ) { if ( $ this -> caldavBackend instanceof Backend \ SharingSupport ) { return new SharedCalendar ( $ this -> caldavBackend , $ calendar ) ; } else { return new Calendar ( $ this -> caldavBackend , $ calendar ) ; } } } if ( $ this -> caldavBackend instanceof Backend \ SubscriptionSupport ) { foreach ( $ this -> caldavBackend -> getSubscriptionsForUser ( $ this -> principalInfo [ 'uri' ] ) as $ subscription ) { if ( $ subscription [ 'uri' ] === $ name ) { return new Subscriptions \ Subscription ( $ this -> caldavBackend , $ subscription ) ; } } } throw new NotFound ( 'Node with name \'' . $ name . '\' could not be found' ) ; }
Returns a single calendar by name .
13,619
public function getChildren ( ) { $ calendars = $ this -> caldavBackend -> getCalendarsForUser ( $ this -> principalInfo [ 'uri' ] ) ; $ objs = [ ] ; foreach ( $ calendars as $ calendar ) { if ( $ this -> caldavBackend instanceof Backend \ SharingSupport ) { $ objs [ ] = new SharedCalendar ( $ this -> caldavBackend , $ calendar ) ; } else { $ objs [ ] = new Calendar ( $ this -> caldavBackend , $ calendar ) ; } } if ( $ this -> caldavBackend instanceof Backend \ SchedulingSupport ) { $ objs [ ] = new Schedule \ Inbox ( $ this -> caldavBackend , $ this -> principalInfo [ 'uri' ] ) ; $ objs [ ] = new Schedule \ Outbox ( $ this -> principalInfo [ 'uri' ] ) ; } if ( $ this -> caldavBackend instanceof Backend \ NotificationSupport ) { $ objs [ ] = new Notifications \ Collection ( $ this -> caldavBackend , $ this -> principalInfo [ 'uri' ] ) ; } if ( $ this -> caldavBackend instanceof Backend \ SubscriptionSupport ) { foreach ( $ this -> caldavBackend -> getSubscriptionsForUser ( $ this -> principalInfo [ 'uri' ] ) as $ subscription ) { $ objs [ ] = new Subscriptions \ Subscription ( $ this -> caldavBackend , $ subscription ) ; } } return $ objs ; }
Returns a list of calendars .
13,620
public function createExtendedCollection ( $ name , MkCol $ mkCol ) { $ isCalendar = false ; $ isSubscription = false ; foreach ( $ mkCol -> getResourceType ( ) as $ rt ) { switch ( $ rt ) { case '{DAV:}collection' : case '{http://calendarserver.org/ns/}shared-owner' : break ; case '{urn:ietf:params:xml:ns:caldav}calendar' : $ isCalendar = true ; break ; case '{http://calendarserver.org/ns/}subscribed' : $ isSubscription = true ; break ; default : throw new DAV \ Exception \ InvalidResourceType ( 'Unknown resourceType: ' . $ rt ) ; } } $ properties = $ mkCol -> getRemainingValues ( ) ; $ mkCol -> setRemainingResultCode ( 201 ) ; if ( $ isSubscription ) { if ( ! $ this -> caldavBackend instanceof Backend \ SubscriptionSupport ) { throw new DAV \ Exception \ InvalidResourceType ( 'This backend does not support subscriptions' ) ; } $ this -> caldavBackend -> createSubscription ( $ this -> principalInfo [ 'uri' ] , $ name , $ properties ) ; } elseif ( $ isCalendar ) { $ this -> caldavBackend -> createCalendar ( $ this -> principalInfo [ 'uri' ] , $ name , $ properties ) ; } else { throw new DAV \ Exception \ InvalidResourceType ( 'You can only create calendars and subscriptions in this collection' ) ; } }
Creates a new calendar or subscription .
13,621
public function shareReply ( $ href , $ status , $ calendarUri , $ inReplyTo , $ summary = null ) { if ( ! $ this -> caldavBackend instanceof Backend \ SharingSupport ) { throw new DAV \ Exception \ NotImplemented ( 'Sharing support is not implemented by this backend.' ) ; } return $ this -> caldavBackend -> shareReply ( $ href , $ status , $ calendarUri , $ inReplyTo , $ summary ) ; }
This method is called when a user replied to a request to share .
13,622
public function httpGet ( RequestInterface $ request , ResponseInterface $ response ) { $ queryParams = $ request -> getQueryParameters ( ) ; if ( ! array_key_exists ( 'mount' , $ queryParams ) ) { return ; } $ currentUri = $ request -> getAbsoluteUrl ( ) ; list ( $ currentUri ) = explode ( '?' , $ currentUri ) ; $ this -> davMount ( $ response , $ currentUri ) ; return false ; }
beforeMethod event handles . This event handles intercepts GET requests ending with ?mount .
13,623
public function davMount ( ResponseInterface $ response , $ uri ) { $ response -> setStatus ( 200 ) ; $ response -> setHeader ( 'Content-Type' , 'application/davmount+xml' ) ; ob_start ( ) ; echo '<?xml version="1.0"?>' , "\n" ; echo "<dm:mount xmlns:dm=\"http://purl.org/NET/webdav/mount\">\n" ; echo ' <dm:url>' , htmlspecialchars ( $ uri , ENT_NOQUOTES , 'UTF-8' ) , "</dm:url>\n" ; echo '</dm:mount>' ; $ response -> setBody ( ob_get_clean ( ) ) ; }
Generates the davmount response .
13,624
public function getChildForPrincipal ( array $ principalInfo ) { $ owner = $ principalInfo [ 'uri' ] ; $ acl = [ [ 'privilege' => '{DAV:}all' , 'principal' => '{DAV:}owner' , 'protected' => true , ] , ] ; list ( , $ principalBaseName ) = Uri \ split ( $ owner ) ; $ path = $ this -> storagePath . '/' . $ principalBaseName ; if ( ! is_dir ( $ path ) ) { mkdir ( $ path , 0777 , true ) ; } return new Collection ( $ path , $ acl , $ owner ) ; }
Returns a principals collection of files .
13,625
public function getPrincipalsByPrefix ( $ prefixPath ) { $ fields = [ 'uri' , ] ; foreach ( $ this -> fieldMap as $ key => $ value ) { $ fields [ ] = $ value [ 'dbField' ] ; } $ result = $ this -> pdo -> query ( 'SELECT ' . implode ( ',' , $ fields ) . ' FROM ' . $ this -> tableName ) ; $ principals = [ ] ; while ( $ row = $ result -> fetch ( \ PDO :: FETCH_ASSOC ) ) { list ( $ rowPrefix ) = Uri \ split ( $ row [ 'uri' ] ) ; if ( $ rowPrefix !== $ prefixPath ) { continue ; } $ principal = [ 'uri' => $ row [ 'uri' ] , ] ; foreach ( $ this -> fieldMap as $ key => $ value ) { if ( $ row [ $ value [ 'dbField' ] ] ) { $ principal [ $ key ] = $ row [ $ value [ 'dbField' ] ] ; } } $ principals [ ] = $ principal ; } return $ principals ; }
Returns a list of principals based on a prefix .
13,626
public function getPrincipalByPath ( $ path ) { $ fields = [ 'id' , 'uri' , ] ; foreach ( $ this -> fieldMap as $ key => $ value ) { $ fields [ ] = $ value [ 'dbField' ] ; } $ stmt = $ this -> pdo -> prepare ( 'SELECT ' . implode ( ',' , $ fields ) . ' FROM ' . $ this -> tableName . ' WHERE uri = ?' ) ; $ stmt -> execute ( [ $ path ] ) ; $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ; if ( ! $ row ) { return ; } $ principal = [ 'id' => $ row [ 'id' ] , 'uri' => $ row [ 'uri' ] , ] ; foreach ( $ this -> fieldMap as $ key => $ value ) { if ( $ row [ $ value [ 'dbField' ] ] ) { $ principal [ $ key ] = $ row [ $ value [ 'dbField' ] ] ; } } return $ principal ; }
Returns a specific principal specified by it s path . The returned structure should be the exact same as from getPrincipalsByPrefix .
13,627
public function updatePrincipal ( $ path , DAV \ PropPatch $ propPatch ) { $ propPatch -> handle ( array_keys ( $ this -> fieldMap ) , function ( $ properties ) use ( $ path ) { $ query = 'UPDATE ' . $ this -> tableName . ' SET ' ; $ first = true ; $ values = [ ] ; foreach ( $ properties as $ key => $ value ) { $ dbField = $ this -> fieldMap [ $ key ] [ 'dbField' ] ; if ( ! $ first ) { $ query .= ', ' ; } $ first = false ; $ query .= $ dbField . ' = :' . $ dbField ; $ values [ $ dbField ] = $ value ; } $ query .= ' WHERE uri = :uri' ; $ values [ 'uri' ] = $ path ; $ stmt = $ this -> pdo -> prepare ( $ query ) ; $ stmt -> execute ( $ values ) ; return true ; } ) ; }
Updates one ore more webdav properties on a principal .
13,628
public function getGroupMemberSet ( $ principal ) { $ principal = $ this -> getPrincipalByPath ( $ principal ) ; if ( ! $ principal ) { throw new DAV \ Exception ( 'Principal not found' ) ; } $ stmt = $ this -> pdo -> prepare ( 'SELECT principals.uri as uri FROM ' . $ this -> groupMembersTableName . ' AS groupmembers LEFT JOIN ' . $ this -> tableName . ' AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?' ) ; $ stmt -> execute ( [ $ principal [ 'id' ] ] ) ; $ result = [ ] ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ result [ ] = $ row [ 'uri' ] ; } return $ result ; }
Returns the list of members for a group - principal .
13,629
public function setGroupMemberSet ( $ principal , array $ members ) { $ stmt = $ this -> pdo -> prepare ( 'SELECT id, uri FROM ' . $ this -> tableName . ' WHERE uri IN (? ' . str_repeat ( ', ? ' , count ( $ members ) ) . ');' ) ; $ stmt -> execute ( array_merge ( [ $ principal ] , $ members ) ) ; $ memberIds = [ ] ; $ principalId = null ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { if ( $ row [ 'uri' ] == $ principal ) { $ principalId = $ row [ 'id' ] ; } else { $ memberIds [ ] = $ row [ 'id' ] ; } } if ( ! $ principalId ) { throw new DAV \ Exception ( 'Principal not found' ) ; } $ stmt = $ this -> pdo -> prepare ( 'DELETE FROM ' . $ this -> groupMembersTableName . ' WHERE principal_id = ?;' ) ; $ stmt -> execute ( [ $ principalId ] ) ; foreach ( $ memberIds as $ memberId ) { $ stmt = $ this -> pdo -> prepare ( 'INSERT INTO ' . $ this -> groupMembersTableName . ' (principal_id, member_id) VALUES (?, ?);' ) ; $ stmt -> execute ( [ $ principalId , $ memberId ] ) ; } }
Updates the list of group members for a group principal .
13,630
public function createPrincipal ( $ path , MkCol $ mkCol ) { $ stmt = $ this -> pdo -> prepare ( 'INSERT INTO ' . $ this -> tableName . ' (uri) VALUES (?)' ) ; $ stmt -> execute ( [ $ path ] ) ; $ this -> updatePrincipal ( $ path , $ mkCol ) ; }
Creates a new principal .
13,631
public function initialize ( Server $ server ) { $ this -> server = $ server ; $ server -> on ( 'beforeMethod:*' , [ $ this , 'beforeMethod' ] ) ; $ server -> on ( 'beforeCreateFile' , [ $ this , 'beforeCreateFile' ] ) ; }
Initialize the plugin .
13,632
public function beforeMethod ( RequestInterface $ request , ResponseInterface $ response ) { if ( ! $ tempLocation = $ this -> isTempFile ( $ request -> getPath ( ) ) ) { return ; } switch ( $ request -> getMethod ( ) ) { case 'GET' : return $ this -> httpGet ( $ request , $ response , $ tempLocation ) ; case 'PUT' : return $ this -> httpPut ( $ request , $ response , $ tempLocation ) ; case 'PROPFIND' : return $ this -> httpPropfind ( $ request , $ response , $ tempLocation ) ; case 'DELETE' : return $ this -> httpDelete ( $ request , $ response , $ tempLocation ) ; } return ; }
This method is called before any HTTP method handler .
13,633
public function beforeCreateFile ( $ uri , $ data , ICollection $ parent , $ modified ) { if ( $ tempPath = $ this -> isTempFile ( $ uri ) ) { $ hR = $ this -> server -> httpResponse ; $ hR -> setHeader ( 'X-Sabre-Temp' , 'true' ) ; file_put_contents ( $ tempPath , $ data ) ; return false ; } return ; }
This method is invoked if some subsystem creates a new file .
13,634
public function httpGet ( RequestInterface $ request , ResponseInterface $ hR , $ tempLocation ) { if ( ! file_exists ( $ tempLocation ) ) { return ; } $ hR -> setHeader ( 'Content-Type' , 'application/octet-stream' ) ; $ hR -> setHeader ( 'Content-Length' , filesize ( $ tempLocation ) ) ; $ hR -> setHeader ( 'X-Sabre-Temp' , 'true' ) ; $ hR -> setStatus ( 200 ) ; $ hR -> setBody ( fopen ( $ tempLocation , 'r' ) ) ; return false ; }
This method handles the GET method for temporary files . If the file doesn t exist it will return false which will kick in the regular system for the GET method .
13,635
public function httpPut ( RequestInterface $ request , ResponseInterface $ hR , $ tempLocation ) { $ hR -> setHeader ( 'X-Sabre-Temp' , 'true' ) ; $ newFile = ! file_exists ( $ tempLocation ) ; if ( ! $ newFile && ( $ this -> server -> httpRequest -> getHeader ( 'If-None-Match' ) ) ) { throw new Exception \ PreconditionFailed ( 'The resource already exists, and an If-None-Match header was supplied' ) ; } file_put_contents ( $ tempLocation , $ this -> server -> httpRequest -> getBody ( ) ) ; $ hR -> setStatus ( $ newFile ? 201 : 200 ) ; return false ; }
This method handles the PUT method .
13,636
public function httpDelete ( RequestInterface $ request , ResponseInterface $ hR , $ tempLocation ) { if ( ! file_exists ( $ tempLocation ) ) { return ; } unlink ( $ tempLocation ) ; $ hR -> setHeader ( 'X-Sabre-Temp' , 'true' ) ; $ hR -> setStatus ( 204 ) ; return false ; }
This method handles the DELETE method .
13,637
public function httpPropfind ( RequestInterface $ request , ResponseInterface $ hR , $ tempLocation ) { if ( ! file_exists ( $ tempLocation ) ) { return ; } $ hR -> setHeader ( 'X-Sabre-Temp' , 'true' ) ; $ hR -> setStatus ( 207 ) ; $ hR -> setHeader ( 'Content-Type' , 'application/xml; charset=utf-8' ) ; $ properties = [ 'href' => $ request -> getPath ( ) , 200 => [ '{DAV:}getlastmodified' => new Xml \ Property \ GetLastModified ( filemtime ( $ tempLocation ) ) , '{DAV:}getcontentlength' => filesize ( $ tempLocation ) , '{DAV:}resourcetype' => new Xml \ Property \ ResourceType ( null ) , '{' . Server :: NS_SABREDAV . '}tempFile' => true , ] , ] ; $ data = $ this -> server -> generateMultiStatus ( [ $ properties ] ) ; $ hR -> setBody ( $ data ) ; return false ; }
This method handles the PROPFIND method .
13,638
public function shareResource ( $ path , array $ sharees ) { $ node = $ this -> server -> tree -> getNodeForPath ( $ path ) ; if ( ! $ node instanceof ISharedNode ) { throw new Forbidden ( 'Sharing is not allowed on this node' ) ; } $ acl = $ this -> server -> getPlugin ( 'acl' ) ; if ( $ acl ) { $ acl -> checkPrivileges ( $ path , '{DAV:}share' ) ; } foreach ( $ sharees as $ sharee ) { $ principal = null ; $ this -> server -> emit ( 'getPrincipalByUri' , [ $ sharee -> href , & $ principal ] ) ; $ sharee -> principal = $ principal ; } $ node -> updateInvites ( $ sharees ) ; }
Updates the list of sharees on a shared resource .
13,639
public function propFind ( PropFind $ propFind , INode $ node ) { if ( $ node instanceof ISharedNode ) { $ propFind -> handle ( '{DAV:}share-access' , function ( ) use ( $ node ) { return new Property \ ShareAccess ( $ node -> getShareAccess ( ) ) ; } ) ; $ propFind -> handle ( '{DAV:}invite' , function ( ) use ( $ node ) { return new Property \ Invite ( $ node -> getInvites ( ) ) ; } ) ; $ propFind -> handle ( '{DAV:}share-resource-uri' , function ( ) use ( $ node ) { return new Property \ Href ( $ node -> getShareResourceUri ( ) ) ; } ) ; } }
This event is triggered when properties are requested for nodes .
13,640
public function httpPost ( RequestInterface $ request , ResponseInterface $ response ) { $ path = $ request -> getPath ( ) ; $ contentType = $ request -> getHeader ( 'Content-Type' ) ; if ( null === $ contentType ) { return ; } if ( false === strpos ( $ contentType , 'application/davsharing+xml' ) ) { return ; } $ message = $ this -> server -> xml -> parse ( $ request -> getBody ( ) , $ request -> getUrl ( ) , $ documentType ) ; switch ( $ documentType ) { case '{DAV:}share-resource' : $ this -> shareResource ( $ path , $ message -> sharees ) ; $ response -> setStatus ( 200 ) ; $ response -> setHeader ( 'X-Sabre-Status' , 'everything-went-well' ) ; return false ; default : throw new BadRequest ( 'Unexpected document type: ' . $ documentType . ' for this Content-Type' ) ; } }
We intercept this to handle POST requests on shared resources .
13,641
public function htmlActionsPanel ( INode $ node , & $ output , $ path ) { if ( ! $ node instanceof ISharedNode ) { return ; } $ aclPlugin = $ this -> server -> getPlugin ( 'acl' ) ; if ( $ aclPlugin ) { if ( ! $ aclPlugin -> checkPrivileges ( $ path , '{DAV:}share' , \ Sabre \ DAVACL \ Plugin :: R_PARENT , false ) ) { return ; } } $ output .= '<tr><td colspan="2"><form method="post" action=""> <h3>Share this resource</h3> <input type="hidden" name="sabreAction" value="share" /> <label>Share with (uri):</label> <input type="text" name="href" placeholder="mailto:user@example.org"/><br /> <label>Access</label> <select name="access"> <option value="readwrite">Read-write</option> <option value="read">Read-only</option> <option value="no-access">Revoke access</option> </select><br /> <input type="submit" value="share" /> </form> </td></tr>' ; }
This method is used to generate HTML output for the DAV \ Browser \ Plugin .
13,642
public function browserPostAction ( $ path , $ action , $ postVars ) { if ( 'share' !== $ action ) { return ; } if ( empty ( $ postVars [ 'href' ] ) ) { throw new BadRequest ( 'The "href" POST parameter is required' ) ; } if ( empty ( $ postVars [ 'access' ] ) ) { throw new BadRequest ( 'The "access" POST parameter is required' ) ; } $ accessMap = [ 'readwrite' => self :: ACCESS_READWRITE , 'read' => self :: ACCESS_READ , 'no-access' => self :: ACCESS_NOACCESS , ] ; if ( ! isset ( $ accessMap [ $ postVars [ 'access' ] ] ) ) { throw new BadRequest ( 'The "access" POST must be readwrite, read or no-access' ) ; } $ sharee = new Sharee ( [ 'href' => $ postVars [ 'href' ] , 'access' => $ accessMap [ $ postVars [ 'access' ] ] , ] ) ; $ this -> shareResource ( $ path , [ $ sharee ] ) ; return false ; }
This method is triggered for POST actions generated by the browser plugin .
13,643
public function getBaseUri ( ) { if ( is_null ( $ this -> baseUri ) ) { $ this -> baseUri = $ this -> guessBaseUri ( ) ; } return $ this -> baseUri ; }
Returns the base responding uri .
13,644
public function guessBaseUri ( ) { $ pathInfo = $ this -> httpRequest -> getRawServerValue ( 'PATH_INFO' ) ; $ uri = $ this -> httpRequest -> getRawServerValue ( 'REQUEST_URI' ) ; if ( ! empty ( $ pathInfo ) ) { if ( $ pos = strpos ( $ uri , '?' ) ) { $ uri = substr ( $ uri , 0 , $ pos ) ; } $ decodedUri = HTTP \ decodePath ( $ uri ) ; if ( substr ( $ decodedUri , strlen ( $ decodedUri ) - strlen ( $ pathInfo ) ) === $ pathInfo ) { $ baseUri = substr ( $ decodedUri , 0 , strlen ( $ decodedUri ) - strlen ( $ pathInfo ) ) ; return rtrim ( $ baseUri , '/' ) . '/' ; } throw new Exception ( 'The REQUEST_URI (' . $ uri . ') did not end with the contents of PATH_INFO (' . $ pathInfo . '). This server might be misconfigured.' ) ; } return '/' ; }
This method attempts to detect the base uri . Only the PATH_INFO variable is considered .
13,645
public function addPlugin ( ServerPlugin $ plugin ) { $ this -> plugins [ $ plugin -> getPluginName ( ) ] = $ plugin ; $ plugin -> initialize ( $ this ) ; }
Adds a plugin to the server .
13,646
public function getPlugin ( $ name ) { if ( isset ( $ this -> plugins [ $ name ] ) ) { return $ this -> plugins [ $ name ] ; } return null ; }
Returns an initialized plugin by it s name .
13,647
public function invokeMethod ( RequestInterface $ request , ResponseInterface $ response , $ sendResponse = true ) { $ method = $ request -> getMethod ( ) ; if ( ! $ this -> emit ( 'beforeMethod:' . $ method , [ $ request , $ response ] ) ) { return ; } if ( self :: $ exposeVersion ) { $ response -> setHeader ( 'X-Sabre-Version' , Version :: VERSION ) ; } $ this -> transactionType = strtolower ( $ method ) ; if ( ! $ this -> checkPreconditions ( $ request , $ response ) ) { $ this -> sapi -> sendResponse ( $ response ) ; return ; } if ( $ this -> emit ( 'method:' . $ method , [ $ request , $ response ] ) ) { $ exMessage = 'There was no plugin in the system that was willing to handle this ' . $ method . ' method.' ; if ( 'GET' === $ method ) { $ exMessage .= ' Enable the Browser plugin to get a better result here.' ; } throw new Exception \ NotImplemented ( $ exMessage ) ; } if ( ! $ this -> emit ( 'afterMethod:' . $ method , [ $ request , $ response ] ) ) { return ; } if ( null === $ response -> getStatus ( ) ) { throw new Exception ( 'No subsystem set a valid HTTP status code. Something must have interrupted the request without providing further detail.' ) ; } if ( $ sendResponse ) { $ this -> sapi -> sendResponse ( $ response ) ; $ this -> emit ( 'afterResponse' , [ $ request , $ response ] ) ; } }
Handles a http request and execute a method based on its name .
13,648
public function getAllowedMethods ( $ path ) { $ methods = [ 'OPTIONS' , 'GET' , 'HEAD' , 'DELETE' , 'PROPFIND' , 'PUT' , 'PROPPATCH' , 'COPY' , 'MOVE' , 'REPORT' , ] ; try { $ this -> tree -> getNodeForPath ( $ path ) ; } catch ( Exception \ NotFound $ e ) { $ methods [ ] = 'MKCOL' ; } foreach ( $ this -> plugins as $ plugin ) { $ methods = array_merge ( $ methods , $ plugin -> getHTTPMethods ( $ path ) ) ; } array_unique ( $ methods ) ; return $ methods ; }
Returns an array with all the supported HTTP methods for a specific uri .
13,649
public function calculateUri ( $ uri ) { if ( '' != $ uri && '/' != $ uri [ 0 ] && strpos ( $ uri , '://' ) ) { $ uri = parse_url ( $ uri , PHP_URL_PATH ) ; } $ uri = Uri \ normalize ( preg_replace ( '|/+|' , '/' , $ uri ) ) ; $ baseUri = Uri \ normalize ( $ this -> getBaseUri ( ) ) ; if ( 0 === strpos ( $ uri , $ baseUri ) ) { return trim ( HTTP \ decodePath ( substr ( $ uri , strlen ( $ baseUri ) ) ) , '/' ) ; } elseif ( $ uri . '/' === $ baseUri ) { return '' ; } else { throw new Exception \ Forbidden ( 'Requested uri (' . $ uri . ') is out of base uri (' . $ this -> getBaseUri ( ) . ')' ) ; } }
Turns a URI such as the REQUEST_URI into a local path .
13,650
public function getHTTPDepth ( $ default = self :: DEPTH_INFINITY ) { $ depth = $ this -> httpRequest -> getHeader ( 'Depth' ) ; if ( is_null ( $ depth ) ) { return $ default ; } if ( 'infinity' == $ depth ) { return self :: DEPTH_INFINITY ; } if ( ! ctype_digit ( $ depth ) ) { return $ default ; } return ( int ) $ depth ; }
Returns the HTTP depth header .
13,651
public function getHTTPRange ( ) { $ range = $ this -> httpRequest -> getHeader ( 'range' ) ; if ( is_null ( $ range ) ) { return null ; } if ( ! preg_match ( '/^bytes=([0-9]*)-([0-9]*)$/i' , $ range , $ matches ) ) { return null ; } if ( '' === $ matches [ 1 ] && '' === $ matches [ 2 ] ) { return null ; } return [ '' !== $ matches [ 1 ] ? ( int ) $ matches [ 1 ] : null , '' !== $ matches [ 2 ] ? ( int ) $ matches [ 2 ] : null , ] ; }
Returns the HTTP range header .
13,652
public function getHTTPPrefer ( ) { $ result = [ 'respond-async' => false , 'return' => null , 'wait' => null , 'handling' => false , ] ; if ( $ prefer = $ this -> httpRequest -> getHeader ( 'Prefer' ) ) { $ result = array_merge ( $ result , HTTP \ parsePrefer ( $ prefer ) ) ; } elseif ( 't' == $ this -> httpRequest -> getHeader ( 'Brief' ) ) { $ result [ 'return' ] = 'minimal' ; } return $ result ; }
Returns the HTTP Prefer header information .
13,653
public function getCopyAndMoveInfo ( RequestInterface $ request ) { if ( ! $ request -> getHeader ( 'Destination' ) ) { throw new Exception \ BadRequest ( 'The destination header was not supplied' ) ; } $ destination = $ this -> calculateUri ( $ request -> getHeader ( 'Destination' ) ) ; $ overwrite = $ request -> getHeader ( 'Overwrite' ) ; if ( ! $ overwrite ) { $ overwrite = 'T' ; } if ( 'T' == strtoupper ( $ overwrite ) ) { $ overwrite = true ; } elseif ( 'F' == strtoupper ( $ overwrite ) ) { $ overwrite = false ; } else { throw new Exception \ BadRequest ( 'The HTTP Overwrite header should be either T or F' ) ; } list ( $ destinationDir ) = Uri \ split ( $ destination ) ; try { $ destinationParent = $ this -> tree -> getNodeForPath ( $ destinationDir ) ; if ( ! ( $ destinationParent instanceof ICollection ) ) { throw new Exception \ UnsupportedMediaType ( 'The destination node is not a collection' ) ; } } catch ( Exception \ NotFound $ e ) { throw new Exception \ Conflict ( 'The destination node is not found' ) ; } try { $ destinationNode = $ this -> tree -> getNodeForPath ( $ destination ) ; if ( ! $ overwrite ) { throw new Exception \ PreconditionFailed ( 'The destination node already exists, and the overwrite header is set to false' , 'Overwrite' ) ; } } catch ( Exception \ NotFound $ e ) { $ destinationNode = false ; } $ requestPath = $ request -> getPath ( ) ; if ( $ destination === $ requestPath ) { throw new Exception \ Forbidden ( 'Source and destination uri are identical.' ) ; } if ( substr ( $ destination , 0 , strlen ( $ requestPath ) + 1 ) === $ requestPath . '/' ) { throw new Exception \ Conflict ( 'The destination may not be part of the same subtree as the source path.' ) ; } return [ 'destination' => $ destination , 'destinationExists' => ( bool ) $ destinationNode , 'destinationNode' => $ destinationNode , ] ; }
Returns information about Copy and Move requests .
13,654
public function getProperties ( $ path , $ propertyNames ) { $ result = $ this -> getPropertiesForPath ( $ path , $ propertyNames , 0 ) ; if ( isset ( $ result [ 0 ] [ 200 ] ) ) { return $ result [ 0 ] [ 200 ] ; } else { return [ ] ; } }
Returns a list of properties for a path .
13,655
public function getPropertiesForChildren ( $ path , $ propertyNames ) { $ result = [ ] ; foreach ( $ this -> getPropertiesForPath ( $ path , $ propertyNames , 1 ) as $ k => $ row ) { if ( 0 === $ k ) { continue ; } $ result [ $ row [ 'href' ] ] = $ row [ 200 ] ; } return $ result ; }
A kid - friendly way to fetch properties for a node s children .
13,656
public function getHTTPHeaders ( $ path ) { $ propertyMap = [ '{DAV:}getcontenttype' => 'Content-Type' , '{DAV:}getcontentlength' => 'Content-Length' , '{DAV:}getlastmodified' => 'Last-Modified' , '{DAV:}getetag' => 'ETag' , ] ; $ properties = $ this -> getProperties ( $ path , array_keys ( $ propertyMap ) ) ; $ headers = [ ] ; foreach ( $ propertyMap as $ property => $ header ) { if ( ! isset ( $ properties [ $ property ] ) ) { continue ; } if ( is_scalar ( $ properties [ $ property ] ) ) { $ headers [ $ header ] = $ properties [ $ property ] ; } elseif ( $ properties [ $ property ] instanceof Xml \ Property \ GetLastModified ) { $ headers [ $ header ] = HTTP \ toDate ( $ properties [ $ property ] -> getTime ( ) ) ; } } return $ headers ; }
Returns a list of HTTP headers for a particular resource .
13,657
private function generatePathNodes ( PropFind $ propFind , array $ yieldFirst = null ) { if ( null !== $ yieldFirst ) { yield $ yieldFirst ; } $ newDepth = $ propFind -> getDepth ( ) ; $ path = $ propFind -> getPath ( ) ; if ( self :: DEPTH_INFINITY !== $ newDepth ) { -- $ newDepth ; } $ propertyNames = $ propFind -> getRequestedProperties ( ) ; $ propFindType = ! empty ( $ propertyNames ) ? PropFind :: NORMAL : PropFind :: ALLPROPS ; foreach ( $ this -> tree -> getChildren ( $ path ) as $ childNode ) { if ( '' !== $ path ) { $ subPath = $ path . '/' . $ childNode -> getName ( ) ; } else { $ subPath = $ childNode -> getName ( ) ; } $ subPropFind = new PropFind ( $ subPath , $ propertyNames , $ newDepth , $ propFindType ) ; yield [ $ subPropFind , $ childNode , ] ; if ( ( self :: DEPTH_INFINITY === $ newDepth || $ newDepth >= 1 ) && $ childNode instanceof ICollection ) { foreach ( $ this -> generatePathNodes ( $ subPropFind ) as $ subItem ) { yield $ subItem ; } } } }
Small helper to support PROPFIND with DEPTH_INFINITY .
13,658
public function getPropertiesForMultiplePaths ( array $ paths , array $ propertyNames = [ ] ) { $ result = [ ] ; $ nodes = $ this -> tree -> getMultipleNodes ( $ paths ) ; foreach ( $ nodes as $ path => $ node ) { $ propFind = new PropFind ( $ path , $ propertyNames ) ; $ r = $ this -> getPropertiesByNode ( $ propFind , $ node ) ; if ( $ r ) { $ result [ $ path ] = $ propFind -> getResultForMultiStatus ( ) ; $ result [ $ path ] [ 'href' ] = $ path ; $ resourceType = $ this -> getResourceTypeForNode ( $ node ) ; if ( in_array ( '{DAV:}collection' , $ resourceType ) || in_array ( '{DAV:}principal' , $ resourceType ) ) { $ result [ $ path ] [ 'href' ] .= '/' ; } } } return $ result ; }
Returns a list of properties for a list of paths .
13,659
public function createFile ( $ uri , $ data , & $ etag = null ) { list ( $ dir , $ name ) = Uri \ split ( $ uri ) ; if ( ! $ this -> emit ( 'beforeBind' , [ $ uri ] ) ) { return false ; } $ parent = $ this -> tree -> getNodeForPath ( $ dir ) ; if ( ! $ parent instanceof ICollection ) { throw new Exception \ Conflict ( 'Files can only be created as children of collections' ) ; } $ modified = false ; if ( ! $ this -> emit ( 'beforeCreateFile' , [ $ uri , & $ data , $ parent , & $ modified ] ) ) { return false ; } $ etag = $ parent -> createFile ( $ name , $ data ) ; if ( $ modified ) { $ etag = null ; } $ this -> tree -> markDirty ( $ dir . '/' . $ name ) ; $ this -> emit ( 'afterBind' , [ $ uri ] ) ; $ this -> emit ( 'afterCreateFile' , [ $ uri , $ parent ] ) ; return true ; }
This method is invoked by sub - systems creating a new file .
13,660
public function updateFile ( $ uri , $ data , & $ etag = null ) { $ node = $ this -> tree -> getNodeForPath ( $ uri ) ; $ modified = false ; if ( ! $ this -> emit ( 'beforeWriteContent' , [ $ uri , $ node , & $ data , & $ modified ] ) ) { return false ; } $ etag = $ node -> put ( $ data ) ; if ( $ modified ) { $ etag = null ; } $ this -> emit ( 'afterWriteContent' , [ $ uri , $ node ] ) ; return true ; }
This method is invoked by sub - systems updating a file .
13,661
public function createCollection ( $ uri , MkCol $ mkCol ) { list ( $ parentUri , $ newName ) = Uri \ split ( $ uri ) ; try { $ parent = $ this -> tree -> getNodeForPath ( $ parentUri ) ; } catch ( Exception \ NotFound $ e ) { throw new Exception \ Conflict ( 'Parent node does not exist' ) ; } if ( ! $ parent instanceof ICollection ) { throw new Exception \ Conflict ( 'Parent node is not a collection' ) ; } try { $ parent -> getChild ( $ newName ) ; throw new Exception \ MethodNotAllowed ( 'The resource you tried to create already exists' ) ; } catch ( Exception \ NotFound $ e ) { } if ( ! $ this -> emit ( 'beforeBind' , [ $ uri ] ) ) { return ; } if ( $ parent instanceof IExtendedCollection ) { $ parent -> createExtendedCollection ( $ newName , $ mkCol ) ; } else { if ( count ( $ mkCol -> getResourceType ( ) ) > 1 ) { throw new Exception \ InvalidResourceType ( 'The {DAV:}resourcetype you specified is not supported here.' ) ; } $ parent -> createDirectory ( $ newName ) ; } if ( $ mkCol -> getRemainingMutations ( ) ) { $ this -> emit ( 'propPatch' , [ $ uri , $ mkCol ] ) ; } $ success = $ mkCol -> commit ( ) ; if ( ! $ success ) { $ result = $ mkCol -> getResult ( ) ; $ formattedResult = [ 'href' => $ uri , ] ; foreach ( $ result as $ propertyName => $ status ) { if ( ! isset ( $ formattedResult [ $ status ] ) ) { $ formattedResult [ $ status ] = [ ] ; } $ formattedResult [ $ status ] [ $ propertyName ] = null ; } return $ formattedResult ; } $ this -> tree -> markDirty ( $ parentUri ) ; $ this -> emit ( 'afterBind' , [ $ uri ] ) ; }
Use this method to create a new collection .
13,662
public function updateProperties ( $ path , array $ properties ) { $ propPatch = new PropPatch ( $ properties ) ; $ this -> emit ( 'propPatch' , [ $ path , $ propPatch ] ) ; $ propPatch -> commit ( ) ; return $ propPatch -> getResult ( ) ; }
This method updates a resource s properties .
13,663
public function getResourceTypeForNode ( INode $ node ) { $ result = [ ] ; foreach ( $ this -> resourceTypeMapping as $ className => $ resourceType ) { if ( $ node instanceof $ className ) { $ result [ ] = $ resourceType ; } } return $ result ; }
Returns an array with resourcetypes for a node .
13,664
public function generateMultiStatus ( $ fileProperties , $ strip404s = false ) { $ w = $ this -> xml -> getWriter ( ) ; $ w -> openMemory ( ) ; $ w -> contextUri = $ this -> baseUri ; $ w -> startDocument ( ) ; $ w -> startElement ( '{DAV:}multistatus' ) ; foreach ( $ fileProperties as $ entry ) { $ href = $ entry [ 'href' ] ; unset ( $ entry [ 'href' ] ) ; if ( $ strip404s ) { unset ( $ entry [ 404 ] ) ; } $ response = new Xml \ Element \ Response ( ltrim ( $ href , '/' ) , $ entry ) ; $ w -> write ( [ 'name' => '{DAV:}response' , 'value' => $ response , ] ) ; } $ w -> endElement ( ) ; return $ w -> outputMemory ( ) ; }
Generates a WebDAV propfind response body based on a list of nodes .
13,665
public function httpGet ( RequestInterface $ request , ResponseInterface $ response ) { $ node = $ this -> server -> tree -> getNodeForPath ( $ request -> getPath ( ) ) ; if ( $ node instanceof DAV \ IFile ) { return ; } $ subRequest = clone $ request ; $ subRequest -> setMethod ( 'PROPFIND' ) ; $ this -> server -> invokeMethod ( $ subRequest , $ response ) ; return false ; }
This method intercepts GET requests to non - files and changes it into an HTTP PROPFIND request .
13,666
public function childExists ( $ name ) { try { $ this -> getChild ( $ name ) ; return true ; } catch ( DAV \ Exception \ NotFound $ e ) { return false ; } }
Returns whether or not the child node exists .
13,667
public function httpOptions ( RequestInterface $ request , ResponseInterface $ response ) { $ methods = $ this -> server -> getAllowedMethods ( $ request -> getPath ( ) ) ; $ response -> setHeader ( 'Allow' , strtoupper ( implode ( ', ' , $ methods ) ) ) ; $ features = [ '1' , '3' , 'extended-mkcol' ] ; foreach ( $ this -> server -> getPlugins ( ) as $ plugin ) { $ features = array_merge ( $ features , $ plugin -> getFeatures ( ) ) ; } $ response -> setHeader ( 'DAV' , implode ( ', ' , $ features ) ) ; $ response -> setHeader ( 'MS-Author-Via' , 'DAV' ) ; $ response -> setHeader ( 'Accept-Ranges' , 'bytes' ) ; $ response -> setHeader ( 'Content-Length' , '0' ) ; $ response -> setStatus ( 200 ) ; return false ; }
HTTP OPTIONS .
13,668
public function httpHead ( RequestInterface $ request , ResponseInterface $ response ) { $ subRequest = clone $ request ; $ subRequest -> setMethod ( 'GET' ) ; $ subRequest -> setHeader ( 'X-Sabre-Original-Method' , 'HEAD' ) ; try { $ this -> server -> invokeMethod ( $ subRequest , $ response , false ) ; } catch ( Exception \ NotImplemented $ e ) { $ response -> setStatus ( 200 ) ; $ response -> setBody ( '' ) ; $ response -> setHeader ( 'Content-Type' , 'text/plain' ) ; $ response -> setHeader ( 'X-Sabre-Real-Status' , $ e -> getHTTPCode ( ) ) ; } return false ; }
HTTP HEAD .
13,669
public function httpDelete ( RequestInterface $ request , ResponseInterface $ response ) { $ path = $ request -> getPath ( ) ; if ( ! $ this -> server -> emit ( 'beforeUnbind' , [ $ path ] ) ) { return false ; } $ this -> server -> tree -> delete ( $ path ) ; $ this -> server -> emit ( 'afterUnbind' , [ $ path ] ) ; $ response -> setStatus ( 204 ) ; $ response -> setHeader ( 'Content-Length' , '0' ) ; return false ; }
HTTP Delete .
13,670
public function httpPropFind ( RequestInterface $ request , ResponseInterface $ response ) { $ path = $ request -> getPath ( ) ; $ requestBody = $ request -> getBodyAsString ( ) ; if ( strlen ( $ requestBody ) ) { try { $ propFindXml = $ this -> server -> xml -> expect ( '{DAV:}propfind' , $ requestBody ) ; } catch ( ParseException $ e ) { throw new BadRequest ( $ e -> getMessage ( ) , 0 , $ e ) ; } } else { $ propFindXml = new Xml \ Request \ PropFind ( ) ; $ propFindXml -> allProp = true ; $ propFindXml -> properties = [ ] ; } $ depth = $ this -> server -> getHTTPDepth ( 1 ) ; if ( ! $ this -> server -> enablePropfindDepthInfinity && 0 != $ depth ) { $ depth = 1 ; } $ newProperties = $ this -> server -> getPropertiesIteratorForPath ( $ path , $ propFindXml -> properties , $ depth ) ; $ response -> setStatus ( 207 ) ; $ response -> setHeader ( 'Content-Type' , 'application/xml; charset=utf-8' ) ; $ response -> setHeader ( 'Vary' , 'Brief,Prefer' ) ; $ features = [ '1' , '3' , 'extended-mkcol' ] ; foreach ( $ this -> server -> getPlugins ( ) as $ plugin ) { $ features = array_merge ( $ features , $ plugin -> getFeatures ( ) ) ; } $ response -> setHeader ( 'DAV' , implode ( ', ' , $ features ) ) ; $ prefer = $ this -> server -> getHTTPPrefer ( ) ; $ minimal = 'minimal' === $ prefer [ 'return' ] ; $ data = $ this -> server -> generateMultiStatus ( $ newProperties , $ minimal ) ; $ response -> setBody ( $ data ) ; return false ; }
WebDAV PROPFIND .
13,671
public function httpPropPatch ( RequestInterface $ request , ResponseInterface $ response ) { $ path = $ request -> getPath ( ) ; try { $ propPatch = $ this -> server -> xml -> expect ( '{DAV:}propertyupdate' , $ request -> getBody ( ) ) ; } catch ( ParseException $ e ) { throw new BadRequest ( $ e -> getMessage ( ) , 0 , $ e ) ; } $ newProperties = $ propPatch -> properties ; $ result = $ this -> server -> updateProperties ( $ path , $ newProperties ) ; $ prefer = $ this -> server -> getHTTPPrefer ( ) ; $ response -> setHeader ( 'Vary' , 'Brief,Prefer' ) ; if ( 'minimal' === $ prefer [ 'return' ] ) { $ ok = true ; foreach ( $ result as $ prop => $ code ) { if ( ( int ) $ code > 299 ) { $ ok = false ; } } if ( $ ok ) { $ response -> setStatus ( 204 ) ; return false ; } } $ response -> setStatus ( 207 ) ; $ response -> setHeader ( 'Content-Type' , 'application/xml; charset=utf-8' ) ; $ multiStatus = [ ] ; foreach ( $ result as $ propertyName => $ code ) { if ( isset ( $ multiStatus [ $ code ] ) ) { $ multiStatus [ $ code ] [ $ propertyName ] = null ; } else { $ multiStatus [ $ code ] = [ $ propertyName => null ] ; } } $ multiStatus [ 'href' ] = $ path ; $ response -> setBody ( $ this -> server -> generateMultiStatus ( [ $ multiStatus ] ) ) ; return false ; }
WebDAV PROPPATCH .
13,672
public function httpPut ( RequestInterface $ request , ResponseInterface $ response ) { $ body = $ request -> getBodyAsStream ( ) ; $ path = $ request -> getPath ( ) ; if ( $ request -> getHeader ( 'Content-Range' ) ) { throw new Exception \ BadRequest ( 'Content-Range on PUT requests are forbidden.' ) ; } if ( ( $ expected = $ request -> getHeader ( 'X-Expected-Entity-Length' ) ) && $ expected > 0 ) { $ firstByte = fread ( $ body , 1 ) ; if ( 1 !== strlen ( $ firstByte ) ) { throw new Exception \ Forbidden ( 'This server is not compatible with OS/X finder. Consider using a different WebDAV client or webserver.' ) ; } $ newBody = fopen ( 'php://temp' , 'r+' ) ; fwrite ( $ newBody , $ firstByte ) ; stream_copy_to_stream ( $ body , $ newBody ) ; rewind ( $ newBody ) ; $ body = $ newBody ; } if ( $ this -> server -> tree -> nodeExists ( $ path ) ) { $ node = $ this -> server -> tree -> getNodeForPath ( $ path ) ; if ( ! ( $ node instanceof IFile ) ) { throw new Exception \ Conflict ( 'PUT is not allowed on non-files.' ) ; } if ( ! $ this -> server -> updateFile ( $ path , $ body , $ etag ) ) { return false ; } $ response -> setHeader ( 'Content-Length' , '0' ) ; if ( $ etag ) { $ response -> setHeader ( 'ETag' , $ etag ) ; } $ response -> setStatus ( 204 ) ; } else { $ etag = null ; if ( ! $ this -> server -> createFile ( $ path , $ body , $ etag ) ) { return false ; } $ response -> setHeader ( 'Content-Length' , '0' ) ; if ( $ etag ) { $ response -> setHeader ( 'ETag' , $ etag ) ; } $ response -> setStatus ( 201 ) ; } return false ; }
HTTP PUT method .
13,673
public function httpMkcol ( RequestInterface $ request , ResponseInterface $ response ) { $ requestBody = $ request -> getBodyAsString ( ) ; $ path = $ request -> getPath ( ) ; if ( $ requestBody ) { $ contentType = $ request -> getHeader ( 'Content-Type' ) ; if ( null === $ contentType || ( 0 !== strpos ( $ contentType , 'application/xml' ) && 0 !== strpos ( $ contentType , 'text/xml' ) ) ) { throw new Exception \ UnsupportedMediaType ( 'The request body for the MKCOL request must have an xml Content-Type' ) ; } try { $ mkcol = $ this -> server -> xml -> expect ( '{DAV:}mkcol' , $ requestBody ) ; } catch ( \ Sabre \ Xml \ ParseException $ e ) { throw new Exception \ BadRequest ( $ e -> getMessage ( ) , 0 , $ e ) ; } $ properties = $ mkcol -> getProperties ( ) ; if ( ! isset ( $ properties [ '{DAV:}resourcetype' ] ) ) { throw new Exception \ BadRequest ( 'The mkcol request must include a {DAV:}resourcetype property' ) ; } $ resourceType = $ properties [ '{DAV:}resourcetype' ] -> getValue ( ) ; unset ( $ properties [ '{DAV:}resourcetype' ] ) ; } else { $ properties = [ ] ; $ resourceType = [ '{DAV:}collection' ] ; } $ mkcol = new MkCol ( $ resourceType , $ properties ) ; $ result = $ this -> server -> createCollection ( $ path , $ mkcol ) ; if ( is_array ( $ result ) ) { $ response -> setStatus ( 207 ) ; $ response -> setHeader ( 'Content-Type' , 'application/xml; charset=utf-8' ) ; $ response -> setBody ( $ this -> server -> generateMultiStatus ( [ $ result ] ) ) ; } else { $ response -> setHeader ( 'Content-Length' , '0' ) ; $ response -> setStatus ( 201 ) ; } return false ; }
WebDAV MKCOL .
13,674
public function httpMove ( RequestInterface $ request , ResponseInterface $ response ) { $ path = $ request -> getPath ( ) ; $ moveInfo = $ this -> server -> getCopyAndMoveInfo ( $ request ) ; if ( $ moveInfo [ 'destinationExists' ] ) { if ( ! $ this -> server -> emit ( 'beforeUnbind' , [ $ moveInfo [ 'destination' ] ] ) ) { return false ; } } if ( ! $ this -> server -> emit ( 'beforeUnbind' , [ $ path ] ) ) { return false ; } if ( ! $ this -> server -> emit ( 'beforeBind' , [ $ moveInfo [ 'destination' ] ] ) ) { return false ; } if ( ! $ this -> server -> emit ( 'beforeMove' , [ $ path , $ moveInfo [ 'destination' ] ] ) ) { return false ; } if ( $ moveInfo [ 'destinationExists' ] ) { $ this -> server -> tree -> delete ( $ moveInfo [ 'destination' ] ) ; $ this -> server -> emit ( 'afterUnbind' , [ $ moveInfo [ 'destination' ] ] ) ; } $ this -> server -> tree -> move ( $ path , $ moveInfo [ 'destination' ] ) ; $ this -> server -> emit ( 'afterMove' , [ $ path , $ moveInfo [ 'destination' ] ] ) ; $ this -> server -> emit ( 'afterUnbind' , [ $ path ] ) ; $ this -> server -> emit ( 'afterBind' , [ $ moveInfo [ 'destination' ] ] ) ; $ response -> setHeader ( 'Content-Length' , '0' ) ; $ response -> setStatus ( $ moveInfo [ 'destinationExists' ] ? 204 : 201 ) ; return false ; }
WebDAV HTTP MOVE method .
13,675
public function httpCopy ( RequestInterface $ request , ResponseInterface $ response ) { $ path = $ request -> getPath ( ) ; $ copyInfo = $ this -> server -> getCopyAndMoveInfo ( $ request ) ; if ( ! $ this -> server -> emit ( 'beforeBind' , [ $ copyInfo [ 'destination' ] ] ) ) { return false ; } if ( $ copyInfo [ 'destinationExists' ] ) { if ( ! $ this -> server -> emit ( 'beforeUnbind' , [ $ copyInfo [ 'destination' ] ] ) ) { return false ; } $ this -> server -> tree -> delete ( $ copyInfo [ 'destination' ] ) ; } $ this -> server -> tree -> copy ( $ path , $ copyInfo [ 'destination' ] ) ; $ this -> server -> emit ( 'afterBind' , [ $ copyInfo [ 'destination' ] ] ) ; $ response -> setHeader ( 'Content-Length' , '0' ) ; $ response -> setStatus ( $ copyInfo [ 'destinationExists' ] ? 204 : 201 ) ; return false ; }
WebDAV HTTP COPY method .
13,676
public function httpReport ( RequestInterface $ request , ResponseInterface $ response ) { $ path = $ request -> getPath ( ) ; $ result = $ this -> server -> xml -> parse ( $ request -> getBody ( ) , $ request -> getUrl ( ) , $ rootElementName ) ; if ( $ this -> server -> emit ( 'report' , [ $ rootElementName , $ result , $ path ] ) ) { throw new Exception \ ReportNotSupported ( ) ; } return false ; }
HTTP REPORT method implementation .
13,677
public function propFindNode ( PropFind $ propFind , INode $ node ) { if ( $ node instanceof IProperties && $ propertyNames = $ propFind -> get404Properties ( ) ) { $ nodeProperties = $ node -> getProperties ( $ propertyNames ) ; foreach ( $ nodeProperties as $ propertyName => $ propertyValue ) { $ propFind -> set ( $ propertyName , $ propertyValue , 200 ) ; } } }
Fetches properties for a node .
13,678
public function exception ( $ e ) { $ logLevel = \ Psr \ Log \ LogLevel :: CRITICAL ; if ( $ e instanceof \ Sabre \ DAV \ Exception ) { $ code = $ e -> getHTTPCode ( ) ; if ( $ code >= 400 && $ code < 500 ) { $ logLevel = \ Psr \ Log \ LogLevel :: INFO ; } else { $ logLevel = \ Psr \ Log \ LogLevel :: ERROR ; } } $ this -> server -> getLogger ( ) -> log ( $ logLevel , 'Uncaught exception' , [ 'exception' => $ e , ] ) ; }
Listens for exception events and automatically logs them .
13,679
public function addReport ( $ report ) { $ report = ( array ) $ report ; foreach ( $ report as $ r ) { if ( ! preg_match ( '/^{([^}]*)}(.*)$/' , $ r ) ) { throw new DAV \ Exception ( 'Reportname must be in clark-notation' ) ; } $ this -> reports [ ] = $ r ; } }
Adds a report to this property .
13,680
public function getAddressBooksForUser ( $ principalUri ) { $ stmt = $ this -> pdo -> prepare ( 'SELECT id, uri, displayname, principaluri, description, synctoken FROM ' . $ this -> addressBooksTableName . ' WHERE principaluri = ?' ) ; $ stmt -> execute ( [ $ principalUri ] ) ; $ addressBooks = [ ] ; foreach ( $ stmt -> fetchAll ( ) as $ row ) { $ addressBooks [ ] = [ 'id' => $ row [ 'id' ] , 'uri' => $ row [ 'uri' ] , 'principaluri' => $ row [ 'principaluri' ] , '{DAV:}displayname' => $ row [ 'displayname' ] , '{' . CardDAV \ Plugin :: NS_CARDDAV . '}addressbook-description' => $ row [ 'description' ] , '{http://calendarserver.org/ns/}getctag' => $ row [ 'synctoken' ] , '{http://sabredav.org/ns}sync-token' => $ row [ 'synctoken' ] ? $ row [ 'synctoken' ] : '0' , ] ; } return $ addressBooks ; }
Returns the list of addressbooks for a specific user .
13,681
public function updateAddressBook ( $ addressBookId , \ Sabre \ DAV \ PropPatch $ propPatch ) { $ supportedProperties = [ '{DAV:}displayname' , '{' . CardDAV \ Plugin :: NS_CARDDAV . '}addressbook-description' , ] ; $ propPatch -> handle ( $ supportedProperties , function ( $ mutations ) use ( $ addressBookId ) { $ updates = [ ] ; foreach ( $ mutations as $ property => $ newValue ) { switch ( $ property ) { case '{DAV:}displayname' : $ updates [ 'displayname' ] = $ newValue ; break ; case '{' . CardDAV \ Plugin :: NS_CARDDAV . '}addressbook-description' : $ updates [ 'description' ] = $ newValue ; break ; } } $ query = 'UPDATE ' . $ this -> addressBooksTableName . ' SET ' ; $ first = true ; foreach ( $ updates as $ key => $ value ) { if ( $ first ) { $ first = false ; } else { $ query .= ', ' ; } $ query .= ' ' . $ key . ' = :' . $ key . ' ' ; } $ query .= ' WHERE id = :addressbookid' ; $ stmt = $ this -> pdo -> prepare ( $ query ) ; $ updates [ 'addressbookid' ] = $ addressBookId ; $ stmt -> execute ( $ updates ) ; $ this -> addChange ( $ addressBookId , '' , 2 ) ; return true ; } ) ; }
Updates properties for an address book .
13,682
public function deleteAddressBook ( $ addressBookId ) { $ stmt = $ this -> pdo -> prepare ( 'DELETE FROM ' . $ this -> cardsTableName . ' WHERE addressbookid = ?' ) ; $ stmt -> execute ( [ $ addressBookId ] ) ; $ stmt = $ this -> pdo -> prepare ( 'DELETE FROM ' . $ this -> addressBooksTableName . ' WHERE id = ?' ) ; $ stmt -> execute ( [ $ addressBookId ] ) ; $ stmt = $ this -> pdo -> prepare ( 'DELETE FROM ' . $ this -> addressBookChangesTableName . ' WHERE addressbookid = ?' ) ; $ stmt -> execute ( [ $ addressBookId ] ) ; }
Deletes an entire addressbook and all its contents .
13,683
public function getCards ( $ addressbookId ) { $ stmt = $ this -> pdo -> prepare ( 'SELECT id, uri, lastmodified, etag, size FROM ' . $ this -> cardsTableName . ' WHERE addressbookid = ?' ) ; $ stmt -> execute ( [ $ addressbookId ] ) ; $ result = [ ] ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ row [ 'etag' ] = '"' . $ row [ 'etag' ] . '"' ; $ row [ 'lastmodified' ] = ( int ) $ row [ 'lastmodified' ] ; $ result [ ] = $ row ; } return $ result ; }
Returns all cards for a specific addressbook id .
13,684
public function getCard ( $ addressBookId , $ cardUri ) { $ stmt = $ this -> pdo -> prepare ( 'SELECT id, carddata, uri, lastmodified, etag, size FROM ' . $ this -> cardsTableName . ' WHERE addressbookid = ? AND uri = ? LIMIT 1' ) ; $ stmt -> execute ( [ $ addressBookId , $ cardUri ] ) ; $ result = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ; if ( ! $ result ) { return false ; } $ result [ 'etag' ] = '"' . $ result [ 'etag' ] . '"' ; $ result [ 'lastmodified' ] = ( int ) $ result [ 'lastmodified' ] ; return $ result ; }
Returns a specific card .
13,685
public function createCard ( $ addressBookId , $ cardUri , $ cardData ) { $ stmt = $ this -> pdo -> prepare ( 'INSERT INTO ' . $ this -> cardsTableName . ' (carddata, uri, lastmodified, addressbookid, size, etag) VALUES (?, ?, ?, ?, ?, ?)' ) ; $ etag = md5 ( $ cardData ) ; $ stmt -> execute ( [ $ cardData , $ cardUri , time ( ) , $ addressBookId , strlen ( $ cardData ) , $ etag , ] ) ; $ this -> addChange ( $ addressBookId , $ cardUri , 1 ) ; return '"' . $ etag . '"' ; }
Creates a new card .
13,686
public function deleteCard ( $ addressBookId , $ cardUri ) { $ stmt = $ this -> pdo -> prepare ( 'DELETE FROM ' . $ this -> cardsTableName . ' WHERE addressbookid = ? AND uri = ?' ) ; $ stmt -> execute ( [ $ addressBookId , $ cardUri ] ) ; $ this -> addChange ( $ addressBookId , $ cardUri , 3 ) ; return 1 === $ stmt -> rowCount ( ) ; }
Deletes a card .
13,687
public function getChangesForAddressBook ( $ addressBookId , $ syncToken , $ syncLevel , $ limit = null ) { $ stmt = $ this -> pdo -> prepare ( 'SELECT synctoken FROM ' . $ this -> addressBooksTableName . ' WHERE id = ?' ) ; $ stmt -> execute ( [ $ addressBookId ] ) ; $ currentToken = $ stmt -> fetchColumn ( 0 ) ; if ( is_null ( $ currentToken ) ) { return null ; } $ result = [ 'syncToken' => $ currentToken , 'added' => [ ] , 'modified' => [ ] , 'deleted' => [ ] , ] ; if ( $ syncToken ) { $ query = 'SELECT uri, operation FROM ' . $ this -> addressBookChangesTableName . ' WHERE synctoken >= ? AND synctoken < ? AND addressbookid = ? ORDER BY synctoken' ; if ( $ limit > 0 ) { $ query .= ' LIMIT ' . ( int ) $ limit ; } $ stmt = $ this -> pdo -> prepare ( $ query ) ; $ stmt -> execute ( [ $ syncToken , $ currentToken , $ addressBookId ] ) ; $ changes = [ ] ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ changes [ $ row [ 'uri' ] ] = $ row [ 'operation' ] ; } foreach ( $ changes as $ uri => $ operation ) { switch ( $ operation ) { case 1 : $ result [ 'added' ] [ ] = $ uri ; break ; case 2 : $ result [ 'modified' ] [ ] = $ uri ; break ; case 3 : $ result [ 'deleted' ] [ ] = $ uri ; break ; } } } else { $ query = 'SELECT uri FROM ' . $ this -> cardsTableName . ' WHERE addressbookid = ?' ; $ stmt = $ this -> pdo -> prepare ( $ query ) ; $ stmt -> execute ( [ $ addressBookId ] ) ; $ result [ 'added' ] = $ stmt -> fetchAll ( \ PDO :: FETCH_COLUMN ) ; } return $ result ; }
The getChanges method returns all the changes that have happened since the specified syncToken in the specified address book .
13,688
protected function addChange ( $ addressBookId , $ objectUri , $ operation ) { $ stmt = $ this -> pdo -> prepare ( 'INSERT INTO ' . $ this -> addressBookChangesTableName . ' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM ' . $ this -> addressBooksTableName . ' WHERE id = ?' ) ; $ stmt -> execute ( [ $ objectUri , $ addressBookId , $ operation , $ addressBookId , ] ) ; $ stmt = $ this -> pdo -> prepare ( 'UPDATE ' . $ this -> addressBooksTableName . ' SET synctoken = synctoken + 1 WHERE id = ?' ) ; $ stmt -> execute ( [ $ addressBookId , ] ) ; }
Adds a change record to the addressbookchanges table .
13,689
public function updateCalendarObject ( $ calendarId , $ objectUri , $ calendarData ) { $ stmt = $ this -> pdo -> prepare ( 'UPDATE simple_calendarobjects SET calendardata = ? WHERE calendarid = ? AND uri = ?' ) ; $ stmt -> execute ( [ $ calendarData , $ calendarId , $ objectUri ] ) ; return '"' . md5 ( $ calendarData ) . '"' ; }
Updates an existing calendarobject based on it s uri .
13,690
public function propFind ( DAV \ PropFind $ propFind , DAV \ INode $ node ) { $ propFind -> handle ( '{DAV:}supportedlock' , function ( ) { return new DAV \ Xml \ Property \ SupportedLock ( ) ; } ) ; $ propFind -> handle ( '{DAV:}lockdiscovery' , function ( ) use ( $ propFind ) { return new DAV \ Xml \ Property \ LockDiscovery ( $ this -> getLocks ( $ propFind -> getPath ( ) ) ) ; } ) ; }
This method is called after most properties have been found it allows us to add in any Lock - related properties .
13,691
public function httpLock ( RequestInterface $ request , ResponseInterface $ response ) { $ uri = $ request -> getPath ( ) ; $ existingLocks = $ this -> getLocks ( $ uri ) ; if ( $ body = $ request -> getBodyAsString ( ) ) { $ existingLock = null ; foreach ( $ existingLocks as $ existingLock ) { if ( LockInfo :: EXCLUSIVE === $ existingLock -> scope ) { throw new DAV \ Exception \ ConflictingLock ( $ existingLock ) ; } } $ lockInfo = $ this -> parseLockRequest ( $ body ) ; $ lockInfo -> depth = $ this -> server -> getHTTPDepth ( ) ; $ lockInfo -> uri = $ uri ; if ( $ existingLock && LockInfo :: SHARED != $ lockInfo -> scope ) { throw new DAV \ Exception \ ConflictingLock ( $ existingLock ) ; } } else { $ existingLocks = $ this -> getLocks ( $ uri ) ; $ conditions = $ this -> server -> getIfConditions ( $ request ) ; $ found = null ; foreach ( $ existingLocks as $ existingLock ) { foreach ( $ conditions as $ condition ) { foreach ( $ condition [ 'tokens' ] as $ token ) { if ( $ token [ 'token' ] === 'opaquelocktoken:' . $ existingLock -> token ) { $ found = $ existingLock ; break 3 ; } } } } if ( is_null ( $ found ) ) { if ( $ existingLocks ) { throw new DAV \ Exception \ Locked ( reset ( $ existingLocks ) ) ; } else { throw new DAV \ Exception \ BadRequest ( 'An xml body is required for lock requests' ) ; } } $ lockInfo = $ found ; if ( $ uri != $ lockInfo -> uri ) { $ uri = $ lockInfo -> uri ; } } if ( $ timeout = $ this -> getTimeoutHeader ( ) ) { $ lockInfo -> timeout = $ timeout ; } $ newFile = false ; try { $ this -> server -> tree -> getNodeForPath ( $ uri ) ; } catch ( DAV \ Exception \ NotFound $ e ) { $ this -> server -> createFile ( $ uri , fopen ( 'php://memory' , 'r' ) ) ; $ newFile = true ; } $ this -> lockNode ( $ uri , $ lockInfo ) ; $ response -> setHeader ( 'Content-Type' , 'application/xml; charset=utf-8' ) ; $ response -> setHeader ( 'Lock-Token' , '<opaquelocktoken:' . $ lockInfo -> token . '>' ) ; $ response -> setStatus ( $ newFile ? 201 : 200 ) ; $ response -> setBody ( $ this -> generateLockResponse ( $ lockInfo ) ) ; return false ; }
Locks an uri .
13,692
public function getTimeoutHeader ( ) { $ header = $ this -> server -> httpRequest -> getHeader ( 'Timeout' ) ; if ( $ header ) { if ( 0 === stripos ( $ header , 'second-' ) ) { $ header = ( int ) ( substr ( $ header , 7 ) ) ; } elseif ( 0 === stripos ( $ header , 'infinite' ) ) { $ header = LockInfo :: TIMEOUT_INFINITE ; } else { throw new DAV \ Exception \ BadRequest ( 'Invalid HTTP timeout header' ) ; } } else { $ header = 0 ; } return $ header ; }
Returns the contents of the HTTP Timeout header .
13,693
protected function generateLockResponse ( LockInfo $ lockInfo ) { return $ this -> server -> xml -> write ( '{DAV:}prop' , [ '{DAV:}lockdiscovery' => new DAV \ Xml \ Property \ LockDiscovery ( [ $ lockInfo ] ) , ] ) ; }
Generates the response for successful LOCK requests .
13,694
protected function parseLockRequest ( $ body ) { $ result = $ this -> server -> xml -> expect ( '{DAV:}lockinfo' , $ body ) ; $ lockInfo = new LockInfo ( ) ; $ lockInfo -> owner = $ result -> owner ; $ lockInfo -> token = DAV \ UUIDUtil :: getUUID ( ) ; $ lockInfo -> scope = $ result -> scope ; return $ lockInfo ; }
Parses a webdav lock xml body and returns a new Sabre \ DAV \ Locks \ LockInfo object .
13,695
public function getETag ( ) { return '"' . sha1 ( fileinode ( $ this -> path ) . filesize ( $ this -> path ) . filemtime ( $ this -> path ) ) . '"' ; }
Returns the ETag for a file .
13,696
public function put ( $ calendarData ) { if ( is_resource ( $ calendarData ) ) { $ calendarData = stream_get_contents ( $ calendarData ) ; } $ etag = $ this -> caldavBackend -> updateCalendarObject ( $ this -> calendarInfo [ 'id' ] , $ this -> objectData [ 'uri' ] , $ calendarData ) ; $ this -> objectData [ 'calendardata' ] = $ calendarData ; $ this -> objectData [ 'etag' ] = $ etag ; return $ etag ; }
Updates the ICalendar - formatted object .
13,697
public function getContentType ( ) { $ mime = 'text/calendar; charset=utf-8' ; if ( isset ( $ this -> objectData [ 'component' ] ) && $ this -> objectData [ 'component' ] ) { $ mime .= '; component=' . $ this -> objectData [ 'component' ] ; } return $ mime ; }
Returns the mime content - type .
13,698
public function getChildren ( ) { $ children = [ ] ; $ notifications = $ this -> caldavBackend -> getNotificationsForPrincipal ( $ this -> principalUri ) ; foreach ( $ notifications as $ notification ) { $ children [ ] = new Node ( $ this -> caldavBackend , $ this -> principalUri , $ notification ) ; } return $ children ; }
Returns all notifications for a principal .
13,699
public static function textMatch ( $ haystack , $ needle , $ collation , $ matchType = 'contains' ) { switch ( $ collation ) { case 'i;ascii-casemap' : $ haystack = str_replace ( range ( 'a' , 'z' ) , range ( 'A' , 'Z' ) , $ haystack ) ; $ needle = str_replace ( range ( 'a' , 'z' ) , range ( 'A' , 'Z' ) , $ needle ) ; break ; case 'i;octet' : break ; case 'i;unicode-casemap' : $ haystack = mb_strtoupper ( $ haystack , 'UTF-8' ) ; $ needle = mb_strtoupper ( $ needle , 'UTF-8' ) ; break ; default : throw new Exception \ BadRequest ( 'Collation type: ' . $ collation . ' is not supported' ) ; } switch ( $ matchType ) { case 'contains' : return false !== strpos ( $ haystack , $ needle ) ; case 'equals' : return $ haystack === $ needle ; case 'starts-with' : return 0 === strpos ( $ haystack , $ needle ) ; case 'ends-with' : return strrpos ( $ haystack , $ needle ) === strlen ( $ haystack ) - strlen ( $ needle ) ; default : throw new Exception \ BadRequest ( 'Match-type: ' . $ matchType . ' is not supported' ) ; } }
Checks if a needle occurs in a haystack ; ) .