idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
13,100
public function createParser ( $ kind = null ) { if ( $ this -> hasKindsSupport ( ) ) { $ originalFactory = new OriginalParserFactory ( ) ; $ kind = $ kind ? : $ this -> getDefaultKind ( ) ; if ( ! \ in_array ( $ kind , static :: getPossibleKinds ( ) ) ) { throw new \ InvalidArgumentException ( 'Unknown parser kind' ) ; } $ parser = $ originalFactory -> create ( \ constant ( 'PhpParser\ParserFactory::' . $ kind ) ) ; } else { if ( $ kind !== null ) { throw new \ InvalidArgumentException ( 'Install PHP Parser v2.x to specify parser kind' ) ; } $ parser = new Parser ( new Lexer ( ) ) ; } return $ parser ; }
New parser instance with given kind .
13,101
protected function shouldLog ( $ request ) { foreach ( config ( 'LaravelLogger.loggerMiddlewareExcept' , [ ] ) as $ except ) { if ( $ except !== '/' ) { $ except = trim ( $ except , '/' ) ; } if ( $ request -> is ( $ except ) ) { return false ; } } return true ; }
Determine if the request has a URI that should log .
13,102
private function registerEventListeners ( ) { $ listeners = $ this -> getListeners ( ) ; foreach ( $ listeners as $ listenerKey => $ listenerValues ) { foreach ( $ listenerValues as $ listenerValue ) { \ Event :: listen ( $ listenerKey , $ listenerValue ) ; } } }
Register the list of listeners and events .
13,103
private function publishFiles ( ) { $ publishTag = 'LaravelLogger' ; $ this -> publishes ( [ __DIR__ . '/config/laravel-logger.php' => base_path ( 'config/laravel-logger.php' ) , ] , $ publishTag ) ; $ this -> publishes ( [ __DIR__ . '/resources/views' => base_path ( 'resources/views/vendor/' . $ publishTag ) , ] , $ publishTag ) ; $ this -> publishes ( [ __DIR__ . '/resources/lang' => base_path ( 'resources/lang/vendor/' . $ publishTag ) , ] , $ publishTag ) ; }
Publish files for Laravel Logger .
13,104
private function mapAdditionalDetails ( $ collectionItems ) { $ collectionItems -> map ( function ( $ collectionItem ) { $ eventTime = Carbon :: parse ( $ collectionItem -> updated_at ) ; $ collectionItem [ 'timePassed' ] = $ eventTime -> diffForHumans ( ) ; $ collectionItem [ 'userAgentDetails' ] = UserAgentDetails :: details ( $ collectionItem -> useragent ) ; $ collectionItem [ 'langDetails' ] = UserAgentDetails :: localeLang ( $ collectionItem -> locale ) ; $ collectionItem [ 'userDetails' ] = config ( 'LaravelLogger.defaultUserModel' ) :: find ( $ collectionItem -> userId ) ; return $ collectionItem ; } ) ; return $ collectionItems ; }
Add additional details to a collections .
13,105
public function showAccessLogEntry ( Request $ request , $ id ) { $ activity = Activity :: findOrFail ( $ id ) ; $ userDetails = config ( 'LaravelLogger.defaultUserModel' ) :: find ( $ activity -> userId ) ; $ userAgentDetails = UserAgentDetails :: details ( $ activity -> useragent ) ; $ ipAddressDetails = IpAddressDetails :: checkIP ( $ activity -> ipAddress ) ; $ langDetails = UserAgentDetails :: localeLang ( $ activity -> locale ) ; $ eventTime = Carbon :: parse ( $ activity -> created_at ) ; $ timePassed = $ eventTime -> diffForHumans ( ) ; if ( config ( 'LaravelLogger.loggerPaginationEnabled' ) ) { $ userActivities = Activity :: where ( 'userId' , $ activity -> userId ) -> orderBy ( 'created_at' , 'desc' ) -> paginate ( config ( 'LaravelLogger.loggerPaginationPerPage' ) ) ; $ totalUserActivities = $ userActivities -> total ( ) ; } else { $ userActivities = Activity :: where ( 'userId' , $ activity -> userId ) -> orderBy ( 'created_at' , 'desc' ) -> get ( ) ; $ totalUserActivities = $ userActivities -> count ( ) ; } self :: mapAdditionalDetails ( $ userActivities ) ; $ data = [ 'activity' => $ activity , 'userDetails' => $ userDetails , 'ipAddressDetails' => $ ipAddressDetails , 'timePassed' => $ timePassed , 'userAgentDetails' => $ userAgentDetails , 'langDetails' => $ langDetails , 'userActivities' => $ userActivities , 'totalUserActivities' => $ totalUserActivities , 'isClearedEntry' => false , ] ; return View ( 'LaravelLogger::logger.activity-log-item' , $ data ) ; }
Show an individual activity log entry .
13,106
public function showClearedActivityLog ( ) { if ( config ( 'LaravelLogger.loggerPaginationEnabled' ) ) { $ activities = Activity :: onlyTrashed ( ) -> orderBy ( 'created_at' , 'desc' ) -> paginate ( config ( 'LaravelLogger.loggerPaginationPerPage' ) ) ; $ totalActivities = $ activities -> total ( ) ; } else { $ activities = Activity :: onlyTrashed ( ) -> orderBy ( 'created_at' , 'desc' ) -> get ( ) ; $ totalActivities = $ activities -> count ( ) ; } self :: mapAdditionalDetails ( $ activities ) ; $ data = [ 'activities' => $ activities , 'totalActivities' => $ totalActivities , ] ; return View ( 'LaravelLogger::logger.activity-log-cleared' , $ data ) ; }
Show the cleared activity log - softdeleted records .
13,107
public function destroyActivityLog ( Request $ request ) { $ activities = Activity :: onlyTrashed ( ) -> get ( ) ; foreach ( $ activities as $ activity ) { $ activity -> forceDelete ( ) ; } return redirect ( 'activity' ) -> with ( 'success' , trans ( 'LaravelLogger::laravel-logger.messages.logDestroyedSuccessfuly' ) ) ; }
Destroy the specified resource from storage .
13,108
public function restoreClearedActivityLog ( Request $ request ) { $ activities = Activity :: onlyTrashed ( ) -> get ( ) ; foreach ( $ activities as $ activity ) { $ activity -> restore ( ) ; } return redirect ( 'activity' ) -> with ( 'success' , trans ( 'LaravelLogger::laravel-logger.messages.logRestoredSuccessfuly' ) ) ; }
Restore the specified resource from soft deleted storage .
13,109
public static function details ( $ ua ) { $ ua = is_null ( $ ua ) ? $ _SERVER [ 'HTTP_USER_AGENT' ] : $ ua ; $ platforms = 'Windows|iPad|iPhone|Macintosh|Android|BlackBerry|Unix|Linux' ; $ browsers = 'Firefox|Chrome|Opera' ; $ browsers_v = 'Safari|Mobile' ; $ engines = 'Gecko|Trident|Webkit|Presto' ; $ regex_pat = "/((Mozilla)\/[\d\.]+|(Opera)\/[\d\.]+)\s\(.*?((MSIE)\s([\d\.]+).*?(Windows)|({$platforms})).*?\s.*?({$engines})[\/\s]+[\d\.]+(\;\srv\:([\d\.]+)|.*?).*?(Version[\/\s]([\d\.]+)(.*?({$browsers_v})|$)|(({$browsers})[\/\s]+([\d\.]+))|$).*/i" ; $ replace_pat = '$7$8|$2$3|$9|${17}${15}$5$3|${18}${13}$6${11}' ; $ ua_array = explode ( '|' , preg_replace ( $ regex_pat , $ replace_pat , $ ua , PREG_PATTERN_ORDER ) ) ; if ( count ( $ ua_array ) > 1 ) { $ return [ 'platform' ] = $ ua_array [ 0 ] ; $ return [ 'type' ] = $ ua_array [ 1 ] ; $ return [ 'renderer' ] = $ ua_array [ 2 ] ; $ return [ 'browser' ] = $ ua_array [ 3 ] ; if ( preg_match ( "/^[\d]+\.[\d]+(?:\.[\d]{0,2}$)?/" , $ ua_array [ 4 ] , $ matches ) ) { $ return [ 'version' ] = $ matches [ 0 ] ; } else { $ return [ 'version' ] = $ ua_array [ 4 ] ; } } else { return false ; } switch ( strtolower ( $ return [ 'browser' ] ) ) { case 'msie' : case 'trident' : $ return [ 'browser' ] = 'Internet Explorer' ; break ; case '' : if ( strtolower ( $ return [ 'renderer' ] ) == 'trident' ) { $ return [ 'browser' ] = 'Internet Explorer' ; } break ; } switch ( strtolower ( $ return [ 'platform' ] ) ) { case 'android' : case 'blackberry' : if ( $ return [ 'browser' ] == 'Safari' || $ return [ 'browser' ] == 'Mobile' || $ return [ 'browser' ] == '' ) { $ return [ 'browser' ] = "{$return['platform']} mobile" ; } break ; } return $ return ; }
Get the user s agents details .
13,110
public static function activity ( $ description = null ) { $ userType = trans ( 'LaravelLogger::laravel-logger.userTypes.guest' ) ; $ userId = null ; if ( \ Auth :: check ( ) ) { $ userType = trans ( 'LaravelLogger::laravel-logger.userTypes.registered' ) ; $ userId = \ Request :: user ( ) -> id ; } if ( Crawler :: isCrawler ( ) ) { $ userType = trans ( 'LaravelLogger::laravel-logger.userTypes.crawler' ) ; $ description = $ userType . ' ' . trans ( 'LaravelLogger::laravel-logger.verbTypes.crawled' ) . ' ' . \ Request :: fullUrl ( ) ; } if ( ! $ description ) { switch ( strtolower ( \ Request :: method ( ) ) ) { case 'post' : $ verb = trans ( 'LaravelLogger::laravel-logger.verbTypes.created' ) ; break ; case 'patch' : case 'put' : $ verb = trans ( 'LaravelLogger::laravel-logger.verbTypes.edited' ) ; break ; case 'delete' : $ verb = trans ( 'LaravelLogger::laravel-logger.verbTypes.deleted' ) ; break ; case 'get' : default : $ verb = trans ( 'LaravelLogger::laravel-logger.verbTypes.viewed' ) ; break ; } $ description = $ verb . ' ' . \ Request :: path ( ) ; } $ data = [ 'description' => $ description , 'userType' => $ userType , 'userId' => $ userId , 'route' => \ Request :: fullUrl ( ) , 'ipAddress' => \ Request :: ip ( ) , 'userAgent' => \ Request :: header ( 'user-agent' ) , 'locale' => \ Request :: header ( 'accept-language' ) , 'referer' => \ Request :: header ( 'referer' ) , 'methodType' => \ Request :: method ( ) , ] ; $ validator = Validator :: make ( $ data , Activity :: Rules ( [ ] ) ) ; if ( $ validator -> fails ( ) ) { $ errors = self :: prepareErrorMessage ( $ validator -> errors ( ) , $ data ) ; if ( config ( 'LaravelLogger.logDBActivityLogFailuresToFile' ) ) { Log :: error ( 'Failed to record activity event. Failed Validation: ' . $ errors ) ; } } else { self :: storeActivity ( $ data ) ; } }
Laravel Logger Log Activity .
13,111
private static function storeActivity ( $ data ) { Activity :: create ( [ 'description' => $ data [ 'description' ] , 'userType' => $ data [ 'userType' ] , 'userId' => $ data [ 'userId' ] , 'route' => $ data [ 'route' ] , 'ipAddress' => $ data [ 'ipAddress' ] , 'userAgent' => $ data [ 'userAgent' ] , 'locale' => $ data [ 'locale' ] , 'referer' => $ data [ 'referer' ] , 'methodType' => $ data [ 'methodType' ] , ] ) ; }
Store activity entry to database .
13,112
public function withRules ( array $ rules ) : self { $ new = clone $ this ; unset ( $ new -> rules ) ; $ new -> rules = new \ SplStack ; foreach ( $ rules as $ callable ) { $ new = $ new -> addRule ( $ callable ) ; } return $ new ; }
Set all rules in the stack .
13,113
private function shouldAuthenticate ( ServerRequestInterface $ request ) : bool { foreach ( $ this -> rules as $ callable ) { if ( false === $ callable ( $ request ) ) { return false ; } } return true ; }
Check if middleware should authenticate .
13,114
private function fetchToken ( ServerRequestInterface $ request ) : string { $ header = $ request -> getHeaderLine ( $ this -> options [ "header" ] ) ; if ( false === empty ( $ header ) ) { if ( preg_match ( $ this -> options [ "regexp" ] , $ header , $ matches ) ) { $ this -> log ( LogLevel :: DEBUG , "Using token from request header" ) ; return $ matches [ 1 ] ; } } $ cookieParams = $ request -> getCookieParams ( ) ; if ( isset ( $ cookieParams [ $ this -> options [ "cookie" ] ] ) ) { $ this -> log ( LogLevel :: DEBUG , "Using token from cookie" ) ; return $ cookieParams [ $ this -> options [ "cookie" ] ] ; } ; $ this -> log ( LogLevel :: WARNING , "Token not found" ) ; throw new RuntimeException ( "Token not found." ) ; }
Fetch the access token .
13,115
private function decodeToken ( string $ token ) : array { try { $ decoded = JWT :: decode ( $ token , $ this -> options [ "secret" ] , ( array ) $ this -> options [ "algorithm" ] ) ; return ( array ) $ decoded ; } catch ( Exception $ exception ) { $ this -> log ( LogLevel :: WARNING , $ exception -> getMessage ( ) , [ $ token ] ) ; throw $ exception ; } }
Decode the token .
13,116
private function secret ( $ secret ) : void { if ( false === is_array ( $ secret ) && false === is_string ( $ secret ) ) { throw new InvalidArgumentException ( 'Secret must be either a string or an array of "kid" => "secret" pairs' ) ; } $ this -> options [ "secret" ] = $ secret ; }
Set the secret key .
13,117
private function error ( callable $ error ) : void { if ( $ error instanceof Closure ) { $ this -> options [ "error" ] = $ error -> bindTo ( $ this ) ; } else { $ this -> options [ "error" ] = $ error ; } }
Set the error handler .
13,118
private function before ( callable $ before ) : void { if ( $ before instanceof Closure ) { $ this -> options [ "before" ] = $ before -> bindTo ( $ this ) ; } else { $ this -> options [ "before" ] = $ before ; } }
Set the before handler .
13,119
private function after ( callable $ after ) : void { if ( $ after instanceof Closure ) { $ this -> options [ "after" ] = $ after -> bindTo ( $ this ) ; } else { $ this -> options [ "after" ] = $ after ; } }
Set the after handler .
13,120
public static function restore ( $ clear = true ) { if ( $ clear ) { libxml_clear_errors ( ) ; } libxml_use_internal_errors ( self :: $ internalErrors ) ; libxml_disable_entity_loader ( self :: $ disableEntities ) ; }
Restore error reporting .
13,121
protected function parseStyleAttribute ( ) { if ( ! $ this -> element -> hasAttribute ( 'style' ) ) { if ( $ this -> styleString !== '' ) { $ this -> styleString = '' ; $ this -> properties = [ ] ; } return ; } if ( $ this -> element -> getAttribute ( 'style' ) === $ this -> styleString ) { return ; } $ this -> styleString = $ this -> element -> getAttribute ( 'style' ) ; $ styleString = trim ( $ this -> styleString , ' ;' ) ; if ( $ styleString === '' ) { $ this -> properties = [ ] ; return ; } $ properties = explode ( ';' , $ styleString ) ; foreach ( $ properties as $ property ) { list ( $ name , $ value ) = explode ( ':' , $ property ) ; $ name = trim ( $ name ) ; $ value = trim ( $ value ) ; $ this -> properties [ $ name ] = $ value ; } }
Parses style attribute of the element .
13,122
protected function updateStyleAttribute ( ) { $ this -> styleString = $ this -> buildStyleString ( ) ; $ this -> element -> setAttribute ( 'style' , $ this -> styleString ) ; }
Updates style attribute of the element .
13,123
public function prependChild ( $ nodes ) { if ( $ this -> node -> ownerDocument === null ) { throw new LogicException ( 'Can not prepend child to element without owner document' ) ; } $ returnArray = true ; if ( ! is_array ( $ nodes ) ) { $ nodes = [ $ nodes ] ; $ returnArray = false ; } $ nodes = array_reverse ( $ nodes ) ; $ result = [ ] ; $ referenceNode = $ this -> node -> firstChild ; foreach ( $ nodes as $ node ) { $ result [ ] = $ this -> insertBefore ( $ node , $ referenceNode ) ; $ referenceNode = $ this -> node -> firstChild ; } return $ returnArray ? $ result : $ result [ 0 ] ; }
Adds a new child at the start of the children .
13,124
public function insertBefore ( $ node , $ referenceNode = null ) { if ( $ this -> node -> ownerDocument === null ) { throw new LogicException ( 'Can not insert child to element without owner document' ) ; } if ( $ node instanceof Element ) { $ node = $ node -> getNode ( ) ; } if ( ! $ node instanceof DOMNode ) { throw new InvalidArgumentException ( sprintf ( 'Argument 1 passed to %s must be an instance of %s\Element or DOMNode, %s given' , __METHOD__ , __NAMESPACE__ , ( is_object ( $ node ) ? get_class ( $ node ) : gettype ( $ node ) ) ) ) ; } if ( $ referenceNode !== null ) { if ( $ referenceNode instanceof Element ) { $ referenceNode = $ referenceNode -> getNode ( ) ; } if ( ! $ referenceNode instanceof DOMNode ) { throw new InvalidArgumentException ( sprintf ( 'Argument 2 passed to %s must be an instance of %s\Element or DOMNode, %s given' , __METHOD__ , __NAMESPACE__ , ( is_object ( $ referenceNode ) ? get_class ( $ referenceNode ) : gettype ( $ referenceNode ) ) ) ) ; } } Errors :: disable ( ) ; $ clonedNode = $ node -> cloneNode ( true ) ; $ newNode = $ this -> node -> ownerDocument -> importNode ( $ clonedNode , true ) ; $ insertedNode = $ this -> node -> insertBefore ( $ newNode , $ referenceNode ) ; Errors :: restore ( ) ; return new Element ( $ insertedNode ) ; }
Adds a new child before a reference node .
13,125
public function insertAfter ( $ node , $ referenceNode = null ) { if ( $ referenceNode === null ) { return $ this -> insertBefore ( $ node ) ; } if ( $ referenceNode instanceof Element ) { $ referenceNode = $ referenceNode -> getNode ( ) ; } if ( ! $ referenceNode instanceof DOMNode ) { throw new InvalidArgumentException ( sprintf ( 'Argument 2 passed to %s must be an instance of %s\Element or DOMNode, %s given' , __METHOD__ , __NAMESPACE__ , ( is_object ( $ referenceNode ) ? get_class ( $ referenceNode ) : gettype ( $ referenceNode ) ) ) ) ; } return $ this -> insertBefore ( $ node , $ referenceNode -> nextSibling ) ; }
Adds a new child after a reference node .
13,126
public function findInDocument ( $ expression , $ type = Query :: TYPE_CSS , $ wrapNode = true ) { $ ownerDocument = $ this -> getDocument ( ) ; if ( $ ownerDocument === null ) { throw new LogicException ( 'Can not search in context without owner document' ) ; } return $ ownerDocument -> find ( $ expression , $ type , $ wrapNode , $ this -> node ) ; }
Searches for an node in the owner document using current node as context .
13,127
public function firstInDocument ( $ expression , $ type = Query :: TYPE_CSS , $ wrapNode = true ) { $ ownerDocument = $ this -> getDocument ( ) ; if ( $ ownerDocument === null ) { throw new LogicException ( 'Can not search in context without owner document' ) ; } return $ ownerDocument -> first ( $ expression , $ type , $ wrapNode , $ this -> node ) ; }
Searches for an node in the owner document using current node as context and returns first element or null .
13,128
public function xpath ( $ expression , $ wrapNode = true ) { return $ this -> find ( $ expression , Query :: TYPE_XPATH , $ wrapNode ) ; }
Searches for an node in the DOM tree for a given XPath expression .
13,129
public function matches ( $ selector , $ strict = false ) { if ( ! is_string ( $ selector ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 1 to be string, %s given' , __METHOD__ , gettype ( $ selector ) ) ) ; } if ( ! $ this -> node instanceof DOMElement ) { return false ; } if ( $ selector === '*' ) { return true ; } if ( ! $ strict ) { $ innerHtml = $ this -> html ( ) ; $ html = "<root>$innerHtml</root>" ; $ selector = 'root > ' . trim ( $ selector ) ; $ document = new Document ( ) ; $ document -> loadHtml ( $ html , LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED ) ; return $ document -> has ( $ selector ) ; } $ segments = Query :: getSegments ( $ selector ) ; if ( ! array_key_exists ( 'tag' , $ segments ) ) { throw new RuntimeException ( sprintf ( 'Tag name must be specified in %s' , $ selector ) ) ; } if ( $ segments [ 'tag' ] !== $ this -> tag && $ segments [ 'tag' ] !== '*' ) { return false ; } $ segments [ 'id' ] = array_key_exists ( 'id' , $ segments ) ? $ segments [ 'id' ] : null ; if ( $ segments [ 'id' ] !== $ this -> getAttribute ( 'id' ) ) { return false ; } $ classes = $ this -> hasAttribute ( 'class' ) ? explode ( ' ' , trim ( $ this -> getAttribute ( 'class' ) ) ) : [ ] ; $ segments [ 'classes' ] = array_key_exists ( 'classes' , $ segments ) ? $ segments [ 'classes' ] : [ ] ; $ diff1 = array_diff ( $ segments [ 'classes' ] , $ classes ) ; $ diff2 = array_diff ( $ classes , $ segments [ 'classes' ] ) ; if ( count ( $ diff1 ) > 0 || count ( $ diff2 ) > 0 ) { return false ; } $ attributes = $ this -> attributes ( ) ; unset ( $ attributes [ 'id' ] , $ attributes [ 'class' ] ) ; $ segments [ 'attributes' ] = array_key_exists ( 'attributes' , $ segments ) ? $ segments [ 'attributes' ] : [ ] ; $ diff1 = array_diff_assoc ( $ segments [ 'attributes' ] , $ attributes ) ; $ diff2 = array_diff_assoc ( $ attributes , $ segments [ 'attributes' ] ) ; if ( count ( $ diff1 ) > 0 || count ( $ diff2 ) > 0 ) { return false ; } return true ; }
Checks that the node matches selector .
13,130
public function setAttribute ( $ name , $ value ) { if ( is_numeric ( $ value ) ) { $ value = ( string ) $ value ; } if ( ! is_string ( $ value ) && $ value !== null ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 2 to be string or null, %s given' , __METHOD__ , ( is_object ( $ value ) ? get_class ( $ value ) : gettype ( $ value ) ) ) ) ; } $ this -> node -> setAttribute ( $ name , $ value ) ; return $ this ; }
Set an attribute on the element .
13,131
public function getAttribute ( $ name , $ default = null ) { if ( $ this -> hasAttribute ( $ name ) ) { return $ this -> node -> getAttribute ( $ name ) ; } return $ default ; }
Access to the element s attributes .
13,132
public function removeAllAttributes ( array $ exclusions = [ ] ) { if ( ! $ this -> node instanceof DOMElement ) { return $ this ; } foreach ( $ this -> attributes ( ) as $ name => $ value ) { if ( in_array ( $ name , $ exclusions , true ) ) { continue ; } $ this -> node -> removeAttribute ( $ name ) ; } return $ this ; }
Unset all attributes of the element .
13,133
public function attr ( $ name , $ value = null ) { if ( $ value === null ) { return $ this -> getAttribute ( $ name ) ; } return $ this -> setAttribute ( $ name , $ value ) ; }
Alias for getAttribute and setAttribute methods .
13,134
public function attributes ( array $ names = null ) { if ( ! $ this -> node instanceof DOMElement ) { return null ; } if ( $ names === null ) { $ result = [ ] ; foreach ( $ this -> node -> attributes as $ name => $ attribute ) { $ result [ $ name ] = $ attribute -> value ; } return $ result ; } $ result = [ ] ; foreach ( $ this -> node -> attributes as $ name => $ attribute ) { if ( in_array ( $ name , $ names , true ) ) { $ result [ $ name ] = $ attribute -> value ; } } return $ result ; }
Returns the node attributes or null if it is not DOMElement .
13,135
public function innerHtml ( $ delimiter = '' ) { $ innerHtml = [ ] ; foreach ( $ this -> node -> childNodes as $ childNode ) { $ innerHtml [ ] = $ childNode -> ownerDocument -> saveHTML ( $ childNode ) ; } return implode ( $ delimiter , $ innerHtml ) ; }
Dumps the node descendants into a string using HTML formatting .
13,136
public function innerXml ( $ delimiter = '' ) { $ innerXml = [ ] ; foreach ( $ this -> node -> childNodes as $ childNode ) { $ innerXml [ ] = $ childNode -> ownerDocument -> saveXML ( $ childNode ) ; } return implode ( $ delimiter , $ innerXml ) ; }
Dumps the node descendants into a string using XML formatting .
13,137
public function setInnerHtml ( $ html ) { if ( ! is_string ( $ html ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 1 to be string, %s given' , __METHOD__ , ( is_object ( $ html ) ? get_class ( $ html ) : gettype ( $ html ) ) ) ) ; } $ this -> removeChildren ( ) ; if ( $ html !== '' ) { Errors :: disable ( ) ; $ html = "<htmlfragment>$html</htmlfragment>" ; $ document = new Document ( $ html ) ; $ fragment = $ document -> first ( 'htmlfragment' ) -> getNode ( ) ; foreach ( $ fragment -> childNodes as $ node ) { $ newNode = $ this -> node -> ownerDocument -> importNode ( $ node , true ) ; $ this -> node -> appendChild ( $ newNode ) ; } Errors :: restore ( ) ; } return $ this ; }
Sets inner HTML .
13,138
public function setValue ( $ value ) { if ( is_numeric ( $ value ) ) { $ value = ( string ) $ value ; } if ( ! is_string ( $ value ) && $ value !== null ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 1 to be string, %s given' , __METHOD__ , ( is_object ( $ value ) ? get_class ( $ value ) : gettype ( $ value ) ) ) ) ; } $ this -> node -> nodeValue = $ value ; return $ this ; }
Set the value of this node .
13,139
public function is ( $ node ) { if ( $ node instanceof Element ) { $ node = $ node -> getNode ( ) ; } if ( ! $ node instanceof DOMNode ) { throw new InvalidArgumentException ( sprintf ( 'Argument 1 passed to %s must be an instance of %s or DOMNode, %s given' , __METHOD__ , __CLASS__ , ( is_object ( $ node ) ? get_class ( $ node ) : gettype ( $ node ) ) ) ) ; } return $ this -> node -> isSameNode ( $ node ) ; }
Indicates if two nodes are the same node .
13,140
public function closest ( $ selector , $ strict = false ) { $ node = $ this ; while ( true ) { $ parent = $ node -> parent ( ) ; if ( $ parent === null || $ parent instanceof Document ) { return null ; } if ( $ parent -> matches ( $ selector , $ strict ) ) { return $ parent ; } $ node = $ parent ; } }
Returns first parent node matches passed selector .
13,141
public function removeChild ( $ childNode ) { if ( $ childNode instanceof Element ) { $ childNode = $ childNode -> getNode ( ) ; } if ( ! $ childNode instanceof DOMNode ) { throw new InvalidArgumentException ( sprintf ( 'Argument 1 passed to %s must be an instance of %s or DOMNode, %s given' , __METHOD__ , __CLASS__ , ( is_object ( $ childNode ) ? get_class ( $ childNode ) : gettype ( $ childNode ) ) ) ) ; } $ removedNode = $ this -> node -> removeChild ( $ childNode ) ; return new Element ( $ removedNode ) ; }
Removes child from list of children .
13,142
public function removeChildren ( ) { $ childNodes = [ ] ; foreach ( $ this -> node -> childNodes as $ childNode ) { $ childNodes [ ] = $ childNode ; } $ removedNodes = [ ] ; foreach ( $ childNodes as $ childNode ) { $ removedNode = $ this -> node -> removeChild ( $ childNode ) ; $ removedNodes [ ] = new Element ( $ removedNode ) ; } return $ removedNodes ; }
Removes all child nodes .
13,143
public function remove ( ) { if ( $ this -> node -> parentNode === null ) { throw new LogicException ( 'Can not remove element without parent node' ) ; } $ removedNode = $ this -> node -> parentNode -> removeChild ( $ this -> node ) ; return new Element ( $ removedNode ) ; }
Removes current node from the parent .
13,144
public function replace ( $ newNode , $ clone = true ) { if ( $ this -> node -> parentNode === null ) { throw new LogicException ( 'Can not replace element without parent node' ) ; } if ( $ newNode instanceof Element ) { $ newNode = $ newNode -> getNode ( ) ; } if ( ! $ newNode instanceof DOMNode ) { throw new InvalidArgumentException ( sprintf ( 'Argument 1 passed to %s must be an instance of %s or DOMNode, %s given' , __METHOD__ , __CLASS__ , ( is_object ( $ newNode ) ? get_class ( $ newNode ) : gettype ( $ newNode ) ) ) ) ; } if ( $ clone ) { $ newNode = $ newNode -> cloneNode ( true ) ; } if ( $ newNode -> ownerDocument === null || ! $ this -> getDocument ( ) -> is ( $ newNode -> ownerDocument ) ) { $ newNode = $ this -> node -> ownerDocument -> importNode ( $ newNode , true ) ; } $ node = $ this -> node -> parentNode -> replaceChild ( $ newNode , $ this -> node ) ; return new Element ( $ node ) ; }
Replaces a child .
13,145
protected function setNode ( $ node ) { $ allowedClasses = [ 'DOMElement' , 'DOMText' , 'DOMComment' , 'DOMCdataSection' ] ; if ( ! is_object ( $ node ) || ! in_array ( get_class ( $ node ) , $ allowedClasses , true ) ) { throw new InvalidArgumentException ( sprintf ( 'Argument 1 passed to %s must be an instance of DOMElement, DOMText, DOMComment or DOMCdataSection, %s given' , __METHOD__ , ( is_object ( $ node ) ? get_class ( $ node ) : gettype ( $ node ) ) ) ) ; } $ this -> node = $ node ; return $ this ; }
Sets current node instance .
13,146
public function getDocument ( ) { if ( $ this -> node -> ownerDocument === null ) { return null ; } return new Document ( $ this -> node -> ownerDocument ) ; }
Returns the document associated with this node .
13,147
public function toDocument ( $ encoding = 'UTF-8' ) { $ document = new Document ( null , false , $ encoding ) ; $ document -> appendChild ( $ this -> node ) ; return $ document ; }
Get the DOM document with the current element .
13,148
public function createElement ( $ name , $ value = null , array $ attributes = [ ] ) { $ node = $ this -> document -> createElement ( $ name ) ; return new Element ( $ node , $ value , $ attributes ) ; }
Creates a new element node .
13,149
public function appendChild ( $ nodes ) { $ returnArray = true ; if ( ! is_array ( $ nodes ) ) { $ nodes = [ $ nodes ] ; $ returnArray = false ; } $ result = [ ] ; foreach ( $ nodes as $ node ) { if ( $ node instanceof Element ) { $ node = $ node -> getNode ( ) ; } if ( ! $ node instanceof DOMNode ) { throw new InvalidArgumentException ( sprintf ( 'Argument 1 passed to %s must be an instance of %s\Element or DOMNode, %s given' , __METHOD__ , __NAMESPACE__ , ( is_object ( $ node ) ? get_class ( $ node ) : gettype ( $ node ) ) ) ) ; } Errors :: disable ( ) ; $ cloned = $ node -> cloneNode ( true ) ; $ newNode = $ this -> document -> importNode ( $ cloned , true ) ; $ result [ ] = $ this -> document -> appendChild ( $ newNode ) ; Errors :: restore ( ) ; } $ result = array_map ( function ( DOMNode $ node ) { return new Element ( $ node ) ; } , $ result ) ; return $ returnArray ? $ result : $ result [ 0 ] ; }
Adds a new child at the end of the children .
13,150
public function preserveWhiteSpace ( $ value = true ) { if ( ! is_bool ( $ value ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 1 to be boolean, %s given' , __METHOD__ , gettype ( $ value ) ) ) ; } $ this -> document -> preserveWhiteSpace = $ value ; return $ this ; }
Set preserveWhiteSpace property .
13,151
public function load ( $ string , $ isFile = false , $ type = Document :: TYPE_HTML , $ options = null ) { if ( ! is_string ( $ string ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 1 to be string, %s given' , __METHOD__ , ( is_object ( $ string ) ? get_class ( $ string ) : gettype ( $ string ) ) ) ) ; } if ( ! is_string ( $ type ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 3 to be string, %s given' , __METHOD__ , ( is_object ( $ type ) ? get_class ( $ type ) : gettype ( $ type ) ) ) ) ; } if ( ! in_array ( strtolower ( $ type ) , [ Document :: TYPE_HTML , Document :: TYPE_XML ] , true ) ) { throw new RuntimeException ( sprintf ( 'Document type must be "xml" or "html", %s given' , $ type ) ) ; } if ( $ options === null ) { $ options = LIBXML_HTML_NODEFDTD ; } if ( ! is_int ( $ options ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 4 to be integer, %s given' , __METHOD__ , ( is_object ( $ options ) ? get_class ( $ options ) : gettype ( $ options ) ) ) ) ; } $ string = trim ( $ string ) ; if ( $ isFile ) { $ string = $ this -> loadFile ( $ string ) ; } if ( strtolower ( $ type ) === Document :: TYPE_HTML ) { $ string = Encoder :: convertToHtmlEntities ( $ string , $ this -> encoding ) ; } $ this -> type = strtolower ( $ type ) ; Errors :: disable ( ) ; if ( $ this -> type === Document :: TYPE_HTML ) { $ this -> document -> loadHtml ( $ string , $ options ) ; } else { $ this -> document -> loadXml ( $ string , $ options ) ; } Errors :: restore ( ) ; return $ this ; }
Load HTML or XML .
13,152
public function loadHtmlFile ( $ filename , $ options = null ) { return $ this -> load ( $ filename , true , Document :: TYPE_HTML , $ options ) ; }
Load HTML from a file .
13,153
public function loadXml ( $ xml , $ options = null ) { return $ this -> load ( $ xml , false , Document :: TYPE_XML , $ options ) ; }
Load XML from a string .
13,154
public function loadXmlFile ( $ filename , $ options = null ) { return $ this -> load ( $ filename , true , Document :: TYPE_XML , $ options ) ; }
Load XML from a file .
13,155
protected function loadFile ( $ filename ) { if ( ! is_string ( $ filename ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 1 to be string, %s given' , __METHOD__ , gettype ( $ filename ) ) ) ; } try { $ content = file_get_contents ( $ filename ) ; } catch ( \ Exception $ exception ) { throw new RuntimeException ( sprintf ( 'Could not load file %s' , $ filename ) ) ; } if ( $ content === false ) { throw new RuntimeException ( sprintf ( 'Could not load file %s' , $ filename ) ) ; } return $ content ; }
Reads entire file into a string .
13,156
public function format ( $ format = true ) { if ( ! is_bool ( $ format ) ) { throw new InvalidArgumentException ( sprintf ( '%s expects parameter 1 to be boolean, %s given' , __METHOD__ , gettype ( $ format ) ) ) ; } $ this -> document -> formatOutput = $ format ; return $ this ; }
Nicely formats output with indentation and extra space .
13,157
public function is ( $ document ) { if ( $ document instanceof Document ) { $ element = $ document -> getElement ( ) ; } else { if ( ! $ document instanceof DOMDocument ) { throw new InvalidArgumentException ( sprintf ( 'Argument 1 passed to %s must be an instance of %s or DOMDocument, %s given' , __METHOD__ , __CLASS__ , ( is_object ( $ document ) ? get_class ( $ document ) : gettype ( $ document ) ) ) ) ; } $ element = $ document -> documentElement ; } if ( $ element === null ) { return false ; } return $ this -> getElement ( ) -> isSameNode ( $ element ) ; }
Indicates if two documents are the same document .
13,158
protected function parseClassAttribute ( ) { if ( ! $ this -> element -> hasAttribute ( 'class' ) ) { if ( $ this -> classesString !== '' ) { $ this -> classesString = '' ; $ this -> classes = [ ] ; } return ; } if ( $ this -> element -> getAttribute ( 'class' ) === $ this -> classesString ) { return ; } $ this -> classesString = $ this -> element -> getAttribute ( 'class' ) ; $ classesString = trim ( $ this -> classesString ) ; if ( $ classesString === '' ) { $ this -> classes = [ ] ; return ; } $ classes = explode ( ' ' , $ classesString ) ; $ classes = array_map ( 'trim' , $ classes ) ; $ classes = array_filter ( $ classes ) ; $ classes = array_unique ( $ classes ) ; $ this -> classes = array_values ( $ classes ) ; }
Parses class attribute of the element .
13,159
protected function updateClassAttribute ( ) { $ this -> classesString = implode ( ' ' , $ this -> classes ) ; $ this -> element -> setAttribute ( 'class' , $ this -> classesString ) ; }
Updates class attribute of the element .
13,160
protected static function convertPseudo ( $ pseudo , & $ tagName , array $ parameters = [ ] ) { switch ( $ pseudo ) { case 'first-child' : return 'position() = 1' ; break ; case 'last-child' : return 'position() = last()' ; break ; case 'nth-child' : $ xpath = sprintf ( '(name()="%s") and (%s)' , $ tagName , self :: convertNthExpression ( $ parameters [ 0 ] ) ) ; $ tagName = '*' ; return $ xpath ; break ; case 'contains' : $ string = trim ( $ parameters [ 0 ] , '\'"' ) ; if ( count ( $ parameters ) === 1 ) { return self :: convertContains ( $ string ) ; } if ( $ parameters [ 1 ] !== 'true' && $ parameters [ 1 ] !== 'false' ) { throw new InvalidSelectorException ( sprintf ( 'Parameter 2 of "contains" pseudo-class must be equal true or false, "%s" given' , $ parameters [ 1 ] ) ) ; } $ caseSensitive = $ parameters [ 1 ] === 'true' ; if ( count ( $ parameters ) === 2 ) { return self :: convertContains ( $ string , $ caseSensitive ) ; } if ( $ parameters [ 2 ] !== 'true' && $ parameters [ 2 ] !== 'false' ) { throw new InvalidSelectorException ( sprintf ( 'Parameter 3 of "contains" pseudo-class must be equal true or false, "%s" given' , $ parameters [ 2 ] ) ) ; } $ fullMatch = $ parameters [ 2 ] === 'true' ; return self :: convertContains ( $ string , $ caseSensitive , $ fullMatch ) ; break ; case 'has' : return self :: cssToXpath ( $ parameters [ 0 ] , './/' ) ; break ; case 'not' : return sprintf ( 'not(self::%s)' , self :: cssToXpath ( $ parameters [ 0 ] , '' ) ) ; break ; case 'nth-of-type' : return self :: convertNthExpression ( $ parameters [ 0 ] ) ; break ; case 'empty' : return 'count(descendant::*) = 0' ; break ; case 'not-empty' : return 'count(descendant::*) > 0' ; break ; } throw new InvalidSelectorException ( sprintf ( 'Unknown pseudo-class "%s"' , $ pseudo ) ) ; }
Converts a CSS pseudo - class into an XPath expression .
13,161
protected static function convertNthExpression ( $ expression ) { if ( $ expression === '' ) { throw new InvalidSelectorException ( 'nth-child (or nth-last-child) expression must not be empty' ) ; } if ( $ expression === 'odd' ) { return 'position() mod 2 = 1 and position() >= 1' ; } if ( $ expression === 'even' ) { return 'position() mod 2 = 0 and position() >= 0' ; } if ( is_numeric ( $ expression ) ) { return sprintf ( 'position() = %d' , $ expression ) ; } if ( preg_match ( "/^(?P<mul>[0-9]?n)(?:(?P<sign>\+|\-)(?P<pos>[0-9]+))?$/is" , $ expression , $ segments ) ) { if ( isset ( $ segments [ 'mul' ] ) ) { $ multiplier = $ segments [ 'mul' ] === 'n' ? 1 : trim ( $ segments [ 'mul' ] , 'n' ) ; $ sign = ( isset ( $ segments [ 'sign' ] ) && $ segments [ 'sign' ] === '+' ) ? '-' : '+' ; $ position = isset ( $ segments [ 'pos' ] ) ? $ segments [ 'pos' ] : 0 ; return sprintf ( '(position() %s %d) mod %d = 0 and position() >= %d' , $ sign , $ position , $ multiplier , $ position ) ; } } throw new InvalidSelectorException ( sprintf ( 'Invalid nth-child expression "%s"' , $ expression ) ) ; }
Converts nth - expression into an XPath expression .
13,162
public static function load ( $ url , $ user = null , $ pass = null ) { $ xml = self :: loadXml ( $ url , $ user , $ pass ) ; if ( $ xml -> channel ) { return self :: fromRss ( $ xml ) ; } else { return self :: fromAtom ( $ xml ) ; } }
Loads RSS or Atom feed .
13,163
public static function loadRss ( $ url , $ user = null , $ pass = null ) { return self :: fromRss ( self :: loadXml ( $ url , $ user , $ pass ) ) ; }
Loads RSS feed .
13,164
public static function loadAtom ( $ url , $ user = null , $ pass = null ) { return self :: fromAtom ( self :: loadXml ( $ url , $ user , $ pass ) ) ; }
Loads Atom feed .
13,165
public function toArray ( SimpleXMLElement $ xml = null ) { if ( $ xml === null ) { $ xml = $ this -> xml ; } if ( ! $ xml -> children ( ) ) { return ( string ) $ xml ; } $ arr = array ( ) ; foreach ( $ xml -> children ( ) as $ tag => $ child ) { if ( count ( $ xml -> $ tag ) === 1 ) { $ arr [ $ tag ] = $ this -> toArray ( $ child ) ; } else { $ arr [ $ tag ] [ ] = $ this -> toArray ( $ child ) ; } } return $ arr ; }
Converts a SimpleXMLElement into an array .
13,166
private static function loadXml ( $ url , $ user , $ pass ) { $ e = self :: $ cacheExpire ; $ cacheFile = self :: $ cacheDir . '/feed.' . md5 ( serialize ( func_get_args ( ) ) ) . '.xml' ; if ( self :: $ cacheDir && ( time ( ) - @ filemtime ( $ cacheFile ) <= ( is_string ( $ e ) ? strtotime ( $ e ) - time ( ) : $ e ) ) && $ data = @ file_get_contents ( $ cacheFile ) ) { } elseif ( $ data = trim ( self :: httpRequest ( $ url , $ user , $ pass ) ) ) { if ( self :: $ cacheDir ) { file_put_contents ( $ cacheFile , $ data ) ; } } elseif ( self :: $ cacheDir && $ data = @ file_get_contents ( $ cacheFile ) ) { } else { throw new FeedException ( 'Cannot load feed.' ) ; } return new SimpleXMLElement ( $ data , LIBXML_NOWARNING | LIBXML_NOERROR ) ; }
Load XML from cache or HTTP .
13,167
private static function adjustNamespaces ( $ el ) { foreach ( $ el -> getNamespaces ( true ) as $ prefix => $ ns ) { $ children = $ el -> children ( $ ns ) ; foreach ( $ children as $ tag => $ content ) { $ el -> { $ prefix . ':' . $ tag } = $ content ; } } }
Generates better accessible namespaced tags .
13,168
public static function iniSizeToBytes ( $ size ) { if ( \ is_numeric ( $ size ) ) { return ( int ) $ size ; } $ suffix = \ strtoupper ( \ substr ( $ size , - 1 ) ) ; $ strippedSize = \ substr ( $ size , 0 , - 1 ) ; if ( ! \ is_numeric ( $ strippedSize ) ) { throw new \ InvalidArgumentException ( "$size is not a valid ini size" ) ; } if ( $ strippedSize <= 0 ) { throw new \ InvalidArgumentException ( "Expect $size to be higher isn't zero or lower" ) ; } if ( $ suffix === 'K' ) { return $ strippedSize * 1024 ; } if ( $ suffix === 'M' ) { return $ strippedSize * 1024 * 1024 ; } if ( $ suffix === 'G' ) { return $ strippedSize * 1024 * 1024 * 1024 ; } if ( $ suffix === 'T' ) { return $ strippedSize * 1024 * 1024 * 1024 * 1024 ; } return ( int ) $ size ; }
Convert a ini like size to a numeric size in bytes .
13,169
public function save ( $ filename , $ overwrite = false ) { if ( $ this -> html ) { $ this -> snappy -> generateFromHtml ( $ this -> html , $ filename , $ this -> options , $ overwrite ) ; } elseif ( $ this -> file ) { $ this -> snappy -> generate ( $ this -> file , $ filename , $ this -> options , $ overwrite ) ; } return $ this ; }
Save the image to a file
13,170
protected function ensureResponseHasView ( ) { if ( ! isset ( $ this -> view ) || ! $ this -> view instanceof View ) { return PHPUnit :: fail ( 'The response is not a view.' ) ; } return $ this ; }
Ensure that the response has a view as its original content .
13,171
public function assertViewHasAll ( array $ bindings ) { foreach ( $ bindings as $ key => $ value ) { if ( is_int ( $ key ) ) { $ this -> assertViewHas ( $ value ) ; } else { $ this -> assertViewHas ( $ key , $ value ) ; } } return $ this ; }
Assert that the response view has a given list of bound data .
13,172
public function output ( ) { if ( $ this -> html ) { return $ this -> snappy -> getOutputFromHtml ( $ this -> html , $ this -> options ) ; } if ( $ this -> file ) { return $ this -> snappy -> getOutput ( $ this -> file , $ this -> options ) ; } throw new \ InvalidArgumentException ( 'PDF Generator requires a html or file in order to produce output.' ) ; }
Output the PDF as a string .
13,173
public function validate ( $ attributes = [ ] , $ returnData = false ) { $ data = ( $ attributes ) ? $ attributes : $ this -> _writeProperties ; $ data = $ this -> filter ( $ data ) ; $ this -> _writeProperties = ( ! $ attributes ) ? $ data : $ this -> _writeProperties ; $ rules = $ this -> rules ( ) ; if ( $ this -> _selfCondition ) { $ newRules = [ ] ; foreach ( ( array ) $ rules as $ key => $ rule ) { if ( isset ( $ this -> _writeProperties [ $ rule [ 'field' ] ] ) ) { $ newRules [ ] = $ rule ; } } $ rules = $ newRules ; } if ( empty ( $ rules ) ) return ( $ returnData ) ? $ data : true ; if ( empty ( $ data ) ) return false ; get_instance ( ) -> load -> library ( 'form_validation' , null , 'yidas_model_form_validation' ) ; $ validator = get_instance ( ) -> yidas_model_form_validation ; $ validator -> reset_validation ( ) ; $ validator -> set_data ( $ data ) ; $ validator -> set_rules ( $ rules ) ; $ result = $ validator -> run ( ) ; if ( $ result === false ) { $ this -> _errors = $ validator -> error_array ( ) ; return false ; } else { return ( $ returnData ) ? $ data : true ; } }
Performs the data validation with filters
13,174
public function find ( $ withAll = false ) { $ instance = ( isset ( $ this ) ) ? $ this : new static ; if ( $ instance -> _cleanNextFind === true ) { $ instance -> setAlias ( null ) ; } else { $ instance -> _cleanNextFind = true ; } $ sqlFrom = ( $ instance -> alias ) ? "{$instance->table} AS {$instance->alias}" : $ instance -> table ; $ instance -> _dbr -> from ( $ sqlFrom ) ; if ( $ withAll === true ) { $ instance -> withAll ( ) ; } $ instance -> _addGlobalScopeCondition ( ) ; $ instance -> _addSoftDeletedCondition ( ) ; return $ instance -> _dbr ; }
Create an existent CI Query Builder instance with Model features for query purpose .
13,175
public static function findOne ( $ condition = [ ] ) { $ instance = ( isset ( $ this ) ) ? $ this : new static ; $ record = $ instance -> _findByCondition ( $ condition ) -> limit ( 1 ) -> get ( ) -> row_array ( ) ; if ( ! $ record ) { return $ record ; } return $ instance -> createActiveRecord ( $ record , $ record [ $ instance -> primaryKey ] ) ; }
Return a single active record model instance by a primary key or an array of column values .
13,176
public function batchInsert ( $ data , $ runValidation = true ) { foreach ( $ data as $ key => & $ attributes ) { if ( $ runValidation && false === $ attributes = $ this -> validate ( $ attributes , true ) ) return false ; $ this -> _attrEventBeforeInsert ( $ attributes ) ; } return $ this -> _db -> insert_batch ( $ this -> table , $ data ) ; }
Insert a batch of rows with Timestamps feature into the associated database table using the attribute values of this record .
13,177
public function replace ( $ attributes , $ runValidation = true ) { if ( $ runValidation && false === $ attributes = $ this -> validate ( $ attributes , true ) ) return false ; $ this -> _attrEventBeforeInsert ( $ attributes ) ; return $ this -> _db -> replace ( $ this -> table , $ attributes ) ; }
Replace a row with Timestamps feature into the associated database table using the attribute values of this record .
13,178
public function batchUpdate ( Array $ dataSet , $ withAll = false , $ maxLength = 4 * 1024 * 1024 , $ runValidation = true ) { $ count = 0 ; $ sqlBatch = '' ; foreach ( $ dataSet as $ key => & $ each ) { list ( $ attributes , $ condition ) = $ each ; if ( ! is_array ( $ attributes ) || ! $ attributes ) continue ; if ( $ runValidation && false === $ attributes = $ this -> validate ( $ attributes , true ) ) continue ; if ( $ withAll === true ) { $ this -> withAll ( ) ; } $ query = $ this -> _findByCondition ( $ condition ) ; $ attributes = $ this -> _attrEventBeforeUpdate ( $ attributes ) ; $ sql = $ this -> _dbr -> set ( $ attributes ) -> get_compiled_update ( ) ; $ this -> _dbr -> reset_query ( ) ; if ( ( $ count == 0 && $ sqlBatch ) || strlen ( $ sqlBatch ) >= $ maxLength ) { $ result = $ this -> _db -> query ( $ sqlBatch ) ; $ sqlBatch = "" ; $ count = ( $ result ) ? $ count + 1 : $ count ; } $ sqlBatch .= "{$sql};\n" ; } $ result = $ this -> _db -> query ( $ sqlBatch ) ; return ( $ result ) ? $ count + 1 : $ count ; }
Update a batch of update queries into combined query strings .
13,179
public function lockForUpdate ( ) { $ sql = $ this -> _dbr -> get_compiled_select ( ) ; $ this -> _dbr -> reset_query ( ) ; return $ this -> _db -> query ( "{$sql} FOR UPDATE" ) ; }
Lock the selected rows in the table for updating .
13,180
public function sharedLock ( ) { $ sql = $ this -> _dbr -> get_compiled_select ( ) ; $ this -> _dbr -> reset_query ( ) ; return $ this -> _db -> query ( "{$sql} LOCK IN SHARE MODE" ) ; }
Share lock the selected rows in the table .
13,181
public function createActiveRecord ( $ readProperties , $ selfCondition ) { $ activeRecord = new static ( ) ; $ activeRecord -> _readProperties = $ readProperties ; $ activeRecord -> _selfCondition = $ selfCondition ; return $ activeRecord ; }
New a Active Record from Model by data
13,182
protected function _relationship ( $ modelName , $ relationship , $ foreignKey = null , $ localKey = null ) { if ( strpos ( $ modelName , "\\" ) !== false ) { $ model = new $ modelName ; } else { get_instance ( ) -> load -> model ( $ modelName ) ; $ model = $ this -> $ modelName ; } $ libClass = __CLASS__ ; if ( ! is_subclass_of ( $ model , $ libClass ) ) { throw new Exception ( "Model `{$modelName}` does not extend {$libClass}" , 500 ) ; } $ foreignKey = ( $ foreignKey ) ? $ foreignKey : $ this -> primaryKey ; $ localKey = ( $ localKey ) ? $ localKey : $ this -> primaryKey ; $ query = $ model -> find ( ) -> where ( $ foreignKey , $ this -> $ localKey ) ; $ query -> modelName = $ modelName ; $ query -> relationship = $ relationship ; return $ query ; }
Base relationship .
13,183
public static function indexBy ( Array & $ array , $ key = null , $ obj2Array = false ) { $ key = ( $ key ) ? : ( new static ( ) ) -> primaryKey ; $ tmp = [ ] ; foreach ( $ array as $ row ) { if ( is_object ( $ row ) && isset ( $ row -> $ key ) ) { $ tmp [ $ row -> $ key ] = ( $ obj2Array ) ? ( array ) $ row : $ row ; } elseif ( is_array ( $ row ) && isset ( $ row [ $ key ] ) ) { $ tmp [ $ row [ $ key ] ] = $ row ; } } return $ array = $ tmp ; }
Index by Key
13,184
public static function htmlEncode ( $ content , $ doubleEncode = true ) { $ ci = & get_instance ( ) ; return htmlspecialchars ( $ content , ENT_QUOTES | ENT_SUBSTITUTE , $ ci -> config -> item ( 'charset' ) ? $ ci -> config -> item ( 'charset' ) : 'UTF-8' , $ doubleEncode ) ; }
Encodes special characters into HTML entities .
13,185
protected function _attrEventBeforeInsert ( & $ attributes ) { $ this -> _formatDate ( static :: CREATED_AT , $ attributes ) ; if ( $ this -> createdWithUpdated ) { $ this -> _formatDate ( static :: UPDATED_AT , $ attributes ) ; } return $ attributes ; }
Attributes handle function for each Insert
13,186
protected function _formatDate ( $ field , & $ attributes ) { if ( $ this -> timestamps && $ field ) { switch ( $ this -> dateFormat ) { case 'datetime' : $ dateFormat = date ( "Y-m-d H:i:s" ) ; break ; case 'unixtime' : default : $ dateFormat = time ( ) ; break ; } $ attributes [ $ field ] = $ dateFormat ; } return $ attributes ; }
Format a date for timestamps
13,187
protected function _addSoftDeletedCondition ( ) { if ( $ this -> _withoutSoftDeletedScope ) { $ this -> _withoutSoftDeletedScope = false ; } elseif ( static :: SOFT_DELETED && isset ( $ this -> softDeletedFalseValue ) ) { $ this -> _dbr -> where ( $ this -> _field ( static :: SOFT_DELETED ) , $ this -> softDeletedFalseValue ) ; } return true ; }
The scope which not been soft deleted
13,188
public function __isset ( $ name ) { if ( isset ( $ this -> _writeProperties [ $ name ] ) ) { return true ; } return isset ( $ this -> _readProperties [ $ name ] ) ; }
ORM isset property
13,189
public function setLocation ( FileDescriptor $ file , $ line = 0 ) { $ this -> setFile ( $ file ) ; $ this -> line = $ line ; }
Sets the file and linenumber where this element is at .
13,190
public function getVersion ( ) { $ version = $ this -> getTags ( ) -> get ( 'version' , new Collection ( ) ) ; if ( $ version -> count ( ) !== 0 ) { return $ version ; } $ inheritedElement = $ this -> getInheritedElement ( ) ; if ( $ inheritedElement ) { return $ inheritedElement -> getVersion ( ) ; } return new Collection ( ) ; }
Returns the versions for this element .
13,191
public function getCopyright ( ) { $ copyright = $ this -> getTags ( ) -> get ( 'copyright' , new Collection ( ) ) ; if ( $ copyright -> count ( ) !== 0 ) { return $ copyright ; } $ inheritedElement = $ this -> getInheritedElement ( ) ; if ( $ inheritedElement ) { return $ inheritedElement -> getCopyright ( ) ; } return new Collection ( ) ; }
Returns the copyrights for this element .
13,192
public function process ( \ DOMDocument $ xml ) { $ ignoreQry = '//long-description[contains(., "{@internal")]' ; $ xpath = new \ DOMXPath ( $ xml ) ; $ nodes = $ xpath -> query ( $ ignoreQry ) ; $ replacement = $ this -> internalAllowed ? '$1' : '' ; foreach ( $ nodes as $ node ) { $ node -> nodeValue = preg_replace ( '/\{@internal\s(.+?)\}\}/' , $ replacement , $ node -> nodeValue ) ; } return $ xml ; }
Converts the internal tags in Long Descriptions .
13,193
public function offsetSet ( $ index , $ newval ) { if ( ! $ newval instanceof TableOfContents \ File ) { throw new \ InvalidArgumentException ( 'A table of contents may only be filled with File objects' ) ; } $ basename = basename ( $ newval -> getFilename ( ) ) ; if ( strpos ( $ basename , '.' ) !== false ) { $ basename = substr ( $ basename , 0 , strpos ( $ basename , '.' ) ) ; } if ( strtolower ( $ basename ) === 'index' ) { $ this -> modules [ ] = $ newval ; } parent :: offsetSet ( $ newval -> getFilename ( ) , $ newval ) ; }
Override offsetSet to force the use of the relative filename .
13,194
public function setExtension ( string $ extension ) : void { if ( ! preg_match ( '/^[a-zA-Z0-9]{2,4}$/' , $ extension ) ) { throw new InvalidArgumentException ( 'Extension should be only be composed of alphanumeric characters' . ' and should be at least 2 but no more than 4 characters' ) ; } $ this -> extension = $ extension ; }
Sets the file extension used to determine the template filename .
13,195
protected function getTemplateFilename ( ) { $ filename = $ this -> name . '/layout.' . $ this -> extension . '.twig' ; $ template_path = $ this -> path . DIRECTORY_SEPARATOR . $ filename ; if ( ! file_exists ( $ template_path ) ) { throw new \ DomainException ( 'Template file "' . $ template_path . '" could not be found' ) ; } return $ filename ; }
Returns the filename for the template .
13,196
public function process ( \ DOMDocument $ xml ) { $ ignoreQry = '//tag[@name=\'' . $ this -> tag . '\']' ; $ xpath = new \ DOMXPath ( $ xml ) ; $ nodes = $ xpath -> query ( $ ignoreQry ) ; foreach ( $ nodes as $ node ) { $ remove = $ node -> parentNode -> parentNode ; if ( ! isset ( $ remove -> parentNode ) ) { continue ; } $ remove -> parentNode -> removeChild ( $ remove ) ; } return $ xml ; }
Removes DocBlocks marked with ignore tag from the structure .
13,197
private function parse ( string $ dsn ) : void { $ dsnParts = explode ( ';' , $ dsn ) ; $ location = $ dsnParts [ 0 ] ; unset ( $ dsnParts [ 0 ] ) ; $ locationParts = parse_url ( $ location ) ; if ( $ locationParts === false || ( array_key_exists ( 'scheme' , $ locationParts ) && \ strlen ( $ locationParts [ 'scheme' ] ) === 1 ) ) { preg_match ( static :: WINDOWS_DSN , $ dsn , $ locationParts ) ; } if ( ! array_key_exists ( 'scheme' , $ locationParts ) || ( $ locationParts [ 'scheme' ] === '' && array_key_exists ( 'path' , $ locationParts ) ) ) { $ locationParts [ 'scheme' ] = 'file' ; $ location = 'file://' . $ location ; } if ( ! filter_var ( $ location , FILTER_VALIDATE_URL ) && ! preg_match ( static :: WINDOWS_DSN , $ location ) ) { throw new InvalidArgumentException ( sprintf ( '"%s" is not a valid DSN.' , $ dsn ) ) ; } $ this -> parseDsn ( $ location , $ dsnParts ) ; $ this -> parseScheme ( $ locationParts ) ; $ this -> parseHostAndPath ( $ locationParts ) ; $ this -> parsePort ( $ locationParts ) ; $ this -> user = $ locationParts [ 'user' ] ?? '' ; $ this -> password = $ locationParts [ 'pass' ] ?? '' ; $ this -> parseQuery ( $ locationParts ) ; $ this -> parseParameters ( $ dsnParts ) ; }
Parses the given DSN
13,198
private function parseScheme ( array $ locationParts ) : void { if ( ! $ this -> isValidScheme ( $ locationParts [ 'scheme' ] ) ) { throw new InvalidArgumentException ( sprintf ( '"%s" is not a valid scheme.' , $ locationParts [ 'scheme' ] ) ) ; } $ this -> scheme = strtolower ( $ locationParts [ 'scheme' ] ) ; }
validates and sets the scheme property
13,199
private function isValidScheme ( string $ scheme ) : bool { $ validSchemes = [ 'file' , 'git+http' , 'git+https' ] ; return \ in_array ( \ strtolower ( $ scheme ) , $ validSchemes , true ) ; }
Validated provided scheme .