idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
31,900 | static public function instance ( $ method = null , $ url = null , $ data = false , $ options = false ) { return new static ( $ method , $ url , $ data , $ options ) ; } | http request instance return HttpRequest object . |
31,901 | public function type ( $ type ) { $ type = strtoupper ( $ type ) ; if ( ! in_array ( $ type , [ 'CURL' , 'SOCKET' , 'FILE' ] ) ) { $ type = 'CURL' ; } $ this -> def [ 'type' ] = $ type ; return $ this ; } | set handle type can be CURL|SOCKET|FILE |
31,902 | public function header ( $ name , $ value = null ) { if ( is_array ( $ name ) ) { $ this -> def [ 'header' ] = array_merge ( $ this -> def [ 'header' ] , $ name ) ; } else { $ this -> def [ 'header' ] [ $ name ] = $ value ; } return $ this ; } | set request header |
31,903 | public function cookie ( $ name , $ value = null ) { $ str = '' ; if ( is_array ( $ name ) ) { $ arr = [ ] ; foreach ( $ name as $ k => $ v ) { $ arr [ ] = $ k . '=' . $ v ; } $ str = implode ( ';' , $ arr ) ; } elseif ( $ value ) { $ str = $ name . '=' . $ value ; } else { $ str = $ name ; } $ this -> def [ 'cookie' ] = $ this -> def [ 'cookie' ] ? $ this -> def [ 'cookie' ] . ';' . $ str : $ str ; return $ this ; } | set request cookie |
31,904 | private function header2Array ( $ str ) { if ( is_array ( $ str ) ) return $ str ; $ result = [ ] ; $ array = explode ( "\n" , trim ( str_replace ( "\r\n" , "\n" , $ str ) , "\n" ) ) ; foreach ( $ array as $ i => $ line ) { if ( $ i === 0 ) { $ result [ 'Http-Status' ] = $ line ; } else { $ header = explode ( ':' , $ line , 2 ) ; if ( ! $ header [ 0 ] ) continue ; if ( isset ( $ header [ 1 ] ) ) { $ result [ trim ( $ header [ 0 ] ) ] = trim ( $ header [ 1 ] ) ; } else { $ result [ ] = trim ( $ header [ 0 ] ) ; } } } return $ result ; } | parse header to array |
31,905 | private function header2String ( $ header ) { $ str = '' ; if ( is_array ( $ header ) ) foreach ( $ header as $ k => $ v ) { if ( is_numeric ( $ k ) ) continue ; $ str .= $ k . ': ' . $ v . "\r\n" ; } else { $ str = $ header ; } return $ str ; } | parse header to string |
31,906 | public function getErrorString ( ) { $ this -> execute ( ) ; return $ this -> error ? $ this -> error [ 'errcode' ] . ':' . $ this -> error [ 'errmsg' ] : null ; } | get error string |
31,907 | public function getResponse ( ) { $ this -> execute ( ) ; switch ( $ this -> def [ 'dataType' ] ) { case 'array' : $ result = static :: toArray ( ) ; break ; case 'object' : case 'json' : $ result = static :: toJson ( ) ; break ; default : $ result = $ this -> getErrorString ( ) ? : $ this -> responseText ; } return $ result ; } | get resposne return for dataType result |
31,908 | public function getContentType ( ) { if ( isset ( $ this -> responseInfo [ 'content_type' ] ) ) { $ contentType = $ this -> responseInfo [ 'content_type' ] ; } else { $ contentType = isset ( $ this -> responseHeaders [ 'Content-Type' ] ) ? $ this -> responseHeaders [ 'Content-Type' ] : null ; } if ( $ contentType ) { $ contentTypeParts = preg_split ( '/\s*[;,]\s*/' , $ contentType ) ; return strtolower ( $ contentTypeParts [ 0 ] ) ; } return null ; } | get content type |
31,909 | public function toArray ( ) { $ this -> dataType ( 'array' ) ; $ this -> execute ( ) ; if ( $ this -> def [ 'savePath' ] ) { return $ this -> save ( ) ; } elseif ( $ this -> def [ 'verbose' ] ) { return $ this -> getVerboseResponse ( ) ; } return $ this -> getError ( ) ? : json_decode ( $ this -> responseText , true ) ; } | return array response |
31,910 | public function register ( $ errorLevel = \ E_WARNING ) { if ( ! $ this -> isRegistered ) { set_exception_handler ( [ $ this , 'handleException' ] ) ; if ( ! isset ( $ errorLevel ) ) $ errorLevel = \ E_WARNING ; set_error_handler ( [ $ this , 'handleError' ] , $ errorLevel ) ; if ( $ this -> options [ 'memory_reserve_size' ] > 0 ) { $ this -> _memoryReserve = str_repeat ( 'x' , $ this -> options [ 'memory_reserve_size' ] ) ; } register_shutdown_function ( [ $ this , 'handleFatalError' ] ) ; $ this -> isRegistered = true ; } return $ this ; } | Register this error handler |
31,911 | protected function getTextMessage ( $ exception ) { $ message = 'Application Exception' . PHP_EOL ; $ message .= static :: getItemTextMessage ( $ exception ) ; while ( $ exception = $ exception -> getPrevious ( ) ) { $ message .= PHP_EOL . 'Previous exception:' . PHP_EOL ; $ message .= static :: getItemTextMessage ( $ exception ) ; } return $ message ; } | getexception text content |
31,912 | protected function getItemTextMessage ( $ exception ) { $ text = sprintf ( 'Type: %s' . PHP_EOL , get_class ( $ exception ) ) ; if ( ( $ code = $ exception -> getCode ( ) ) ) { $ text .= sprintf ( 'Code: %s' . PHP_EOL , $ code ) ; } if ( ( $ message = $ exception -> getMessage ( ) ) ) { $ text .= sprintf ( 'Message: %s' . PHP_EOL , htmlentities ( $ message ) ) ; } if ( ( $ file = $ exception -> getFile ( ) ) ) { $ text .= sprintf ( 'File: %s' . PHP_EOL , $ file ) ; } if ( ( $ line = $ exception -> getLine ( ) ) ) { $ text .= sprintf ( 'Line: %s' . PHP_EOL , $ line ) ; } if ( ( $ trace = $ exception -> getTraceAsString ( ) ) ) { $ text .= sprintf ( 'Trace: ' . PHP_EOL . '%s' , $ trace ) ; } return $ text ; } | get each exception text content |
31,913 | protected function getHtmlMessage ( $ exception ) { $ title = 'Application Error' ; if ( $ this -> options [ 'display_details' ] ) { $ html = '<p>The application could not run because of the following error:</p>' ; $ html .= '<h2>Details</h2>' ; $ html .= $ this -> getItemHtmlMessage ( $ exception ) ; while ( $ exception = $ exception -> getPrevious ( ) ) { $ html .= '<h2>Previous exception</h2>' ; $ html .= $ this -> getItemHtmlMessage ( $ exception ) ; } } else { $ html = '<p>A website error has occurred. Sorry for the temporary inconvenience.</p>' ; } $ output = sprintf ( "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" . "<title>%s</title><style>body{margin:0;padding:30px;font:14px/1.5 Helvetica,Arial,Verdana," . "sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{" . "display:inline-block;width:65px;}</style></head><body><h1>%s</h1>%s</body></html>" , $ title , $ title , $ html ) ; return $ output ; } | get html format of exception |
31,914 | protected function getItemHtmlMessage ( $ exception ) { $ html = sprintf ( '<div><strong>Type:</strong> %s</div>' , get_class ( $ exception ) ) ; if ( ( $ code = $ exception -> getCode ( ) ) ) { $ html .= sprintf ( '<div><strong>Code:</strong> %s</div>' , $ code ) ; } if ( ( $ message = $ exception -> getMessage ( ) ) ) { $ html .= sprintf ( '<div><strong>Message:</strong> %s</div>' , htmlentities ( $ message ) ) ; } if ( ( $ file = $ exception -> getFile ( ) ) ) { $ html .= sprintf ( '<div><strong>File:</strong> %s</div>' , $ file ) ; } if ( ( $ line = $ exception -> getLine ( ) ) ) { $ html .= sprintf ( '<div><strong>Line:</strong> %s</div>' , $ line ) ; } if ( ( $ trace = $ exception -> getTraceAsString ( ) ) ) { $ html .= '<h2>Trace</h2>' ; $ html .= sprintf ( '<pre>%s</pre>' , htmlentities ( $ trace ) ) ; } return $ html ; } | get each exception html content |
31,915 | protected function getJsonMessage ( $ exception ) { $ error = array ( 'message' => 'Application Error' , ) ; if ( $ this -> options [ 'display_details' ] ) { $ error [ 'exception' ] = array ( ) ; do { $ error [ 'exception' ] [ ] = array ( 'type' => get_class ( $ exception ) , 'code' => $ exception -> getCode ( ) , 'message' => $ exception -> getMessage ( ) , 'file' => $ exception -> getFile ( ) , 'line' => $ exception -> getLine ( ) , 'trace' => explode ( "\n" , $ exception -> getTraceAsString ( ) ) , ) ; } while ( $ exception = $ exception -> getPrevious ( ) ) ; } return json_encode ( $ error , JSON_PRETTY_PRINT ) ; } | get JSON error |
31,916 | protected function getXmlMessage ( $ exception ) { $ xml = "<error>\n <message>Application Error</message>\n" ; if ( $ this -> options [ 'display_details' ] ) { do { $ xml .= " <exception>\n" ; $ xml .= " <type>" . get_class ( $ exception ) . "</type>\n" ; $ xml .= " <code>" . $ exception -> getCode ( ) . "</code>\n" ; $ xml .= " <message>" . $ this -> createCdataSection ( $ exception -> getMessage ( ) ) . "</message>\n" ; $ xml .= " <file>" . $ exception -> getFile ( ) . "</file>\n" ; $ xml .= " <line>" . $ exception -> getLine ( ) . "</line>\n" ; $ xml .= " <trace>" . $ this -> createCdataSection ( $ exception -> getTraceAsString ( ) ) . "</trace>\n" ; $ xml .= " </exception>\n" ; } while ( $ exception = $ exception -> getPrevious ( ) ) ; } $ xml .= "</error>" ; return $ xml ; } | get exception xml content |
31,917 | public function setDefaultFont ( $ default = null ) { $ old = $ this -> _defaultFont ; $ this -> _defaultFont = $ default ; if ( $ default ) $ this -> value [ 'font-family' ] = $ default ; return $ old ; } | define the Default Font to use if the font does not exist or if no font asked |
31,918 | protected function _init ( ) { require ( K_PATH_MAIN . 'htmlcolors.php' ) ; $ this -> _htmlColor = $ webcolor ; $ this -> table = array ( ) ; $ this -> value = array ( ) ; $ this -> initStyle ( ) ; $ this -> resetStyle ( ) ; } | Init the object |
31,919 | public function setPosition ( ) { $ currentX = $ this -> _pdf -> getX ( ) ; $ currentY = $ this -> _pdf -> getY ( ) ; $ this -> value [ 'xc' ] = $ currentX ; $ this -> value [ 'yc' ] = $ currentY ; if ( $ this -> value [ 'position' ] == 'relative' || $ this -> value [ 'position' ] == 'absolute' ) { if ( $ this -> value [ 'right' ] !== null ) { $ x = $ this -> getLastWidth ( true ) - $ this -> value [ 'right' ] - $ this -> value [ 'width' ] ; if ( $ this -> value [ 'margin' ] [ 'r' ] ) $ x -= $ this -> value [ 'margin' ] [ 'r' ] ; } else { $ x = $ this -> value [ 'left' ] ; if ( $ this -> value [ 'margin' ] [ 'l' ] ) $ x += $ this -> value [ 'margin' ] [ 'l' ] ; } if ( $ this -> value [ 'bottom' ] !== null ) { $ y = $ this -> getLastHeight ( true ) - $ this -> value [ 'bottom' ] - $ this -> value [ 'height' ] ; if ( $ this -> value [ 'margin' ] [ 'b' ] ) $ y -= $ this -> value [ 'margin' ] [ 'b' ] ; } else { $ y = $ this -> value [ 'top' ] ; if ( $ this -> value [ 'margin' ] [ 't' ] ) $ y += $ this -> value [ 'margin' ] [ 't' ] ; } if ( $ this -> value [ 'position' ] == 'relative' ) { $ this -> value [ 'x' ] = $ currentX + $ x ; $ this -> value [ 'y' ] = $ currentY + $ y ; } else { $ this -> value [ 'x' ] = $ this -> _getLastAbsoluteX ( ) + $ x ; $ this -> value [ 'y' ] = $ this -> _getLastAbsoluteY ( ) + $ y ; } } else { $ this -> value [ 'x' ] = $ currentX ; $ this -> value [ 'y' ] = $ currentY ; if ( $ this -> value [ 'margin' ] [ 'l' ] ) $ this -> value [ 'x' ] += $ this -> value [ 'margin' ] [ 'l' ] ; if ( $ this -> value [ 'margin' ] [ 't' ] ) $ this -> value [ 'y' ] += $ this -> value [ 'margin' ] [ 't' ] ; } $ this -> _pdf -> setXY ( $ this -> value [ 'x' ] , $ this -> value [ 'y' ] ) ; } | set the New position for the current Tag |
31,920 | public function getFormStyle ( ) { $ prop = array ( ) ; $ prop [ 'alignment' ] = $ this -> value [ 'text-align' ] ; if ( isset ( $ this -> value [ 'background' ] [ 'color' ] ) && is_array ( $ this -> value [ 'background' ] [ 'color' ] ) ) { $ prop [ 'fillColor' ] = $ this -> value [ 'background' ] [ 'color' ] ; } if ( isset ( $ this -> value [ 'border' ] [ 't' ] [ 'color' ] ) ) { $ prop [ 'strokeColor' ] = $ this -> value [ 'border' ] [ 't' ] [ 'color' ] ; } if ( isset ( $ this -> value [ 'border' ] [ 't' ] [ 'width' ] ) ) { $ prop [ 'lineWidth' ] = $ this -> value [ 'border' ] [ 't' ] [ 'width' ] ; } if ( isset ( $ this -> value [ 'border' ] [ 't' ] [ 'type' ] ) ) { $ prop [ 'borderStyle' ] = $ this -> value [ 'border' ] [ 't' ] [ 'type' ] ; } if ( ! empty ( $ this -> value [ 'color' ] ) ) { $ prop [ 'textColor' ] = $ this -> value [ 'color' ] ; } if ( ! empty ( $ this -> value [ 'font-size' ] ) ) { $ prop [ 'textSize' ] = $ this -> value [ 'font-size' ] ; } return $ prop ; } | Analise the CSS style to convert it into Form style |
31,921 | public function getLineHeight ( ) { $ val = $ this -> value [ 'line-height' ] ; if ( $ val == 'normal' ) $ val = '108%' ; return $ this -> convertToMM ( $ val , $ this -> value [ 'font-size' ] ) ; } | get the height of the current line |
31,922 | public function getLastWidth ( $ mode = false ) { for ( $ k = count ( $ this -> table ) - 1 ; $ k >= 0 ; $ k -- ) { if ( $ this -> table [ $ k ] [ 'width' ] ) { $ w = $ this -> table [ $ k ] [ 'width' ] ; if ( $ mode ) { $ w += $ this -> table [ $ k ] [ 'border' ] [ 'l' ] [ 'width' ] + $ this -> table [ $ k ] [ 'padding' ] [ 'l' ] + 0.02 ; $ w += $ this -> table [ $ k ] [ 'border' ] [ 'r' ] [ 'width' ] + $ this -> table [ $ k ] [ 'padding' ] [ 'r' ] + 0.02 ; } return $ w ; } } return $ this -> _pdf -> getW ( ) - $ this -> _pdf -> getlMargin ( ) - $ this -> _pdf -> getrMargin ( ) ; } | get the width of the parent |
31,923 | protected function _getLastAbsoluteX ( ) { for ( $ k = count ( $ this -> table ) - 1 ; $ k >= 0 ; $ k -- ) { if ( $ this -> table [ $ k ] [ 'x' ] && $ this -> table [ $ k ] [ 'position' ] ) return $ this -> table [ $ k ] [ 'x' ] ; } return $ this -> _pdf -> getlMargin ( ) ; } | get the last absolute X |
31,924 | protected function _getLastAbsoluteY ( ) { for ( $ k = count ( $ this -> table ) - 1 ; $ k >= 0 ; $ k -- ) { if ( $ this -> table [ $ k ] [ 'y' ] && $ this -> table [ $ k ] [ 'position' ] ) return $ this -> table [ $ k ] [ 'y' ] ; } return $ this -> _pdf -> gettMargin ( ) ; } | get the last absolute Y |
31,925 | protected function _getFromCSS ( ) { $ styles = array ( ) ; $ getit = array ( ) ; $ lst = array ( ) ; $ lst [ ] = $ this -> value [ 'id_lst' ] ; for ( $ i = count ( $ this -> table ) - 1 ; $ i >= 0 ; $ i -- ) { $ lst [ ] = $ this -> table [ $ i ] [ 'id_lst' ] ; } foreach ( $ this -> cssKeys as $ key => $ num ) { if ( $ this -> _getReccursiveStyle ( $ key , $ lst ) ) { $ getit [ $ key ] = $ num ; } } if ( count ( $ getit ) ) { asort ( $ getit ) ; foreach ( $ getit as $ key => $ val ) $ styles = array_merge ( $ styles , $ this -> css [ $ key ] ) ; } return $ styles ; } | get the CSS properties of the current tag |
31,926 | public function readBorder ( $ css ) { $ none = array ( 'type' => 'none' , 'width' => 0 , 'color' => array ( 0 , 0 , 0 ) ) ; $ type = 'solid' ; $ width = $ this -> convertToMM ( '1pt' ) ; $ color = array ( 0 , 0 , 0 ) ; $ css = explode ( ' ' , $ css ) ; foreach ( $ css as $ k => $ v ) { $ v = trim ( $ v ) ; if ( $ v ) $ css [ $ k ] = $ v ; else unset ( $ css [ $ k ] ) ; } $ css = array_values ( $ css ) ; $ res = null ; foreach ( $ css as $ value ) { if ( $ value == 'none' || $ value == 'hidden' ) { return $ none ; } $ tmp = $ this -> convertToMM ( $ value ) ; if ( $ tmp !== null ) { $ width = $ tmp ; } else if ( in_array ( $ value , array ( 'solid' , 'dotted' , 'dashed' , 'double' ) ) ) { $ type = $ value ; } else { $ tmp = $ this -> convertToColor ( $ value , $ res ) ; if ( $ res ) $ color = $ tmp ; } } if ( ! $ width ) return $ none ; return array ( 'type' => $ type , 'width' => $ width , 'color' => $ color ) ; } | Analyse a border |
31,927 | protected function _duplicateBorder ( & $ val ) { if ( count ( $ val ) == 1 ) { $ val [ 1 ] = $ val [ 0 ] ; $ val [ 2 ] = $ val [ 0 ] ; $ val [ 3 ] = $ val [ 0 ] ; } else if ( count ( $ val ) == 2 ) { $ val [ 2 ] = $ val [ 0 ] ; $ val [ 3 ] = $ val [ 1 ] ; } else if ( count ( $ val ) == 3 ) { $ val [ 3 ] = $ val [ 1 ] ; } } | duplicate the borders if needed |
31,928 | public function convertBackgroundPosition ( $ css , & $ res ) { $ res = false ; $ css = explode ( ' ' , $ css ) ; if ( count ( $ css ) < 2 ) { if ( ! $ css [ 0 ] ) return null ; $ css [ 1 ] = 'center' ; } if ( count ( $ css ) > 2 ) return null ; $ x = 0 ; $ y = 0 ; $ res = true ; if ( $ css [ 0 ] == 'left' ) $ x = '0%' ; else if ( $ css [ 0 ] == 'center' ) $ x = '50%' ; else if ( $ css [ 0 ] == 'right' ) $ x = '100%' ; else if ( $ css [ 0 ] == 'top' ) $ y = '0%' ; else if ( $ css [ 0 ] == 'bottom' ) $ y = '100%' ; else if ( preg_match ( '/^[-]?[0-9\.]+%$/isU' , $ css [ 0 ] ) ) $ x = $ css [ 0 ] ; else if ( $ this -> convertToMM ( $ css [ 0 ] ) ) $ x = $ this -> convertToMM ( $ css [ 0 ] ) ; else $ res = false ; if ( $ css [ 1 ] == 'left' ) $ x = '0%' ; else if ( $ css [ 1 ] == 'right' ) $ x = '100%' ; else if ( $ css [ 1 ] == 'top' ) $ y = '0%' ; else if ( $ css [ 1 ] == 'center' ) $ y = '50%' ; else if ( $ css [ 1 ] == 'bottom' ) $ y = '100%' ; else if ( preg_match ( '/^[-]?[0-9\.]+%$/isU' , $ css [ 1 ] ) ) $ y = $ css [ 1 ] ; else if ( $ this -> convertToMM ( $ css [ 1 ] ) ) $ y = $ this -> convertToMM ( $ css [ 1 ] ) ; else $ res = false ; return array ( $ x , $ y ) ; } | parse a background position |
31,929 | public function convertToMM ( $ css , $ old = 0. ) { $ css = trim ( $ css ) ; if ( preg_match ( '/^[0-9\.\-]+$/isU' , $ css ) ) $ css .= 'px' ; if ( preg_match ( '/^[0-9\.\-]+px$/isU' , $ css ) ) $ css = 25.4 / 96. * str_replace ( 'px' , '' , $ css ) ; else if ( preg_match ( '/^[0-9\.\-]+pt$/isU' , $ css ) ) $ css = 25.4 / 72. * str_replace ( 'pt' , '' , $ css ) ; else if ( preg_match ( '/^[0-9\.\-]+in$/isU' , $ css ) ) $ css = 25.4 * str_replace ( 'in' , '' , $ css ) ; else if ( preg_match ( '/^[0-9\.\-]+mm$/isU' , $ css ) ) $ css = 1. * str_replace ( 'mm' , '' , $ css ) ; else if ( preg_match ( '/^[0-9\.\-]+%$/isU' , $ css ) ) $ css = 1. * $ old * str_replace ( '%' , '' , $ css ) / 100. ; else $ css = null ; return $ css ; } | convert a distance to mm |
31,930 | public function convertToRadius ( $ css ) { $ css = explode ( ' ' , $ css ) ; foreach ( $ css as $ k => $ v ) { $ v = trim ( $ v ) ; if ( $ v ) { $ v = $ this -> convertToMM ( $ v , 0 ) ; if ( $ v !== null ) { $ css [ $ k ] = $ v ; } else { unset ( $ css [ $ k ] ) ; } } else { unset ( $ css [ $ k ] ) ; } } return array_values ( $ css ) ; } | convert a css radius |
31,931 | protected function fetchParameters ( $ locationOrArray ) { if ( is_array ( $ locationOrArray ) ) { return $ locationOrArray ; } $ maybeConfig = ConfigFactory :: loadConfigFile ( $ locationOrArray ) ; Validator :: mustBeAnArray ( $ maybeConfig ) ; Validator :: mustNotBeEmpty ( $ maybeConfig ) ; return $ maybeConfig ; } | Fetch the runtime parameters or defaults . |
31,932 | public function set ( $ dotNotationKeys , $ value ) { $ keys = is_array ( $ dotNotationKeys ) ? $ dotNotationKeys : [ $ dotNotationKeys => $ value ] ; foreach ( $ keys as $ key => $ value ) { DotArray :: set ( $ this -> items , $ key , $ value ) ; } } | Set a new value for the given item in the configuration . |
31,933 | protected function checkSources ( $ config , $ defaults = '' ) { Validator :: mustBeStringOrArray ( $ config ) ; Validator :: mustNotBeEmpty ( $ config ) ; if ( is_string ( $ config ) ) { Validator :: mustBeLoadable ( $ config ) ; } if ( empty ( $ defaults ) ) { return ; } Validator :: mustBeStringOrArray ( $ defaults ) ; if ( is_string ( $ defaults ) ) { Validator :: mustBeLoadable ( $ defaults ) ; } } | Checks the sources to ensure loadable . |
31,934 | protected function getParameters ( array $ keys ) { $ parameters = [ ] ; foreach ( $ keys as $ parameterKey => $ default ) { $ parameters [ $ parameterKey ] = $ this -> get ( $ parameterKey , $ default ) ; } return $ parameters ; } | Get multiple configuration parameters . |
31,935 | public function view ( ContentfulEntry $ contentDocument ) : Response { if ( ! $ contentDocument -> getIsPublished ( ) || $ contentDocument -> getIsDeleted ( ) ) { throw new NotFoundHttpException ( ) ; } return $ this -> render ( '@NetgenLayoutsContentful/contentful/content.html.twig' , [ 'content' => $ contentDocument , ] ) ; } | Renders a Contentful entry . |
31,936 | public function webhook ( Request $ request ) : Response { $ content = ( string ) $ request -> getContent ( ) ; $ spaceId = $ request -> headers -> get ( 'X-Space-Id' ) ; $ spaceId = is_array ( $ spaceId ) ? $ spaceId [ 0 ] : $ spaceId ; try { $ client = $ this -> contentful -> getClientBySpaceId ( ( string ) $ spaceId ) ; } catch ( Throwable $ t ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } if ( $ client === null ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } try { $ remoteEntry = $ client -> parseJson ( $ content ) ; } catch ( Throwable $ t ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } switch ( $ request -> headers -> get ( 'X-Contentful-Topic' ) ) { case self :: ENTRY_PUBLISH : if ( ! $ remoteEntry instanceof Entry ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } $ this -> contentful -> refreshContentfulEntry ( $ remoteEntry ) ; break ; case self :: ENTRY_UNPUBLISH : if ( ! $ remoteEntry instanceof DeletedEntry ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } $ this -> contentful -> unpublishContentfulEntry ( $ remoteEntry ) ; break ; case self :: ENTRY_DELETE : if ( ! $ remoteEntry instanceof DeletedEntry ) { throw new BadRequestHttpException ( 'Invalid request' ) ; } $ this -> contentful -> deleteContentfulEntry ( $ remoteEntry ) ; break ; case self :: CONTENT_TYPE_PUBLISH : case self :: CONTENT_TYPE_UNPUBLISH : case self :: CONTENT_TYPE_DELETE : $ this -> contentful -> refreshContentTypeCache ( $ client ) ; break ; default : throw new BadRequestHttpException ( 'Invalid request' ) ; } return new Response ( ) ; } | Contentful webhook for clearing local caches . |
31,937 | protected function replaceContent ( AlSlotContent $ slotContent , $ content ) { $ regex = $ this -> getPattern ( $ slotContent -> getSlotName ( ) ) ; return preg_replace ( $ regex , $ slotContent -> getContent ( ) , $ content ) ; } | Replaces rhe content on the current slot with the new one |
31,938 | static private function _checkData ( $ arr , $ v ) { foreach ( $ arr as $ key => $ value ) { if ( ! is_array ( $ key ) ) { if ( $ res = static :: _checkString ( $ key , $ v ) ) { return $ res ; } } else { if ( $ res = static :: _checkData ( $ key , $ v ) ) { return $ res ; } } if ( ! is_array ( $ value ) ) { if ( $ res = static :: _checkString ( $ value , $ v ) ) { return $ res ; } } else { if ( $ res = static :: _checkData ( $ value , $ v ) ) { return $ res ; } } } return null ; } | check data if safe return null if has unsafe string return unsafe value |
31,939 | private function CheckData ( $ key ) { if ( ! is_array ( $ this -> row ) ) throw new \ BadMethodCallException ( 'MysqliReader has no data. Call Read method or check query.' ) ; if ( ! array_key_exists ( $ key , $ this -> row ) ) throw new \ InvalidArgumentException ( 'Mysqli Reader has no index ' . $ key ) ; if ( $ this -> IsClosed ( ) ) throw new \ BadMethodCallException ( 'MysqliReader is closed.' ) ; } | Checks if key exists and reader not at end or closed . |
31,940 | public function afterResolve ( \ Magento \ Webapi \ Controller \ Rest \ InputParamsResolver $ subject , $ result ) { $ this -> hlpReg -> setRestInputParams ( $ result ) ; return $ result ; } | Save REST input request into Magento registry . |
31,941 | public function init ( Table & $ table ) { $ this -> _table = & $ table ; $ className = str_replace ( '\\' , '.' , get_called_class ( ) ) ; $ path = DATA . 'mapper' . DIRECTORY_SEPARATOR . $ className ; $ save = false ; @ session_start ( ) ; if ( @ $ _SESSION [ 'mapperSave' ] && ! is_readable ( $ path ) ) { $ this -> save ( $ path , $ this -> getClassSettings ( ) ) ; unset ( $ _SESSION [ 'mapperSave' ] ) ; } if ( ! $ this -> tableExists ( $ table ) ) { $ save = $ this -> createTable ( $ table ) ; } else { $ this -> checkModelRequirements ( ) ; $ save = $ this -> isUpToDate ( $ path , $ table ) ; } if ( $ save || ! is_readable ( $ path ) ) $ this -> save ( $ path , $ this -> getClassSettings ( ) ) ; } | Initialize the row |
31,942 | private function checkModelRequirements ( ) { $ reload = false ; $ classAnnots = $ this -> getAnnotations ( ) -> getClass ( ) ; if ( ! empty ( $ classAnnots [ 1 ] ) && is_array ( $ classAnnots [ 1 ] ) ) { foreach ( $ classAnnots [ 1 ] as $ desc ) { if ( strtolower ( substr ( $ desc , 0 , 4 ) ) !== 'dbs\\' ) continue ; $ this -> performClassAnnots ( $ desc ) ; $ reload = true ; } } if ( $ reload ) { @ session_start ( ) ; $ _SESSION [ 'mapperSave' ] = true ; header ( 'Location: //' . $ _SERVER [ 'SERVER_NAME' ] . $ _SERVER [ 'REQUEST_URI' ] ) ; exit ; } } | Checks class annotations for requirements |
31,943 | protected function Autogen ( array $ attrs ) { $ ignore = ! empty ( $ attrs [ 'ignore' ] ) ? explode ( '|' , $ attrs [ 'ignore' ] ) : array ( ) ; $ er = error_reporting ( 0 ) ; ob_start ( ) ; $ classPath = $ this -> openClassForWriting ( ) ; $ methods = '' ; foreach ( $ this -> _table -> getColumns ( ) as $ name => $ attrsRow ) { if ( in_array ( Util :: camelTo_ ( $ name ) , $ ignore ) ) continue ; echo "\r\n" ; echo "\t/**\r\n" ; echo "\t * @DBS\\" . $ this -> fetchColumnProperties ( $ attrsRow ) . "\r\n" ; echo "\t */\r\n" ; echo "\tprotected $" . Util :: _toCamel ( $ name ) . ";\r\n" ; $ methods .= "\r\n" ; $ methods .= "\tpublic function set" . ucfirst ( Util :: _toCamel ( $ name ) ) . '($' . Util :: _toCamel ( $ name ) . ") {\r\n" ; $ methods .= "\t\t" . '$this->' . Util :: _toCamel ( $ name ) . ' = $' . Util :: _toCamel ( $ name ) . ";\r\n" ; $ methods .= "\t\t" . 'return $this;' . "\r\n" ; $ methods .= "\t}\r\n" ; $ methods .= "\r\n" ; $ methods .= "\tpublic function get" . ucfirst ( Util :: _toCamel ( $ name ) ) . "() {\r\n" ; $ methods .= "\t\t" . 'return $this->' . Util :: _toCamel ( $ name ) . ";\r\n" ; $ methods .= "\t}\r\n" ; } echo $ methods . "\r\n" ; echo "}\r\n" ; error_reporting ( $ er ) ; return file_put_contents ( $ classPath , ob_get_clean ( ) ) ; } | Auto generates the class from an existing table in the database |
31,944 | private function parseAttributes ( $ columnName , array $ attrs , $ isCreate = true ) { $ return = $ this -> checkType ( $ columnName , $ attrs ) ; if ( strtolower ( $ attrs [ 'type' ] ) === 'timestamp' && ! isset ( $ attrs [ 'attrs' ] [ 'default' ] ) ) { $ attrs [ 'attrs' ] [ 'default' ] = '"0000-00-00 00:00:00"' ; } if ( isset ( $ attrs [ 'attrs' ] [ 'size' ] ) ) $ return .= '(' . $ attrs [ 'attrs' ] [ 'size' ] . ')' ; if ( isset ( $ attrs [ 'attrs' ] [ 'collation' ] ) ) { if ( ! isset ( $ attrs [ 'attrs' ] [ 'charset' ] ) ) $ attrs [ 'attrs' ] [ 'charset' ] = stristr ( $ attrs [ 'attrs' ] [ 'collation' ] , '_' , true ) ; $ return .= ' CHARACTER SET ' . $ attrs [ 'attrs' ] [ 'charset' ] . ' COLLATE ' . $ attrs [ 'attrs' ] [ 'collation' ] ; } $ return .= ( isset ( $ attrs [ 'attrs' ] [ 'nullable' ] ) && strtolower ( $ attrs [ 'attrs' ] [ 'nullable' ] ) == 'true' ) ? ' NULL' : ' NOT NULL' ; if ( isset ( $ attrs [ 'attrs' ] [ 'default' ] ) ) { if ( strtolower ( $ attrs [ 'type' ] ) === 'boolean' ) { if ( $ attrs [ 'attrs' ] [ 'default' ] === 'true' ) { $ attrs [ 'attrs' ] [ 'default' ] = 1 ; } else { $ attrs [ 'attrs' ] [ 'default' ] = 0 ; } } $ return .= ( trim ( strtolower ( $ attrs [ 'type' ] ) ) == 'timestamp' ) ? ' DEFAULT ' . $ attrs [ 'attrs' ] [ 'default' ] : ' DEFAULT "' . $ attrs [ 'attrs' ] [ 'default' ] . '"' ; } if ( isset ( $ attrs [ 'attrs' ] [ 'autoIncrement' ] ) && $ attrs [ 'attrs' ] [ 'autoIncrement' ] == 'true' ) $ return .= ' AUTO_INCREMENT' ; if ( ! $ isCreate ) { if ( ! empty ( $ attrs [ 'attrs' ] [ 'after' ] ) ) $ return .= ' AFTER `' . $ attrs [ 'attrs' ] [ 'after' ] . '`' ; else if ( isset ( $ attrs [ 'attrs' ] [ 'first' ] ) && $ attrs [ 'attrs' ] [ 'first' ] ) $ return .= ' FIRST' ; } if ( isset ( $ attrs [ 'attrs' ] [ 'onUpdate' ] ) && $ attrs [ 'type' ] !== 'ReferenceMany' ) $ return .= ' ON UPDATE ' . $ attrs [ 'attrs' ] [ 'onUpdate' ] ; return $ return ; } | Prepares attributes of columns for use |
31,945 | private function checkType ( $ columnName , array $ attrs ) { if ( in_array ( strtolower ( $ attrs [ 'type' ] ) , array ( 'string' , 'referencemany' ) ) ) { return ( isset ( $ attrs [ 'attrs' ] [ 'size' ] ) && strtolower ( $ attrs [ 'type' ] ) !== 'referencemany' ) ? 'VARCHAR' : 'TEXT' ; } return strtoupper ( $ attrs [ 'type' ] ) ; } | Checks the column type to ensure it has required settings |
31,946 | private function isUpToDate ( $ path , Table & $ table ) { $ classPath = $ this -> getClassPath ( get_called_class ( ) ) ; $ return = null ; foreach ( class_parents ( get_called_class ( ) ) as $ parent ) { if ( $ parent === get_class ( ) ) break ; $ parent = str_replace ( array ( 'DScribe' , 'DBScribe' , 'DSLive' ) , array ( 'd-scribe/core/src' , 'd-scribe/db-scribe/src' , 'd-scribe/ds-live/src' ) , $ parent ) ; $ parentPath = $ this -> getClassPath ( $ parent ) ; if ( ! is_readable ( $ path ) || ( is_readable ( $ path ) && is_readable ( $ parentPath ) && filemtime ( $ classPath ) < filemtime ( $ parentPath ) ) ) { $ return = $ this -> prepareUpdate ( $ path , $ table ) ; break ; } } if ( $ return === null && ( ! is_readable ( $ path ) || ( is_readable ( $ path ) && @ filemtime ( $ path ) < @ filemtime ( MODULES . str_replace ( '\\' , '/' , get_called_class ( ) ) . '.php' ) ) ) ) { $ return = $ this -> prepareUpdate ( $ path , $ table ) ; } if ( count ( $ this -> getCachedSettings ( ) ) !== count ( $ table -> getColumns ( true ) ) ) { foreach ( $ this -> getModelTable ( $ this -> getTableName ( ) ) as $ class ) { unlink ( DATA . 'mapper' . DIRECTORY_SEPARATOR . str_replace ( '\\' , '.' , $ class ) ) ; } } return ( $ return === null ) ? false : $ return ; } | Checks if the table is uptodate with the mapper settings |
31,947 | private function updateReferences ( Table & $ table ) { $ this -> ignoreThis ( ) ; foreach ( $ table -> getBackReferences ( ) as $ array ) { foreach ( $ array as $ ref ) { if ( in_array ( $ ref [ 'refTable' ] , $ this -> getIgnore ( ) ) ) continue ; $ refTable = new Table ( $ ref [ 'refTable' ] , $ table -> getConnection ( ) ) ; $ modelClass = self :: getModelTable ( $ ref [ 'refTable' ] ) ; if ( ! empty ( $ modelClass ) ) { $ mapper = is_array ( $ modelClass ) ? new $ modelClass [ count ( $ modelClass ) - 1 ] : new $ modelClass ; $ mapper -> setConnection ( $ table -> getConnection ( ) ) ; $ mapper -> init ( $ refTable , $ this -> getIgnore ( ) ) ; } } } } | Updates tables that reference current table |
31,948 | private function checkIndexes ( $ dbColumnName , array $ desc , Table & $ table ) { if ( $ table -> getPrimaryKey ( ) !== $ dbColumnName ) { if ( array_key_exists ( $ dbColumnName , $ table -> getIndexes ( ) ) ) { if ( array_key_exists ( $ dbColumnName , $ table -> getReferences ( ) ) ) { $ table -> dropReference ( $ dbColumnName ) ; } $ table -> dropIndex ( $ dbColumnName ) ; } if ( isset ( $ desc [ 'attrs' ] [ 'index' ] ) ) { $ table -> addIndex ( $ dbColumnName , Table :: INDEX_REGULAR ) ; } else if ( isset ( $ desc [ 'attrs' ] [ 'unique' ] ) ) { $ table -> addIndex ( $ dbColumnName , Table :: INDEX_UNIQUE ) ; } else if ( isset ( $ desc [ 'attrs' ] [ 'fulltext' ] ) ) { $ table -> addIndex ( $ dbColumnName , Table :: INDEX_FULLTEXT ) ; } else { return null ; } $ ref = $ table -> getReferences ( ) ; if ( array_key_exists ( $ dbColumnName , $ ref ) && ! empty ( $ ref [ $ dbColumnName ] [ 'refTable' ] ) ) { $ table -> addReference ( $ dbColumnName , $ ref [ $ dbColumnName ] [ 'refTable' ] , $ ref [ $ dbColumnName ] [ 'refColumn' ] , $ ref [ $ dbColumnName ] [ 'onDelete' ] , $ ref [ $ dbColumnName ] [ 'onUpdate' ] ) ; } } } | Checks if a column should be indexed removing old index and adding new |
31,949 | private function parseAnnotations ( array $ annotations , $ createReference = true ) { $ return = $ defer = $ primary = array ( ) ; $ first = $ prev = null ; foreach ( $ annotations as $ property => $ annotArray ) { if ( ! is_array ( $ annotArray ) ) continue ; foreach ( $ annotArray as & $ desc ) { $ desc = $ this -> parseSettings ( substr ( $ desc , 1 ) ) ; if ( $ prev && ! $ desc [ 'attrs' ] [ 'primary' ] ) { $ desc [ 'attrs' ] [ 'after' ] = $ prev ; } else if ( ! $ prev && ! $ desc [ 'attrs' ] [ 'primary' ] ) { $ desc [ 'attrs' ] [ 'first' ] = true ; $ first = $ property ; } $ prev = Util :: camelTo_ ( $ property ) ; if ( strtolower ( $ desc [ 'type' ] ) === 'reference' || strtolower ( $ desc [ 'type' ] ) === 'referencemany' ) { $ defer [ $ property ] = $ desc ; } if ( isset ( $ desc [ 'attrs' ] [ 'primary' ] ) && $ desc [ 'attrs' ] [ 'primary' ] ) { $ primary [ 'column' ] = $ property ; $ desc [ 'attrs' ] [ 'first' ] = true ; if ( $ first ) { $ return [ $ first ] [ 'attrs' ] [ 'after' ] = Util :: camelTo_ ( $ property ) ; unset ( $ return [ $ first ] [ 'attrs' ] [ 'first' ] ) ; $ first = $ property ; } $ primary [ 'desc' ] = $ desc ; } $ return [ $ property ] = $ desc ; break ; } } foreach ( $ defer as $ property => & $ desc ) { $ desc = $ this -> parseForReference ( $ property , $ desc , $ primary , $ createReference ) ; if ( $ desc [ 'attrs' ] [ 'first' ] && ! $ return [ $ property ] [ 'attrs' ] [ 'first' ] ) unset ( $ desc [ 'attrs' ] [ 'first' ] ) ; if ( $ return [ $ property ] [ 'attrs' ] [ 'after' ] ) $ desc [ 'attrs' ] [ 'after' ] = $ return [ $ property ] [ 'attrs' ] [ 'after' ] ; } $ f = array ( ) ; if ( $ first ) { $ f [ $ first ] = $ return [ $ first ] ; unset ( $ return [ $ first ] ) ; } return array_merge ( $ f , $ return , $ defer ) ; } | Parses the annotations to bring out the required |
31,950 | private function parseSettings ( $ annot ) { $ annot = str_ireplace ( array ( ' (' , ', ' , ', ' , ')' , '"' , "'" ) , array ( '(' , ', ' , ', ' ) , $ annot ) ; $ exp = preg_split ( '[\(]' , $ annot ) ; $ return = array ( 'type' => str_ireplace ( 'dbs\\' , '' , $ exp [ 0 ] ) , 'attrs' => array ( ) , ) ; if ( isset ( $ exp [ 1 ] ) ) { parse_str ( str_replace ( array ( ',' ) , array ( '&' ) , $ exp [ 1 ] ) , $ return [ 'attrs' ] ) ; } $ _return = $ return ; foreach ( $ _return [ 'attrs' ] as $ attr => $ val ) { $ return [ 'attrs' ] [ $ attr ] = trim ( $ val ) ; } return $ return ; } | Parses the settings for all columns |
31,951 | final public function getCachedSettings ( $ property = null ) { if ( $ this -> settings === null ) { $ path = DATA . 'mapper' . DIRECTORY_SEPARATOR . str_replace ( '\\' , '.' , get_called_class ( ) ) ; $ this -> settings = include $ path ; } if ( is_array ( $ this -> settings ) && isset ( $ this -> settings [ $ property ] ) ) return $ this -> settings [ $ property ] ; return $ this -> settings ; } | Fetches the settings for a property |
31,952 | private function save ( $ path , $ annotations ) { if ( ! is_dir ( DATA . 'mapper' ) ) mkdir ( DATA . 'mapper' , 0755 , TRUE ) ; $ content = var_export ( $ annotations , true ) ; file_put_contents ( $ path , '<' . '?php' . "\n\t" . 'return ' . str_replace ( "=> \n" , ' => ' , $ content ) . ";" ) ; $ this -> saveModelTable ( $ this -> getTableName ( ) , get_called_class ( ) ) ; } | Saves the annotations as table schema |
31,953 | private function saveModelTable ( $ tableName , $ modelClass ) { $ modelTables = array ( ) ; $ mt = DATA . 'mapper' . DIRECTORY_SEPARATOR . '__modelTables.php' ; if ( is_readable ( $ mt ) ) $ modelTables = include $ mt ; if ( ! $ modelTables [ $ tableName ] || ( $ modelTables [ $ tableName ] && is_a ( $ this , $ modelTables [ $ tableName ] ) ) ) { $ modelTables [ $ tableName ] = $ modelClass ; return file_put_contents ( $ mt , '<' . '?php' . "\n\t" . 'return ' . stripslashes ( var_export ( $ modelTables , true ) ) . ";" ) ; } return true ; } | Saves table models |
31,954 | public static function getModelTable ( $ tableName ) { $ mt = DATA . 'mapper' . DIRECTORY_SEPARATOR . '__modelTables.php' ; if ( ! is_readable ( $ mt ) ) return array ( ) ; $ modelTables = include $ mt ; if ( isset ( $ modelTables [ $ tableName ] ) ) return $ modelTables [ $ tableName ] ; return array ( ) ; } | Fetches the model class for the given table name |
31,955 | public function postFetch ( $ property = null ) { if ( ! empty ( $ this -> settings ) ) { foreach ( $ this -> settings as $ column => $ descArray ) { if ( $ descArray [ 'type' ] === 'ReferenceMany' ) { if ( is_string ( $ this -> $ column ) && $ newValue = json_decode ( $ this -> $ column , true ) ) $ this -> $ column = $ newValue ; $ this -> $ column = new ArrayCollection ( $ this -> $ column ? explode ( self :: ARRAY_COLLECTION_SEPARATOR , $ this -> $ column ) : array ( ) ) ; } } } parent :: postFetch ( ) ; } | Function to call after fetching row |
31,956 | private function getAnnotations ( $ forceNew = false ) { if ( $ this -> annotations === null || $ forceNew === true ) { $ this -> annotations = new Annotation ( get_called_class ( ) ) ; } return $ this -> annotations ; } | Retrieves the annotations in the mapper class |
31,957 | public function toArray ( $ withNull = false , $ asIs = false ) { $ array = parent :: toArray ( ) ; unset ( $ array [ '_table' ] ) ; if ( $ asIs ) { return $ array ; } $ return = array ( ) ; foreach ( $ array as $ name => $ value ) { if ( ( $ value === null && ! $ withNull ) ) { continue ; } else if ( is_object ( $ value ) && is_a ( $ value , 'DBScribe\ArrayCollection' ) ) $ value = $ value -> getArrayCopy ( ) ; $ return [ \ Util :: camelTo_ ( $ name ) ] = $ value ; } return $ return ; } | Fetches an array of properties and their values |
31,958 | public function mapPartnerToUserRoles ( array $ partnerRoles ) { $ userRoles = array ( ) ; foreach ( $ partnerRoles as $ partnerRole ) { $ userRoles [ ] = $ partnerRole ; if ( $ partnerRole == Partner :: ROLE_EMPLOYEE ) { $ userRoles [ ] = 'ROLE_ADMIN' ; } } return $ userRoles ; } | Map provided partner business roles to FOS user roles |
31,959 | public function migrateUp ( MigrationConfig $ config , $ flushDatabase = false ) { $ migrations = $ this -> instantiateMigrations ( $ config ) ; if ( empty ( $ migrations ) ) { $ skip = false ; } else { $ skip = $ this -> platform -> hasTable ( '#__kk_migrations' ) ; if ( $ skip ) { $ params = [ ] ; $ in = [ ] ; $ mtime = clone $ this -> date ; foreach ( array_values ( $ migrations ) as $ i => $ migration ) { $ in [ ] = ':v' . $ i ; $ params [ 'v' . $ i ] = $ migration -> getVersion ( ) ; $ date = new \ DateTime ( '@' . filemtime ( ( new \ ReflectionClass ( get_class ( $ migration ) ) ) -> getFileName ( ) ) ) ; if ( $ date > $ mtime ) { $ mtime = $ date ; } } $ stmt = $ this -> conn -> prepare ( sprintf ( "SELECT COUNT(*) AS cnt, MAX(`migrated`) AS mtime FROM `#__kk_migrations` WHERE `version` IN (%s)" , implode ( ', ' , $ in ) ) ) ; $ stmt -> bindAll ( $ params ) ; $ stmt -> execute ( ) ; $ row = $ stmt -> fetchNextRow ( ) ; $ dbcnt = ( int ) $ row [ 'cnt' ] ; $ dbmtime = \ DateTime :: createFromFormat ( 'YmdHis' , $ row [ 'mtime' ] ) ; $ skip = ( count ( $ params ) === $ dbcnt ) && ( $ dbmtime > $ mtime ) ; } } if ( ! $ skip ) { if ( $ flushDatabase ) { $ this -> platform -> flushDatabase ( ) ; } foreach ( $ migrations as $ migration ) { $ this -> executeMigrationUp ( $ migration ) ; } } if ( $ skip && $ flushDatabase ) { $ this -> platform -> flushData ( ) ; } } | Execute all up - migrations loaded from the given config . |
31,960 | public static function setDefaultMagicFile ( $ filePath = null ) { if ( ! is_null ( $ filePath ) && ! file_exists ( $ filePath ) ) { throw new FileNotFoundException ( 'File does not exist or is not readable: ' . $ filePath ) ; } self :: $ defaultMagicFile = $ filePath ; } | Inject default magic file to be used on instantiating class . |
31,961 | public function isMimeType ( $ filename , $ mimeType ) { if ( is_array ( $ filename ) ) { $ result = array ( ) ; foreach ( $ filename as $ key => $ value ) { $ result [ ] = ( $ this -> getMimeType ( $ value ) == ( is_array ( $ mimeType ) ? $ mimeType [ $ key ] : $ mimeType ) ) ? true : false ; } return $ result ; } else { return $ this -> getMimeType ( $ filename ) == $ mimeType ? true : false ; } } | Returns the results of the mime type check either as a boolean or an array of boolean values . |
31,962 | static public function extractPagerOptions ( $ data ) { $ options = [ ] ; if ( is_array ( $ data ) ) foreach ( $ data as $ k => $ v ) { if ( in_array ( $ k , [ 'show_style' , 'show_pages' , 'prev_title' , 'next_title' ] ) ) { $ options [ $ k ] = $ v ; } } return $ options ; } | extract pager options from array |
31,963 | public function setUrl ( $ url , $ pattern = "/page/(:num)" ) { $ _pattern = str_replace ( "(:num)" , "([0-9]+)" , $ pattern ) ; preg_match ( "~$_pattern~i" , $ url , $ m ) ; if ( count ( $ m ) == 0 ) { $ pag_ = str_replace ( "(:num)" , 0 , $ pattern ) ; if ( strpos ( $ pattern , "=" ) !== false ) { if ( strpos ( $ url , "?" ) !== false ) { $ url .= "&" . $ pag_ ; } else { $ url .= "?" . $ pag_ ; } return $ this -> setUrl ( $ url , $ pattern ) ; } else if ( strpos ( $ pattern , "/" ) !== false ) { $ url_arr = explode ( "?" , $ url , 2 ) ; $ segment = $ url_arr [ 0 ] ; $ query = isset ( $ url_arr [ 1 ] ) ? $ url_arr [ 1 ] : '' ; if ( strpos ( $ url , "?" ) !== false ) { if ( preg_match ( "/\/$/" , $ segment ) ) { $ url = $ segment . ( preg_replace ( "/^\//" , "" , $ pag_ ) ) ; $ url .= ( ( preg_match ( "/\/$/" , $ pag_ ) ) ? "" : "/" ) . "?{$query}" ; } else { $ url = $ segment . $ pag_ ; $ url .= ( ( preg_match ( "/\/$/" , $ pag_ ) ) ? "" : "/" ) . "?{$query}" ; } } else { if ( preg_match ( "/\/$/" , $ segment ) ) { $ url .= ( preg_replace ( "/^\//" , "" , $ pag_ ) ) ; } else { $ url .= $ pag_ ; } } return $ this -> setUrl ( $ url , $ pattern ) ; } } $ match = current ( $ m ) ; $ last = end ( $ m ) ; $ page = $ last ? $ last : 1 ; $ this -> templateUrl = str_replace ( $ match , preg_replace ( "/[0-9]+/" , "(#pageNumber)" , $ match ) , $ url ) ; $ this -> current ( $ page ) ; return $ this ; } | Set the URL automatically it will parse every thing to it |
31,964 | public function count ( $ count = null ) { if ( $ count === null ) { return isset ( $ this -> options [ 'count' ] ) ? $ this -> options [ 'count' ] : 0 ; } else { $ this -> options [ 'count' ] = $ count ; return $ this ; } } | get or set the items count . It will be used to determined the size of the pagination set |
31,965 | public function pagesize ( $ pagesize = null ) { if ( $ pagesize === null ) { return $ this -> options [ 'pagesize' ] ; } else { $ this -> options [ 'pagesize' ] = intval ( $ pagesize ) ; return $ this ; } } | Set the items pagesize |
31,966 | public function current ( $ page = null ) { if ( $ page === null ) { return $ this -> options [ 'page' ] ; } else { $ this -> options [ 'page' ] = $ page ; return $ this ; } } | Set the current page |
31,967 | public function prevUrl ( ) { $ prev = $ this -> current ( ) - 1 ; return ( $ prev > 0 && $ prev < $ this -> pages ( ) ) ? $ this -> parseUrl ( $ prev ) : "" ; } | Get the previous page url if it exists |
31,968 | public function nextUrl ( ) { $ next = $ this -> current ( ) + 1 ; return ( $ next <= $ this -> pages ( ) ) ? $ this -> parseUrl ( $ next ) : "" ; } | Get the next page url if it exists |
31,969 | public function setTitles ( $ prev = "Prev" , $ next = "Next" ) { $ this -> options [ 'prev_title' ] = $ prev ; $ this -> options [ 'next_title' ] = $ next ; return $ this ; } | To set the previous and next title |
31,970 | public function render ( $ count = 0 ) { $ pagination = "" ; $ items = $ this -> navigation ( $ count ) ; if ( $ items ) foreach ( $ items as $ page ) { $ pagination .= $ this -> item ( $ page [ 'page' ] , $ page [ 'url' ] , $ page [ 'label' ] , $ page [ 'class' ] , $ page [ 'current' ] , false ) ; } $ listPropertiesHtml = "" ; foreach ( $ this -> options [ 'list_properties' ] as $ k => $ v ) { $ listPropertiesHtml .= " $k=\"$v\"" ; } $ html = "<{$this->options['list_tag']}$listPropertiesHtml>{$pagination}</{$this->options['list_tag']}>" ; if ( $ this -> options [ 'container_tag' ] ) { $ containerPropertiesHtml = "" ; foreach ( $ this -> options [ 'container_properties' ] as $ k => $ v ) { $ containerPropertiesHtml .= " $k=\"$v\"" ; } $ html = "<div$containerPropertiesHtml> $html </div>" ; } return $ html ; } | Render the paginator in HTML format |
31,971 | protected function invokeMethod ( $ object , $ method , array $ args = [ ] ) { if ( ! $ method || ! is_string ( $ method ) || '' === $ method ) { throw new InvalidArgumentException ( _ ( 'Missing valid method to invoke.' ) ) ; } try { $ reflection = new ReflectionMethod ( get_class ( $ object ) , $ method ) ; $ ordered_arguments = Helper :: parseParams ( $ reflection -> getParameters ( ) , $ args ) ; return $ reflection -> invokeArgs ( $ object , $ ordered_arguments ) ; } catch ( Exception $ exception ) { throw new InvalidArgumentException ( sprintf ( _ ( 'Failed to invoke method "%1$s" of class "%2$s". Reason: %3$s' ) , $ method , get_class ( $ object ) , $ exception -> getMessage ( ) ) ) ; } } | Check the accepted arguments for a given method and pass associative array values in the right order . |
31,972 | function AddDay ( Day $ day ) { foreach ( $ this -> days as $ currentDay ) { if ( $ currentDay -> DayOfWeek ( ) == $ day -> DayOfWeek ( ) ) return ; } $ this -> days [ ] = $ day ; } | Adds an day to the list if not already added |
31,973 | function RemoveDay ( Day $ day ) { $ result = array ( ) ; foreach ( $ this -> days as $ currentDay ) { if ( $ currentDay -> DayOfWeek != $ day -> DayOfWeek ( ) ) $ result [ ] = $ currentDay ; } $ this -> days = $ result ; } | Removes a day from the list of days if added before |
31,974 | public function getBody ( $ code ) { ob_start ( ) ; $ this -> render ( $ code ) ; $ content = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ content ; } | get image body |
31,975 | private function doRequest ( $ path , $ headers = [ ] ) { if ( ! $ this -> isAvailable ( ) ) { throw new NotAvailableException ( 'Service not available.' ) ; } if ( $ this -> loadBalance !== null ) { $ uri = $ this -> loadBalance -> getUri ( $ this -> serviceName ) ; $ this -> zendClient -> setUri ( $ uri ) ; } if ( $ this -> appendPath && strlen ( $ path ) > 0 && $ this -> zendClient -> getUri ( ) -> getPath ( ) != '/' ) { $ path = $ this -> zendClient -> getUri ( ) -> getPath ( ) . $ path ; } $ this -> zendClient -> getUri ( ) -> setPath ( $ path ) ; $ this -> zendClient -> getRequest ( ) -> getHeaders ( ) -> addHeaders ( $ headers ) ; if ( ! $ this -> zendClient -> getRequest ( ) -> getHeaders ( ) -> has ( 'X-Request-Id' ) ) { $ this -> addRequestId ( ) ; } $ this -> addRequestName ( $ this -> serviceName ) ; $ this -> getEventManager ( ) -> trigger ( 'request.pre' , $ this ) ; $ this -> responseTime = 0 ; try { $ requestTime = microtime ( true ) ; $ zendHttpResponse = $ this -> zendClient -> send ( ) ; $ this -> responseTime = ( float ) sprintf ( '%.2f' , ( microtime ( true ) - $ requestTime ) * 1000 ) ; $ this -> addRequestTime ( $ this -> responseTime ) ; $ response = new Response ( $ this -> zendClient , $ zendHttpResponse , $ this -> depth ) ; $ this -> reportSuccess ( ) ; } catch ( RuntimeException $ ex ) { $ this -> reportFailure ( ) ; $ this -> getEventManager ( ) -> trigger ( 'request.fail' , $ this , $ ex ) ; throw new RuntimeException ( $ ex -> getMessage ( ) , $ ex -> getCode ( ) , $ ex ) ; } catch ( \ Exception $ ex ) { $ this -> reportFailure ( ) ; $ this -> getEventManager ( ) -> trigger ( 'request.fail' , $ this , $ ex ) ; throw new RuntimeException ( $ ex -> getMessage ( ) , 500 , $ ex ) ; } $ this -> getEventManager ( ) -> trigger ( 'request.post' , $ this ) ; $ content = $ response -> getContent ( ) ; return $ content ; } | Perform the request to api server . |
31,976 | public function toString ( ResponseInterface $ response ) { $ string = sprintf ( "HTTP/%s %s %s\n" , $ response -> getProtocolVersion ( ) , $ response -> getStatusCode ( ) , $ response -> getReasonPhrase ( ) ) ; $ string .= $ this -> headersAndBody ( $ response ) ; return $ string ; } | Generate a pretty PS7 response . |
31,977 | public function index ( $ jobId ) { $ job = Job :: findOrFail ( $ jobId ) ; $ this -> authorize ( 'view' , $ job ) ; return $ this -> respondRelatedNotes ( $ jobId , 'job' ) ; } | Produce a list of Notes related to a selected Job |
31,978 | static public function isCacheEnum ( $ enum ) { if ( $ enum && in_array ( $ enum , [ static :: CACHE_NOT , static :: CACHE_AUTO , static :: CACHE_FLUSH , static :: CACHE_FLUSH_ONLY ] ) ) { return true ; } return false ; } | check is cache enum |
31,979 | public static function getInstance ( RuleProviderInterface $ ruleProvider ) { if ( func_num_args ( ) > 1 ) { throw new BadMethodCallException ( 'Method allows only one argument (a rule provider), passing options would void warranty' . ' that requested and returned instance are effectvely identical, saw secondary argument type[' . Utils :: getType ( func_get_arg ( 1 ) ) . '].' ) ; } $ provider_class = get_class ( $ ruleProvider ) ; return static :: $ instanceByValidateClass [ $ provider_class ] ?? ( static :: $ instanceByValidateClass [ $ provider_class ] = new static ( $ ruleProvider ) ) ; } | First object instantiated via this method using that rule provider disregarding which ValidateAgainstRuleSet class called on . |
31,980 | protected function preCheckedEnum ( $ subject , array $ allowedValues ) : bool { if ( $ subject !== null && ! is_scalar ( $ subject ) ) { return false ; } foreach ( $ allowedValues as $ allowed ) { if ( $ subject === $ allowed ) { return true ; } } return false ; } | Enum rule method which doesn t check that all allowed values are scalar|null ; ValidationRuleSet checks that . |
31,981 | protected function value ( $ input ) { $ output = $ input ; if ( is_string ( $ input ) === false ) { switch ( gettype ( $ input ) ) { case 'boolean' : $ output = ( $ input === true ) ? 'true' : 'false' ; break ; case 'integer' : case 'double' : $ output = ( string ) $ input ; break ; case 'object' : case 'array' : case 'resource' : case 'unknown type' : $ output = serialize ( $ input ) ; break ; case 'NULL' : default : break ; } } return $ output ; } | Helper for converting native PHP values in HTML usable ones . |
31,982 | public function offsetUnset ( $ offset ) { $ key = array_search ( $ offset , $ this -> index ) ; $ this -> index [ $ key ] = null ; unset ( $ this -> attributes [ $ offset ] ) ; } | Removes an offset . |
31,983 | public function get ( $ format ) { switch ( $ format ) { case 'json' : return $ this -> toJson ( ) ; break ; case 'serialize' : return $ this -> serialize ( ) ; break ; case 'array' : return $ this -> toArray ( ) ; break ; case 'xml' : return $ this -> toXml ( ) ; break ; default : return $ this ; } } | Returns the result by format |
31,984 | public function toXml ( ) { $ xml = new \ SimpleXMLElement ( '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><parser></parser>' ) ; $ xml -> addChild ( 'fqdn' , $ this -> fqdn ) ; $ xml -> addChild ( 'idn_fqdn' , $ this -> idnFqdn ) ; $ xml -> addChild ( 'domain' , $ this -> domain ) ; $ xml -> addChild ( 'idnDomain' , $ this -> idnDomain ) ; $ xml -> addChild ( 'tld' , $ this -> tld ) ; $ xml -> addChild ( 'idnTld' , $ this -> idnTld ) ; $ xml -> addChild ( 'tldGroup' , $ this -> tldGroup ) ; $ xml -> addChild ( 'validHostname' , $ this -> validHostname ) ; return $ xml -> asXML ( ) ; } | Convert properties to xml by using SimpleXMLElement |
31,985 | public function addEvent ( AbstractEvent $ event ) { $ this -> eventHandlerFactory -> getHandlerForEvent ( $ event ) -> addEvent ( $ event ) ; return $ this ; } | Adds an event to the builder . |
31,986 | public function build ( ) { $ this -> prepareHandlers ( ) ; $ this -> renderedCode = new RenderedCode ( ) ; $ this -> renderedCode -> setDirectives ( $ this -> buildDirectives ( ) ) -> setGlobalCode ( $ this -> buildGlobalCode ( ) ) -> setMainFunction ( $ this -> buildMainFunction ( ) ) ; return $ this ; } | Builds the ManiaScript code . |
31,987 | public function getCode ( ) { $ result = '' ; if ( $ this -> options -> getRenderContextDirective ( ) ) { $ result .= $ this -> renderedCode -> getContextDirective ( ) ; } if ( $ this -> options -> getRenderDirectives ( ) ) { $ result .= $ this -> renderedCode -> getDirectives ( ) ; } if ( $ this -> options -> getRenderGlobalCode ( ) ) { $ result .= $ this -> renderedCode -> getGlobalCode ( ) ; } if ( $ this -> options -> getRenderMainFunction ( ) ) { $ result .= $ this -> renderedCode -> getMainFunction ( ) ; } if ( $ this -> options -> getCompress ( ) ) { $ result = $ this -> compress ( $ result ) ; } if ( $ this -> options -> getIncludeScriptTag ( ) ) { $ result = $ this -> addScriptTag ( $ result ) ; } return $ result ; } | Returns the rendered ManiaScript code . |
31,988 | protected function buildDirectives ( ) { $ result = '' ; foreach ( $ this -> directives as $ directive ) { $ result .= $ directive -> buildCode ( ) ; } return $ result ; } | Builds the directives . |
31,989 | protected function buildGlobalCode ( ) { $ result = '' ; foreach ( $ this -> globalCodes as $ code ) { $ result .= $ code -> getCode ( ) . PHP_EOL ; } return $ result ; } | Builds the global code of the ManiaScript . |
31,990 | protected function buildMainFunction ( ) { $ functionPrefix = $ this -> options -> getFunctionPrefix ( ) ; $ result = 'Void ' . $ functionPrefix . '_Dummy() {}' . PHP_EOL . 'main() {' . PHP_EOL . $ this -> eventHandlerFactory -> getHandler ( 'Load' ) -> getInlineCode ( ) . ' yield;' . PHP_EOL . $ this -> eventHandlerFactory -> getHandler ( 'FirstLoop' ) -> getInlineCode ( ) . $ this -> buildEventLoop ( ) . '}' . PHP_EOL ; return $ result ; } | Builds the main function of the ManiaScript . |
31,991 | protected function buildEventLoop ( ) { $ eventLoop = $ this -> eventHandlerFactory -> getHandler ( 'Loop' ) -> getInlineCode ( ) . $ this -> buildControlHandlerLoop ( ) . $ this -> eventHandlerFactory -> getHandler ( 'Custom' ) -> getInlineCode ( ) . $ this -> eventHandlerFactory -> getHandler ( 'Timer' ) -> getInlineCode ( ) ; $ result = '' ; if ( ! empty ( $ eventLoop ) ) { $ result = ' while(True) {' . PHP_EOL . $ eventLoop . ' yield;' . PHP_EOL . ' }' ; } return $ result ; } | Builds the infinite event loop . |
31,992 | protected function buildControlHandlerLoop ( ) { $ controlHandlerCases = $ this -> buildControlHandlerCases ( ) ; $ result = '' ; if ( ! empty ( $ controlHandlerCases ) ) { $ result = ' foreach (Event in PendingEvents) {' . PHP_EOL . ' switch (Event.Type) {' . PHP_EOL . $ controlHandlerCases . ' }' . PHP_EOL . ' }' . PHP_EOL ; } return $ result ; } | Builds the control handler loop . |
31,993 | protected function buildControlHandlerCases ( ) { $ result = '' ; foreach ( $ this -> eventHandlerFactory -> getAllControlHandlers ( ) as $ handler ) { $ result .= $ handler -> getInlineCode ( ) ; } return $ result ; } | Build the control handler cases . |
31,994 | protected function compress ( $ code ) { $ compressor = new Compressor ( ) ; $ result = $ compressor -> setCode ( $ code ) -> compress ( ) -> getCompressedCode ( ) ; return $ result ; } | Compresses the code . |
31,995 | public static function FromString ( $ url ) { $ parts = \ parse_url ( $ url ) ; $ scheme = isset ( $ parts [ 'scheme' ] ) ? $ parts [ 'scheme' ] : '' ; $ host = isset ( $ parts [ 'host' ] ) ? $ parts [ 'host' ] : '' ; $ port = isset ( $ parts [ 'port' ] ) ? $ parts [ 'port' ] : '' ; $ user = isset ( $ parts [ 'user' ] ) ? $ parts [ 'user' ] : '' ; $ password = isset ( $ parts [ 'pass' ] ) ? $ parts [ 'pass' ] : '' ; $ path = isset ( $ parts [ 'path' ] ) ? $ parts [ 'path' ] : '' ; $ query = isset ( $ parts [ 'query' ] ) ? $ parts [ 'query' ] : '' ; $ fragment = isset ( $ parts [ 'fragment' ] ) ? $ parts [ 'fragment' ] : '' ; return new self ( $ scheme , $ host , $ port , $ user , $ password , $ path , $ query , $ fragment ) ; } | Creates an url from string |
31,996 | public function addRights ( $ value , $ type = 'text' ) { $ element = $ this -> addChild ( 'atom:rights' , 'rights' ) ; $ element -> setContent ( $ value , $ type ) ; return $ element ; } | Add rights . |
31,997 | protected function readFile ( $ file ) { if ( false === file_exists ( $ file ) || false === is_file ( $ file ) ) { throw new Doozr_Di_Exception ( sprintf ( 'Error reading file. File "%s" does not exist or is not a valid file' , $ file ) ) ; } return file_get_contents ( $ file ) ; } | Reads content from given file . |
31,998 | public function hasProperty ( string $ name ) : bool { if ( $ this -> properties -> containValue ( $ this -> environment , $ name ) ) { return true ; } return $ this -> properties -> containValue ( 'config' , $ name ) ; } | checks if property with given name exists |
31,999 | private function sortByPriority ( $ a , $ b ) { $ a = $ a [ '_priority' ] ; $ b = $ b [ '_priority' ] ; if ( $ a == $ b ) { return 0 ; } return ( $ a < $ b ) ? - 1 : 1 ; } | Ordena as entradas dos arquivos pela sua prioridade . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.