idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
9,700
public function setAttributes ( ) { $ attributes = func_get_args ( ) ; if ( count ( $ attributes ) ) { if ( count ( $ attributes ) == 1 && is_array ( $ attributes [ 0 ] ) ) { $ attributes = $ attributes [ 0 ] ; } $ this -> attributes = $ attributes ; } return $ this ; }
Set one or many attributes .
9,701
private static function buildHtml ( & $ html , $ tag_object , $ options , $ tab = 0 ) { self :: checkBuildOptions ( $ options ) ; $ tag_is_special = in_array ( $ tag_object -> getTag ( ) , self :: $ special_tags ) ; $ tag_is_ignored = in_array ( $ tag_object -> getTag ( ) , array_get ( $ options , 'ignore_tags' , [ ] ) ) ; $ ignore_tag = true ; if ( ! isset ( $ options [ 'ignore_tags' ] ) || ! $ tag_is_ignored ) { $ ignore_tag = false ; } elseif ( isset ( $ options [ 'ignore_tags' ] ) && $ tag_is_ignored ) { $ tab -- ; } $ pad = '' ; if ( $ tab > 0 ) { $ pad = str_pad ( $ pad , $ tab * 2 , ' ' , STR_PAD_LEFT ) ; } if ( ! $ ignore_tag ) { if ( $ tag_is_special ) { $ html .= $ pad . trim ( ( string ) $ tag_object ) . "\n" ; } elseif ( ! $ tag_is_special ) { $ html .= $ pad ; $ html .= '<' . $ tag_object -> tag . '' . self :: buildHtmlAttribute ( $ tag_object -> getAttributes ( ) ) . '>' ; $ html .= ( $ tag_object -> use_whitespace ) ? "\n" : '' ; if ( strlen ( $ tag_object -> getText ( ) ) ) { $ html .= ( $ tag_object -> use_whitespace ) ? $ pad . ' ' : '' ; $ html .= $ tag_object -> getText ( ) ; } $ html .= ( $ tag_object -> use_whitespace && strlen ( $ tag_object -> getText ( ) ) ) ? "\n" : '' ; } } if ( ! $ tag_is_special && $ tag_object -> hasChildNodes ( ) ) { foreach ( $ tag_object -> getChildNodes ( ) as $ child_tag_object ) { self :: buildHtml ( $ html , $ child_tag_object , $ options , $ tab + 1 ) ; } } $ pad = '' ; if ( $ tab > 0 ) { $ pad = str_pad ( $ pad , $ tab * 2 , ' ' , STR_PAD_LEFT ) ; } if ( ! $ ignore_tag && ! $ tag_is_special ) { $ html .= ( $ tag_object -> use_whitespace ) ? $ pad : '' ; $ html .= '</' . $ tag_object -> tag . '>' . "\n" ; } }
Build html from this object .
9,702
private static function buildHtmlAttribute ( $ attributes ) { $ html = '' ; foreach ( $ attributes as $ name => $ value ) { $ html .= ' ' . $ name . '="' . $ value . '"' ; $ class_list = explode ( ' ' , $ value ) ; foreach ( $ class_list as $ class_name ) { switch ( $ class_name ) { case 'class' : if ( function_exists ( 'hookAddClassHtmlTag' ) ) { hookAddClassHtmlTag ( $ class_name ) ; } } } } return $ html ; }
Build html attributes from array .
9,703
private static function buildArray ( & $ array , $ tag_object , $ options = [ ] ) { self :: checkBuildOptions ( $ options ) ; if ( in_array ( $ tag_object -> getTag ( ) , self :: $ special_tags ) ) { $ array [ ] = [ trim ( ( string ) $ tag_object ) ] ; } elseif ( ! isset ( $ options [ 'ignore_tags' ] ) || ! in_array ( $ tag_object -> getTag ( ) , $ options [ 'ignore_tags' ] ) ) { $ array [ ] = [ $ tag_object -> getTag ( ) , self :: buildHtmlAttribute ( $ tag_object -> getAttributes ( ) ) , $ tag_object -> getText ( ) , [ ] , ] ; } if ( $ tag_object -> hasChildNodes ( ) ) { if ( isset ( $ options [ 'ignore_tags' ] ) && in_array ( $ tag_object -> getTag ( ) , $ options [ 'ignore_tags' ] ) ) { foreach ( $ tag_object -> getChildNodes ( ) as $ child_tag_object ) { self :: buildArray ( $ array , $ child_tag_object ) ; } return ; } foreach ( $ tag_object -> getChildNodes ( ) as $ child_tag_object ) { $ current_position = count ( $ array ) - 1 ; if ( isset ( $ array [ $ current_position ] [ 3 ] ) && ! is_null ( $ array [ $ current_position ] [ 3 ] ) ) { self :: buildArray ( $ array [ count ( $ array ) - 1 ] [ 3 ] , $ child_tag_object ) ; } } } }
Build an array from this object .
9,704
public static function buildFromArray ( & $ html , $ array , $ tab = 0 ) { $ pad = '' ; if ( $ tab > 0 ) { $ pad = str_pad ( $ pad , $ tab * 2 , ' ' , STR_PAD_LEFT ) ; } if ( ! isset ( $ array [ 1 ] ) ) { $ html .= $ array [ 0 ] . "\n" ; return ; } if ( ! empty ( $ array [ 0 ] ) ) { $ html .= $ pad ; $ html .= '<' . $ array [ 0 ] . $ array [ 1 ] . '>' ; $ html .= "\n" ; } if ( ! empty ( $ array [ 2 ] ) ) { $ html .= $ pad . ' ' ; $ html .= $ array [ 2 ] ; $ html .= "\n" ; } if ( isset ( $ array [ 3 ] ) && is_array ( $ array [ 3 ] ) ) { foreach ( $ array [ 3 ] as $ child_array ) { self :: buildFromArray ( $ html , $ child_array , $ tab + 1 ) ; } } if ( ! empty ( $ array [ 0 ] ) ) { $ html .= $ pad ; $ html .= '</' . $ array [ 0 ] . '>' ; $ html .= "\n" ; } }
Build html from an array .
9,705
public function prepare ( $ options = [ ] ) { if ( request ( ) -> ajax ( ) ) { return $ this -> getArray ( $ options ) ; } return $ this -> getHtml ( $ options ) ; }
Automatically returns the object based on the http request .
9,706
public static function fixNamespaceDeclarations ( $ source ) { if ( ! function_exists ( 'token_get_all' ) || ! self :: $ useTokenizer ) { if ( preg_match ( '/namespace(.*?)\s*;/' , $ source ) ) { $ source = preg_replace ( '/namespace(.*?)\s*;/' , "namespace$1\n{" , $ source ) . "}\n" ; } return $ source ; } $ rawChunk = '' ; $ output = '' ; $ inNamespace = false ; $ tokens = token_get_all ( $ source ) ; for ( reset ( $ tokens ) ; false !== $ token = current ( $ tokens ) ; next ( $ tokens ) ) { if ( is_string ( $ token ) ) { $ rawChunk .= $ token ; } elseif ( in_array ( $ token [ 0 ] , array ( T_COMMENT , T_DOC_COMMENT ) ) ) { continue ; } elseif ( T_NAMESPACE === $ token [ 0 ] ) { if ( $ inNamespace ) { $ rawChunk .= "}\n" ; } $ rawChunk .= $ token [ 1 ] ; while ( ( $ t = next ( $ tokens ) ) && is_array ( $ t ) && in_array ( $ t [ 0 ] , array ( T_WHITESPACE , T_NS_SEPARATOR , T_STRING ) ) ) { $ rawChunk .= $ t [ 1 ] ; } if ( '{' === $ t ) { $ inNamespace = false ; prev ( $ tokens ) ; } else { $ rawChunk = rtrim ( $ rawChunk ) . "\n{" ; $ inNamespace = true ; } } elseif ( T_START_HEREDOC === $ token [ 0 ] ) { $ output .= self :: compressCode ( $ rawChunk ) . $ token [ 1 ] ; do { $ token = next ( $ tokens ) ; $ output .= is_string ( $ token ) ? $ token : $ token [ 1 ] ; } while ( $ token [ 0 ] !== T_END_HEREDOC ) ; $ output .= "\n" ; $ rawChunk = '' ; } elseif ( T_CONSTANT_ENCAPSED_STRING === $ token [ 0 ] ) { $ output .= self :: compressCode ( $ rawChunk ) . $ token [ 1 ] ; $ rawChunk = '' ; } else { $ rawChunk .= $ token [ 1 ] ; } } if ( $ inNamespace ) { $ rawChunk .= "}\n" ; } return $ output . self :: compressCode ( $ rawChunk ) ; }
Adds brackets around each namespace if it s not already the case .
9,707
private static function resolveDependencies ( array $ tree , $ node , \ ArrayObject $ resolved = null , \ ArrayObject $ unresolved = null ) { if ( null === $ resolved ) { $ resolved = new \ ArrayObject ( ) ; } if ( null === $ unresolved ) { $ unresolved = new \ ArrayObject ( ) ; } $ nodeName = $ node -> getName ( ) ; $ unresolved [ $ nodeName ] = $ node ; foreach ( $ tree [ $ nodeName ] as $ dependency ) { if ( ! $ resolved -> offsetExists ( $ dependency -> getName ( ) ) ) { self :: resolveDependencies ( $ tree , $ dependency , $ resolved , $ unresolved ) ; } } $ resolved [ $ nodeName ] = $ node ; unset ( $ unresolved [ $ nodeName ] ) ; return $ resolved ; }
Dependencies resolution .
9,708
public function ls ( $ remote_dir ) { $ dir = "ssh2.sftp://" . $ this -> sftp . $ remote_dir ; $ handle = opendir ( $ dir ) ; $ files = Array ( ) ; while ( false !== ( $ file = readdir ( $ handle ) ) ) { if ( substr ( $ file , 0 , 1 ) != '.' ) { $ files [ ] = $ file ; } } closedir ( $ handle ) ; return $ files ; }
Lists the contents of a remote directory
9,709
public function renameRemoteFile ( $ from , $ to ) { if ( @ ssh2_sftp_rename ( $ this -> sftp , $ from , $ to ) ) { throw new \ Exception ( "Could not rename file from $from to $to" ) ; } return true ; }
Renames remote files
9,710
public function getFileStats ( $ path ) { $ stats = @ ssh2_sftp_stat ( $ this -> sftp , $ path ) ; if ( ! $ stats [ 'size' ] ) { throw new \ Exception ( "Could get file stat: " . $ path ) ; } return $ stats ; }
Gets remote file stats
9,711
public function ssh2SftpSymlink ( $ orig_path , $ symlink_path ) { $ result = @ ssh2_sftp_symlink ( $ this -> sftp , $ orig_path , $ symlink_path ) ; if ( ! $ result ) { throw new \ Exception ( "Could create symlink: " . $ path ) ; } return $ result ; }
Create a symlink on the remote system
9,712
public static function createCache ( $ id , $ location = null , $ storageClass , $ options = array ( ) ) { if ( $ location !== null ) { if ( substr ( $ location , 0 , 1 ) === '/' ) { if ( ( $ realLocation = realpath ( $ location ) ) === false ) { throw new ezcBaseFileNotFoundException ( $ location , 'cache location' , 'Does not exist or is no directory.' ) ; } $ location = $ realLocation ; } foreach ( self :: $ configurations as $ confId => $ config ) { if ( $ config [ 'location' ] === $ location ) { throw new ezcCacheUsedLocationException ( $ location , $ confId ) ; } } } if ( ! ezcBaseFeatures :: classExists ( $ storageClass ) || ! is_subclass_of ( $ storageClass , 'ezcCacheStorage' ) ) { throw new ezcCacheInvalidStorageClassException ( $ storageClass ) ; } self :: $ configurations [ $ id ] = array ( 'location' => $ location , 'class' => $ storageClass , 'options' => $ options , ) ; }
Creates a new cache in the manager . This method is used to create a new cache inside the manager . Each cache has a unique ID to access it during the application runtime . Each location may only be used by 1 cache .
9,713
protected function addRedirectUrlField ( ) { $ previous = URL :: previous ( ) ; if ( ! $ previous || $ previous == URL :: current ( ) ) { return ; } if ( Str :: contains ( $ previous , url ( $ this -> getResource ( ) ) ) ) { $ this -> addHiddenField ( ( new Form \ Field \ Hidden ( static :: PREVIOUS_URL_KEY ) ) -> value ( $ previous ) ) ; } }
Add field for store redirect url after update or store .
9,714
protected function processPlugins ( $ plugins , $ dir ) { foreach ( $ plugins as $ plugin ) { $ this -> addPlugin ( $ plugin , $ dir ) ; } }
Processes plugin definitions
9,715
public function addPlugin ( $ name , $ dir ) { Debug :: enterScope ( $ name ) ; $ hasPlugin = $ hasZfile = false ; try { $ this -> plugins [ $ name ] = $ this -> getLocator ( ) -> locate ( $ name . '/Plugin.php' , $ dir , true ) ; $ this -> pluginPaths [ $ name ] = dirname ( $ this -> plugins [ $ name ] ) ; $ hasPlugin = true ; $ this -> sourceFiles [ ] = $ this -> plugins [ $ name ] ; } catch ( \ InvalidArgumentException $ e ) { } try { $ zFileLocation = $ this -> getLocator ( ) -> locate ( $ name . '/z.yml' , $ dir ) ; $ this -> import ( $ zFileLocation , self :: PLUGIN ) ; if ( ! isset ( $ this -> pluginPaths [ $ name ] ) ) { $ this -> pluginPaths [ $ name ] = dirname ( $ zFileLocation ) ; } else if ( $ this -> pluginPaths [ $ name ] != dirname ( $ zFileLocation ) ) { throw new \ UnexpectedValueException ( "Ambiguous plugin configuration:\n" . "There was a Plugin.php found in {$this->pluginPaths[$name]}, but also a z.yml at $zFileLocation" ) ; } $ hasZfile = true ; $ this -> sourceFiles [ ] = $ zFileLocation ; } catch ( \ InvalidArgumentException $ e ) { } if ( ! $ hasPlugin && ! $ hasZfile ) { throw new \ InvalidArgumentException ( "You need at least either a z.yml or a Plugin.php in the plugin path for '{$name}'" ) ; } Debug :: exitScope ( $ name ) ; }
Add a plugin at the passed location
9,716
protected function callClosureAttributes ( array $ attributes ) { foreach ( $ attributes as & $ attribute ) { $ attribute = $ attribute instanceof Closure ? $ attribute ( $ attributes ) : $ attribute ; } return $ attributes ; }
Evaluate any Closure attributes on the attribute array .
9,717
public function remove ( $ key ) { $ keyGen = $ this -> generateKey ( $ key ) ; $ this -> cache -> remove ( $ keyGen ) ; @ unlink ( $ this -> getFilePath ( $ keyGen ) ) ; }
Removes tempnam file by its key
9,718
public function load ( $ key , \ DateTimeInterface $ updatedAt = null ) { $ keyGen = $ this -> generateKey ( $ key ) ; $ updateDate = $ this -> cache -> load ( $ keyGen ) ; if ( $ updateDate === null || $ updateDate != $ updatedAt ) { if ( $ updateDate ) { $ this -> remove ( $ key ) ; } return null ; } return $ this -> getFilePath ( $ keyGen ) ; }
Loads tempnam file path
9,719
public function save ( $ key , $ data , \ DateTimeInterface $ updatedAt = null ) { $ keyGen = $ this -> generateKey ( $ key ) ; $ path = $ this -> putFile ( $ keyGen , $ data ) ; $ this -> cache -> save ( $ keyGen , $ updatedAt ) ; return $ path ; }
Saves tempnam file and returns its path
9,720
private function clean ( ) { foreach ( Finder :: find ( $ this -> namespace . '*' ) -> from ( $ this -> tempDir ) -> childFirst ( ) as $ entry ) { $ path = ( string ) $ entry ; if ( $ entry -> isDir ( ) ) { continue ; } $ updateDate = $ this -> cache -> load ( $ entry -> getFilename ( ) ) ; if ( $ updateDate === null ) { @ unlink ( $ path ) ; } } return ; }
Cleans unused tempnam files
9,721
public function deliveryAddresses ( $ personId ) { $ deliveryAddresses = $ this -> execute ( self :: HTTP_GET , self :: DOMUSERP_API_PEDIDOVENDA . '/pessoas/' . $ personId . '/enderecosentrega' ) ; return $ deliveryAddresses ; }
Gets the delivery address of the person according to the id passed as parameter
9,722
public function orderDefaultValues ( $ personId ) { $ orderDefaultValues = $ this -> execute ( self :: HTTP_GET , self :: DOMUSERP_API_PEDIDOVENDA . '/pessoas/' . $ personId . '/valoresPadraoPedido' ) ; return $ orderDefaultValues ; }
Gets the order default values of a person according to the person id passed as parameter
9,723
public function addStyle ( $ name , $ properties ) { $ style = $ this -> createElement ( 'ss:Style' ) ; $ style -> setAttribute ( 'ss:ID' , $ name ) ; $ this -> styles -> appendChild ( $ style ) ; $ font = $ this -> createElement ( 'ss:Font' ) ; $ style -> appendChild ( $ font ) ; foreach ( $ properties as $ prop => $ val ) { $ font -> setAttribute ( 'ss:' . $ prop , $ val ) ; } return $ style ; }
Creates a new style node and adds it to the styles section
9,724
public function addWorksheet ( $ title ) { $ worksheet = $ this -> workbook -> appendChild ( $ this -> createElement ( 'Worksheet' ) ) ; $ title = preg_replace ( "/[\\\|:|\/|\?|\*|\[|\]]/" , "" , $ title ) ; $ title = substr ( $ title , 0 , 31 ) ; $ worksheet -> setAttribute ( 'ss:Name' , $ title ) ; $ worksheet -> table = $ worksheet -> appendChild ( $ this -> createElement ( 'Table' ) ) ; $ this -> worksheets [ md5 ( $ title ) ] = $ worksheet ; return $ worksheet ; }
Adds a new worksheet to the workbook
9,725
public function setActiveWorksheet ( $ worksheet ) { if ( is_string ( $ worksheet ) ) { $ worksheet = $ this -> worksheets [ md5 ( $ worksheet ) ] ; } $ this -> active_worksheet = $ worksheet ; return $ worksheet ; }
Sets the active worksheet
9,726
public function setRow ( $ row_index , $ values_arr , $ type = null ) { $ cell = null ; foreach ( $ values_arr as $ col_index => $ val ) { $ cell = $ this -> setCell ( $ col_index + 1 , $ row_index , $ val , $ type ) ; } if ( $ cell ) { return $ cell -> parentNode ; } return false ; }
Sets an entire row of data
9,727
public function setCell ( $ col_index , $ row_index , $ val , $ type = null ) { $ result = $ this -> xpath -> query ( "//Row[@Index='" . $ row_index . "']/Cell[@Index='" . $ col_index . "']/Data" , $ this -> active_worksheet ) ; $ data = $ result -> item ( 0 ) ; $ type = $ type ? $ type : $ this -> getValueType ( $ val ) ; if ( $ data ) { $ data -> setAttribute ( 'ss:Type' , $ type ) ; $ data -> firstChild -> nodeValue = $ val ; } else { $ result = $ this -> xpath -> query ( "//Row[@Index='" . $ row_index . "']" ) ; $ row = $ result -> item ( 0 ) ; if ( ! $ row ) { $ row = $ this -> createElement ( 'Row' ) ; $ this -> active_worksheet -> table -> appendChild ( $ row ) ; $ row -> setAttribute ( 'Index' , $ row_index ) ; } $ result = $ this -> xpath -> query ( "//Row[@Index='" . $ row_index . "']/Cell[@Index='" . $ col_index . "']" , $ row ) ; $ cell = $ result -> item ( 0 ) ; if ( ! $ cell ) { $ cell = $ this -> createElement ( 'Cell' ) ; $ row -> appendChild ( $ cell ) ; $ cell -> setAttribute ( 'Index' , $ col_index ) ; $ data = $ this -> createElement ( 'Data' ) ; $ cell -> appendChild ( $ data ) ; $ data -> setAttribute ( 'ss:Type' , $ type ) ; $ data -> appendChild ( $ this -> createTextNode ( $ val ) ) ; } else { $ data = $ cell -> getElementsByTagName ( 'Data' ) -> item ( 0 ) ; $ data -> setAttribute ( 'ss:Type' , $ type ) ; $ data -> firstChild -> nodeValue = $ val ; } } return $ data -> parentNode ; }
Sets a cell by 1 based column and row index
9,728
public function outputWithHeaders ( $ filename = 'worksheet' ) { $ filename = preg_replace ( '/[^aA-zZ0-9\_\-]/' , '' , $ filename ) ; header ( "Content-Type: application/msexcel; charset=" . $ this -> encoding ) ; header ( "Content-Disposition: inline; filename=\"" . $ filename . ".xlsx\"" ) ; echo $ this -> __toString ( ) ; }
Used to generate the xml with output headers
9,729
protected function getValueType ( $ val ) { $ type = 'String' ; if ( $ this -> auto_convert_types === true && is_numeric ( $ val ) ) { $ type = 'Number' ; } return $ type ; }
Determines value type
9,730
protected function alphaIndexToNumeric ( $ alpha_index ) { preg_match ( "~([A-Z]+)(\d)+~" , $ alpha_index , $ match ) ; $ letters = range ( 'A' , 'Z' ) ; $ letters = array_flip ( $ letters ) ; $ col_index = 0 ; $ strlen = strlen ( $ match [ 1 ] ) ; if ( $ strlen == 1 ) { $ col_index += ( $ letters [ $ match [ 1 ] ] + 1 ) ; } elseif ( $ strlen > 1 ) { $ arr = str_split ( $ match [ 1 ] ) ; $ last = array_pop ( $ arr ) ; foreach ( $ arr as $ letter ) { $ col_index += ( $ letters [ $ letter ] + 1 ) * 26 ; } $ col_index += ( $ letters [ $ last ] + 1 ) ; } return Array ( $ col_index , $ match [ 2 ] ) ; }
Converts Alpha column data to numeric indexes
9,731
public function getMessageType ( ) { $ messageType = static :: types ( ) [ $ this -> type ] ; if ( $ this -> type != static :: INCOMING ) { $ messageType = strtoupper ( $ messageType ) ; } return $ messageType ; }
Get message type
9,732
public function convert ( \ DOMElement $ parent , TraitDescriptor $ trait ) { $ child = new \ DOMElement ( 'trait' ) ; $ parent -> appendChild ( $ child ) ; $ namespace = $ trait -> getNamespace ( ) -> getFullyQualifiedStructuralElementName ( ) ; $ child -> setAttribute ( 'namespace' , ltrim ( $ namespace , '\\' ) ) ; $ child -> setAttribute ( 'line' , $ trait -> getLine ( ) ) ; $ child -> appendChild ( new \ DOMElement ( 'name' , $ trait -> getName ( ) ) ) ; $ child -> appendChild ( new \ DOMElement ( 'full_name' , $ trait -> getFullyQualifiedStructuralElementName ( ) ) ) ; $ this -> docBlockConverter -> convert ( $ child , $ trait ) ; foreach ( $ trait -> getProperties ( ) as $ property ) { $ this -> propertyConverter -> convert ( $ child , $ property ) ; } foreach ( $ trait -> getMethods ( ) as $ method ) { $ this -> methodConverter -> convert ( $ child , $ method ) ; } return $ child ; }
Export the given reflected Trait definition to the provided parent element .
9,733
public static function fromArrayAndSettings ( $ cfg , $ settings , $ artifact = null ) { $ chunkSpecification = new static ( $ cfg , $ settings -> getDirectory ( ) ) ; $ chunkSpecification -> set ( "source" , null ) ; $ chunkSpecification -> set ( "target" , fphp \ Helper \ Path :: join ( $ settings -> getOptional ( "target" , null ) , $ chunkSpecification -> getTarget ( ) ) ) ; return $ chunkSpecification ; }
Creates a chunk specification from a plain settings array . The settings context is taken into consideration to generate paths relative to the settings .
9,734
public function getSpriteWebvttForEpisode ( $ episode , $ player_type = "jwplayer" ) { $ this -> calculateInterval ( $ episode ) ; switch ( $ player_type ) { case 'jwplayer' : return $ this -> getSpriteWebvttForJwPlayer ( $ episode ) ; break ; default : return $ this -> getSpriteWebvttForJwPlayer ( $ episode ) ; break ; } }
returns webvtt formated string for webplayers to display thumbnails
9,735
private function calculateInterval ( $ episode ) { $ max_image = floor ( 65500 / $ this -> sprite_height ) ; $ calculated_interval = ceil ( $ episode -> getDuration ( ) / $ max_image ) ; if ( $ calculated_interval > $ this -> sprite_interval ) { $ this -> sprite_interval = $ calculated_interval ; } }
calculates the interval time for the length of an episode and considers jpeg dimension limit of 65500 px .
9,736
protected function _auto ( $ str ) { $ self = $ this ; return preg_replace_callback ( '/`.*?<(.+?)>.*?`|<(.+?)>/' , function ( $ expr ) use ( $ self ) { if ( empty ( $ expr [ 1 ] ) && parse_url ( $ expr [ 2 ] , PHP_URL_SCHEME ) ) { $ expr [ 2 ] = $ self -> esc ( $ expr [ 2 ] ) ; return '<a href="' . $ expr [ 2 ] . '">' . $ expr [ 2 ] . '</a>' ; } return $ expr [ 0 ] ; } , $ str ) ; }
Auto - convert links
9,737
protected function _code ( $ str ) { $ self = $ this ; return preg_replace_callback ( '/`` (.+?) ``|(?<!\\\\)`(.+?)(?!\\\\)`/' , function ( $ expr ) use ( $ self ) { return '<code>' . $ self -> esc ( empty ( $ expr [ 1 ] ) ? $ expr [ 2 ] : $ expr [ 1 ] ) . '</code>' ; } , $ str ) ; }
Process code span
9,738
function esc ( $ str ) { if ( ! $ this -> special ) $ this -> special = array ( '...' => '&hellip;' , '(tm)' => '&trade;' , '(r)' => '&reg;' , '(c)' => '&copy;' ) ; foreach ( $ this -> special as $ key => $ val ) $ str = preg_replace ( '/' . preg_quote ( $ key , '/' ) . '/i' , $ val , $ str ) ; return htmlspecialchars ( $ str , ENT_COMPAT , Base :: instance ( ) -> get ( 'ENCODING' ) , FALSE ) ; }
Convert characters to HTML entities
9,739
protected function getStatusCodeFromApiProblem ( ApiProblem $ problem ) { $ problemData = $ problem -> toArray ( ) ; $ status = array_key_exists ( 'status' , $ problemData ) ? $ problemData [ 'status' ] : 0 ; if ( $ status < 100 || $ status >= 600 ) { return 500 ; } return $ status ; }
Retrieve the HTTP status from an ApiProblem object
9,740
public static function getSizesFor ( string $ size , string $ type , int $ pageUid ) : array { $ settings = ColumnLayoutUtility :: getColumnLayoutSettings ( $ pageUid ) ; if ( ! array_key_exists ( $ size . '.' , $ settings [ 'sizes.' ] ) ) { throw new Exception ( sprintf ( 'The given size "%s" is not defined in the gridsystem' , $ size ) , 1520324173 ) ; } if ( ! array_key_exists ( $ type , $ settings [ 'sizes.' ] [ $ size . '.' ] ) ) { throw new Exception ( sprintf ( 'The given type "%s" does not exist for size "%s"' , $ type , $ size ) , 1520324252 ) ; } return ColumnLayoutUtility :: processColumnSizes ( $ settings [ 'sizes.' ] [ $ size . '.' ] [ $ type ] , $ settings [ 'columnsCount' ] ) ; }
Calculates the column sizes for the given size and the given size type
9,741
public static function getColumnLayoutSettings ( int $ page ) : array { $ pageTSConfig = BackendUtility :: getPagesTSconfig ( $ page ) ; if ( ! array_key_exists ( 'column_layout.' , $ pageTSConfig [ 'mod.' ] ) ) { throw new Exception ( sprintf ( 'No column layout found for page "%d". Please define the column_layout settings in your page TSConfig.' , $ page ) , 1520323245 ) ; } return $ pageTSConfig [ 'mod.' ] [ 'column_layout.' ] ; }
Returns the column layout configuration from page TSConfig .
9,742
public static function hydrateLayoutConfigFlexFormData ( $ flexFormData ) : array { $ dataStructure = $ flexFormData ; if ( is_string ( $ flexFormData ) ) { $ dataStructure = GeneralUtility :: xml2array ( $ flexFormData ) ; } return array_map ( function ( $ sheet ) { return array_map ( function ( $ field ) { return $ field [ 'vDEF' ] ; } , $ sheet [ 'lDEF' ] ) ; } , $ dataStructure [ 'data' ] ) ; }
Simplify a FlexForm DataStructure array . Removes all unnecessary sheet field or value identifiers .
9,743
public function getCustomerGroup ( ConnectionInterface $ con = null ) { if ( $ this -> aCustomerGroup === null && ( $ this -> id !== null ) ) { $ this -> aCustomerGroup = ChildCustomerGroupQuery :: create ( ) -> findPk ( $ this -> id , $ con ) ; } return $ this -> aCustomerGroup ; }
Get the associated ChildCustomerGroup object
9,744
public function getHostWithPort ( ) { if ( $ this -> hasPort ( ) && ( ! $ this -> hasDefaultPort ( ) || ! $ this -> isPortDefault ( ) ) ) { return $ this -> getHost ( ) . ':' . $ this -> getPort ( ) ; } else { return $ this -> getHost ( ) ; } }
Host including port unless it is the default port for the scheme .
9,745
public function getDefaultPort ( ) { if ( ! $ this -> hasDefaultPort ( ) ) throw new UrlException ( sprintf ( "No default port for URL '%s'" , $ this -> _inputString ) ) ; $ scheme = $ this -> getScheme ( ) ; if ( $ scheme == 'http' ) return 80 ; elseif ( $ scheme == 'https' ) return 443 ; else throw new UrlException ( "No default port for scheme '$scheme'" ) ; }
The default TCP port for the scheme of the URL
9,746
public function getHostRelativeUrl ( ) { $ url = $ this -> getPath ( ) ; if ( $ this -> hasQueryString ( ) ) $ url .= '?' . $ this -> getQueryString ( ) ; if ( $ this -> hasFragmentString ( ) ) $ url .= '#' . $ this -> getFragmentString ( ) ; return $ url ; }
The URL components after the host .
9,747
public function getUrlForPath ( $ path ) { $ fragments = parse_url ( $ path ) ; if ( ! isset ( $ fragments [ 'path' ] ) ) throw new UrlException ( "URL is not a valid path: '$path'" ) ; $ newUrl = clone $ this ; $ newUrl -> _fragments [ 'path' ] = $ fragments [ 'path' ] ; foreach ( array ( 'query' , 'fragment' ) as $ component ) { if ( isset ( $ fragments [ $ component ] ) ) $ newUrl -> _fragments [ $ component ] = $ fragments [ $ component ] ; elseif ( isset ( $ newUrl -> _fragments [ $ component ] ) ) unset ( $ newUrl -> _fragments [ $ component ] ) ; } $ newUrl -> _inputString = $ newUrl -> __toString ( ) ; return $ newUrl ; }
Builds a URL with a different path component
9,748
public function getUrlForHost ( $ host ) { $ newUrl = clone $ this ; $ newUrl -> _fragments [ 'host' ] = $ host ; $ newUrl -> _inputString = $ newUrl -> __toString ( ) ; return $ newUrl ; }
Builds a URL with a different host
9,749
public function getUrlForScheme ( $ scheme ) { $ newUrl = clone $ this ; $ wasDefaultPort = ( $ newUrl -> hasScheme ( ) && $ newUrl -> isPortDefault ( ) ) ; $ newUrl -> _fragments [ 'scheme' ] = $ scheme ; if ( $ wasDefaultPort ) { $ newUrl -> _fragments [ 'port' ] = $ newUrl -> getDefaultPort ( ) ; } $ newUrl -> _inputString = $ newUrl -> __toString ( ) ; return $ newUrl ; }
Builds a URL with a different scheme
9,750
public function getUrlForRelativePath ( $ path ) { return $ this -> getUrlForPath ( $ this -> _joinPathComponents ( $ this -> getPath ( ) , ltrim ( $ path , '/' ) ) ) ; }
Builds a URL with a path component that is relative to the current one
9,751
public function addAuthor ( $ author ) { if ( ! is_array ( $ author ) ) { $ author = [ 'name' => $ author ] ; } $ this -> authors -> add ( ( object ) $ author ) ; }
Add an Author to the feed
9,752
public function render ( ) { $ this -> prepare ( ) ; $ view = $ this -> twig -> render ( sprintf ( '%s.twig.html' , $ this -> format ) , [ 'feed' => $ this ] ) ; return Response :: create ( $ view , 200 , [ 'Content-Type' => "{$this->getContentType()}; charset={$this->charset}" , ] ) ; }
Prepare the feed and if it s valid renders it
9,753
public function setCell ( $ cell , $ value , $ type = "auto" ) { if ( $ type == "auto" ) { $ type = \ gettype ( $ value ) ; } if ( \ is_array ( $ cell ) ) { $ parts [ "row" ] = $ cell [ 0 ] ; $ parts [ "col" ] = $ cell [ 1 ] ; } else { $ parts = $ this -> refToArray ( $ cell ) ; } if ( ! \ is_array ( $ parts ) ) { \ trigger_error ( "Cell reference should be in the format A1 or array(0,0)." , E_USER_ERROR ) ; return false ; } $ row = $ parts [ "row" ] ; $ col = $ parts [ "col" ] ; switch ( $ type ) { case "string" : $ value = \ mb_convert_encoding ( $ value , "Windows-1252" , "UTF-8" ) ; $ length = \ mb_strlen ( $ value , "Windows-1252" ) ; if ( $ length > 255 ) { \ trigger_error ( "String '$value' is too long. " . "Please keep to a max of 255 characters." , E_USER_ERROR ) ; return false ; } $ this -> contents .= \ pack ( "s*" , 0x0204 , 8 + $ length , $ row , $ col , 0x00 , $ length ) ; $ this -> contents .= $ value ; break ; case "integer" : $ this -> contents .= \ pack ( "s*" , 0x0203 , 14 , $ row , $ col , 0x00 ) ; $ this -> contents .= \ pack ( "d" , $ value ) ; break ; } return true ; }
Set the value of an individual cell
9,754
public function setRow ( $ row , $ values ) { if ( ! \ is_array ( $ values ) ) { \ trigger_error ( "Values must be an array." , E_USER_ERROR ) ; return false ; } if ( intval ( $ row ) < 1 ) { \ trigger_error ( "Row number must be an integer greater than 1." , E_USER_ERROR ) ; return false ; } $ i = 0 ; foreach ( $ values as $ value ) { $ this -> setCell ( array ( $ row - 1 , $ i ) , $ value ) ; $ i ++ ; } return true ; }
Set the values for a row
9,755
public function outputWithHeaders ( $ filename = 'output.xls' ) { \ header ( "Expires: " . date ( "r" , 0 ) ) ; \ header ( "Last-Modified: " . gmdate ( "r" ) . " GMT" ) ; \ header ( "Content-Type: application/x-msexcel" ) ; \ header ( "Content-Disposition: attachment; filename=" . $ filename ) ; echo $ this -> __toString ( ) ; }
Stream this file over HTTP
9,756
protected function _sort ( ) { if ( ! isset ( $ this -> _sorts ) || count ( $ this -> _sorts ) === 0 ) { return ; } $ columns = $ this -> _dataGrid -> getActiveColumnsOrdered ( ) ; $ sorts = $ this -> _sorts ; $ sortPosition = $ this -> _sortPositions ; usort ( $ this -> _output , function ( $ a , $ b ) use ( $ columns , $ sortPosition , $ sorts ) { foreach ( $ sortPosition as $ colIndex ) { $ sort = $ sorts [ $ colIndex ] ; $ column = $ columns [ $ colIndex ] ; $ valueA = $ column -> getSortData ( $ a ) ; $ valueB = $ column -> getSortData ( $ b ) ; if ( $ valueA == $ valueB ) { continue ; } $ arr = array ( $ valueA , $ valueB ) ; $ args = array_merge ( array ( & $ arr ) , array ( $ sort -> getDirection ( ) , $ sort -> getType ( ) ) ) ; call_user_func_array ( 'array_multisort' , $ args ) ; return ( $ arr [ 0 ] == $ valueA ) ? - 1 : 1 ; } return 0 ; } ) ; }
Performs an array_multisort based on the sorts defined
9,757
protected function _truncate ( ) { if ( ! $ this -> getLimit ( ) -> isNull ( ) ) { if ( is_null ( $ this -> getLimit ( ) -> getCount ( ) ) ) { $ this -> _output = array_splice ( $ this -> _output , $ this -> getLimit ( ) -> getStart ( ) ) ; } else { $ this -> _output = array_splice ( $ this -> _output , $ this -> getLimit ( ) -> getStart ( ) , $ this -> getLimit ( ) -> getCount ( ) ) ; } } }
Simply splice the array
9,758
private static function mandatory ( $ feature ) { if ( $ feature -> getParent ( ) && $ feature -> getMandatory ( ) ) return Logic :: equiv ( Logic :: is ( $ feature ) , Logic :: is ( $ feature -> getParent ( ) ) ) ; }
Semantics for a mandatory feature . A mandatory feature is selected iff its parent is selected .
9,759
private static function optional ( $ feature ) { if ( $ feature -> getParent ( ) ) return Logic :: implies ( Logic :: is ( $ feature ) , Logic :: is ( $ feature -> getParent ( ) ) ) ; }
Semantics for an optional feature . If an optional feature is selected its parent is selected .
9,760
private static function alternative ( $ feature ) { if ( $ feature -> getAlternative ( ) ) { $ children = array ( ) ; foreach ( $ feature -> getChildren ( ) as $ child ) $ children [ ] = Logic :: is ( $ child ) ; $ alternativeConstraints = array ( ) ; for ( $ i = 0 ; $ i < count ( $ children ) ; $ i ++ ) for ( $ j = 0 ; $ j < $ i ; $ j ++ ) $ alternativeConstraints [ ] = Logic :: not ( Logic :: _and ( $ children [ $ i ] , $ children [ $ j ] ) ) ; return Logic :: _and ( Logic :: equiv ( Logic :: is ( $ feature ) , call_user_func_array ( "\FeaturePhp\Helper\Logic::_or" , $ children ) ) , call_user_func_array ( "\FeaturePhp\Helper\Logic::_and" , $ alternativeConstraints ) ) ; } }
Semantics for a feature that provides an alternative choice . Exactly one child of such a feature is selected .
9,761
private static function _or ( $ feature ) { if ( $ feature -> getOr ( ) ) { $ children = array ( ) ; foreach ( $ feature -> getChildren ( ) as $ child ) $ children [ ] = Logic :: is ( $ child ) ; return Logic :: equiv ( Logic :: is ( $ feature ) , call_user_func_array ( "\FeaturePhp\Helper\Logic::_or" , $ children ) ) ; } }
Semantics for a feature that provides a choice using an inclusive or . At least one child of such a feature is selected .
9,762
private function crossTreeConstraint ( $ rule ) { $ op = $ rule -> getName ( ) ; $ num = $ rule -> count ( ) ; if ( $ op === "eq" && $ num === 2 ) return Logic :: equiv ( $ this -> crossTreeConstraint ( $ rule -> children ( ) [ 0 ] ) , $ this -> crossTreeConstraint ( $ rule -> children ( ) [ 1 ] ) ) ; if ( $ op === "imp" && $ num === 2 ) return Logic :: implies ( $ this -> crossTreeConstraint ( $ rule -> children ( ) [ 0 ] ) , $ this -> crossTreeConstraint ( $ rule -> children ( ) [ 1 ] ) ) ; if ( $ op === "conj" && $ num === 2 ) return Logic :: _and ( $ this -> crossTreeConstraint ( $ rule -> children ( ) [ 0 ] ) , $ this -> crossTreeConstraint ( $ rule -> children ( ) [ 1 ] ) ) ; if ( $ op === "disj" && $ num === 2 ) return Logic :: _or ( $ this -> crossTreeConstraint ( $ rule -> children ( ) [ 0 ] ) , $ this -> crossTreeConstraint ( $ rule -> children ( ) [ 1 ] ) ) ; if ( $ op === "not" && $ num === 1 ) return Logic :: not ( $ this -> crossTreeConstraint ( $ rule -> children ( ) [ 0 ] ) ) ; if ( $ op === "var" && $ num === 0 ) return Logic :: is ( $ this -> model -> getFeature ( ( string ) $ rule ) ) ; throw new ConstraintSolverException ( "unknown operation $op with $num arguments encountered" ) ; }
Transforms a cross - tree constraint from an XML rule to a formula .
9,763
public function dispatch ( $ name , $ event ) { if ( ! $ this -> event_dispatcher ) { return null ; } if ( ! $ this -> event_dispatcher instanceof Dispatcher ) { throw new \ Exception ( 'Expected the event dispatcher to be an instance of phpDocumentor\Event\Dispatcher' ) ; } $ this -> event_dispatcher -> dispatch ( $ name , $ event ) ; }
Dispatches an event to the Event Dispatcher .
9,764
public function logParserError ( $ type , $ code , $ line , $ variables = array ( ) ) { $ message = $ this -> __ ( $ code , $ variables ) ; $ this -> log ( $ message , LogLevel :: ERROR ) ; $ this -> dispatch ( 'parser.log' , LogEvent :: createInstance ( $ this ) -> setMessage ( $ message ) -> setType ( $ type ) -> setCode ( $ code ) -> setLine ( $ line ) ) ; }
Dispatches a parser error to be logged .
9,765
public function __ ( $ message , $ variables = array ( ) ) { if ( ! $ this -> translate ) { return vsprintf ( $ message , $ variables ) ; } $ translator = $ this -> translate ; return vsprintf ( $ translator -> translate ( $ message ) , $ variables ) ; }
Translates the ID or message in the given language .
9,766
public function from ( $ type ) { switch ( $ type ) { case 'ini' : $ this -> data = Ini :: decode ( $ this -> string ) ; break ; case 'json' : $ this -> data = Json :: decode ( $ this -> string ) ; break ; case 'php' : $ this -> data = Php :: decode ( $ this -> string ) ; break ; case 'xml' : $ this -> data = Xml :: decode ( $ this -> string ) ; break ; case 'yml' : case 'yaml' : $ this -> data = Yaml :: decode ( $ this -> string ) ; break ; default : throw new \ Exception ( "Format not supported: " . $ type ) ; } return $ this ; }
Specifies the structure type which the content will be parsed from
9,767
public function to ( $ type ) { switch ( $ type ) { case 'ini' : $ this -> string = Ini :: encode ( $ this -> data ) ; break ; case 'json' : $ this -> string = Json :: encode ( $ this -> data , $ this -> prettyOutput ) ; break ; case 'php' : $ this -> string = Php :: encode ( $ this -> data ) ; break ; case 'xml' : $ this -> string = Xml :: encode ( $ this -> data , $ this -> prettyOutput ) ; break ; case 'yml' : case 'yaml' : $ this -> string = Yaml :: encode ( $ this -> data ) ; break ; default : throw new \ Exception ( "Format not supported: " . $ type ) ; } return $ this -> string ; }
Specifies the format you want to encode the data to
9,768
public function apply ( Builder $ builder ) { $ this -> builder = $ builder ; $ this -> builder -> select ( "{$this->getTableName()}.*" ) ; foreach ( $ this -> filters ( ) as $ name => $ value ) { $ this -> callFilterMethod ( $ name , $ value ) ; } return $ this -> builder ; }
Applies all available filters .
9,769
protected function resolve ( $ column , $ key , $ last , callable $ callback ) { if ( ! strpos ( $ column , '.' ) ) { return $ callback ( "{$last}.{$column}" , $ key ) ; } $ scope = strstr ( $ column , '.' , true ) ; $ singular = str_singular ( $ scope ) ; $ next = substr ( strstr ( $ column , '.' ) , 1 ) ; if ( ! in_array ( $ scope , $ this -> loaded ) ) { $ this -> loaded [ ] = $ scope ; $ this -> builder -> join ( $ scope , "{$last}.{$singular}_id" , "{$scope}.id" ) ; } return $ this -> resolve ( $ next , $ key , $ scope , $ callback ) ; }
Recursively build up the query .
9,770
public function _render ( $ textOnly ) { $ featureNum = count ( $ this -> product -> getConfiguration ( ) -> getSelectedFeatures ( ) ) ; $ fileNum = count ( $ this -> files ) ; $ str = "" ; $ maxLen = fphp \ Helper \ _String :: getMaxLength ( $ this -> files , "getTarget" ) ; if ( $ textOnly ) $ str .= "\nProduct Analysis\n================\n" . "For the given product, $featureNum features were selected and the following $fileNum files were generated:\n\n" ; else { $ str .= "<h2>Product Analysis</h2>" ; $ str .= "<div>" ; $ str .= "<p>For the given product, $featureNum features were selected and the following $fileNum files were generated:</p>" ; $ str .= "<ul>" ; } foreach ( $ this -> files as $ file ) { $ summary = $ file -> getContent ( ) -> getSummary ( ) ; if ( $ textOnly ) { $ str .= sprintf ( "$this->accentColor%-{$maxLen}s$this->defaultColor %s\n" , $ file -> getTarget ( ) , fphp \ Helper \ _String :: truncate ( $ summary ) ) ; } else $ str .= "<li><span class='fileName' onclick='var style = this.parentElement.children[1].style; style.display = style.display === \"block\" ? \"none\" : \"block\";'>" . $ file -> getTarget ( ) . "</span><pre style='font-size: 0.8em; display: none'>" . str_replace ( "\n" , "<br />" , htmlspecialchars ( $ summary ) ) . "</pre>" . "</li>" ; } if ( ! $ textOnly ) { $ str .= "</ul>" ; $ str .= "</div>" ; } $ str .= ( new fphp \ Artifact \ TracingLinkRenderer ( $ this -> tracingLinks ) ) -> render ( $ textOnly ) ; return $ str ; }
Returns the product analysis .
9,771
public function table ( ) { if ( ! $ this -> _properties [ 'table_name' ] ) { $ class = explode ( '\\' , get_called_class ( ) ) ; $ this -> _properties [ 'table_name' ] = Instance :: snakecase ( lcfirst ( end ( $ class ) ) ) ; } return $ this -> _properties [ 'table_name' ] ; }
Return table name
9,772
public function field ( $ name ) { return isset ( $ this -> _properties [ 'fields' ] [ $ name ] ) ? $ this -> _properties [ 'fields' ] [ $ name ] : null ; }
return field alias
9,773
public function get ( $ var ) { return isset ( $ this -> _schema [ 'values' ] [ $ var ] ) ? $ this -> _schema [ 'values' ] [ $ var ] : ( isset ( $ this -> _schema [ 'others' ] [ $ var ] ) ? $ this -> _schema [ 'others' ] [ $ var ] : null ) ; }
Get fields value
9,774
public function findByPK ( ) { $ pk = func_get_args ( ) ; if ( ! $ this -> _properties [ 'primary_key' ] || ! $ pk ) throw new Exception ( sprintf ( self :: E_PrimaryKey , get_called_class ( ) ) , 1 ) ; ! is_array ( reset ( $ pk ) ) || $ pk = array_shift ( $ pk ) ; $ criteria = $ values = array ( ) ; foreach ( $ this -> _properties [ 'primary_key' ] as $ field ) { $ token = ':pk_' . $ field ; $ criteria [ ] = '{table}.' . $ field . '=' . $ token ; $ values [ $ token ] = isset ( $ pk [ $ field ] ) ? $ pk [ $ field ] : array_shift ( $ pk ) ; } return $ this -> limit ( 1 ) -> find ( implode ( ' and ' , $ criteria ) , $ values ) ; }
Find by PK
9,775
public function pkValue ( ) { if ( $ args = func_get_args ( ) ) { ! is_array ( $ args [ 0 ] ) || $ args = array_shift ( $ args ) ; $ args = array_values ( $ args ) ; foreach ( $ args as $ key => $ arg ) $ this -> { $ this -> _properties [ 'primary_key' ] [ $ key ] } = $ arg ; return $ this ; } $ pk = array_intersect_key ( $ this -> _schema [ 'values' ] , array_fill_keys ( $ this -> _properties [ 'primary_key' ] , null ) ) ; return count ( $ pk ) == 0 ? null : ( count ( $ pk ) == 1 ? array_shift ( $ pk ) : $ pk ) ; }
Get PK Value
9,776
public function generatePK ( ) { $ format = $ this -> pkFormat ; $ pk = $ this -> _properties [ 'primary_key' ] ; if ( isset ( $ pk [ 1 ] ) ) throw new Exception ( sprintf ( self :: E_Composit , get_called_class ( ) , __FUNCTION__ ) , 1 ) ; $ pk = array_shift ( $ pk ) ; if ( ! $ pk ) throw new Exception ( sprintf ( self :: E_PrimaryKey , get_called_class ( ) ) , 1 ) ; $ last = ( int ) $ this -> select ( ( $ format [ 'serial' ] ? 'right(' . $ pk . ', ' . $ format [ 'serial' ] . ')' : $ pk ) . ' as last' ) -> order ( $ pk . ' desc' ) -> read ( 1 ) -> last ; if ( preg_match ( '/\{(?<date>.+)\}/' , $ format [ 'prefix' ] , $ match ) ) $ newPK = preg_replace ( '/\{.+\}/' , date ( $ match [ 'date' ] ) , $ format [ 'prefix' ] ) ; else $ newPK = $ format [ 'prefix' ] ; $ newPK .= trim ( str_pad ( $ last + 1 , $ format [ 'serial' ] , $ format [ 'prefix' ] ? '0' : ' ' , STR_PAD_LEFT ) ) ; return $ newPK ; }
Generate PK only if pk count = 1
9,777
public function unique ( $ criteria = null , array $ values = array ( ) ) { if ( ! $ this -> _properties [ 'primary_key' ] || ( ! $ values && ! $ criteria ) ) throw new Exception ( sprintf ( self :: E_PrimaryKey , get_called_class ( ) ) , 1 ) ; $ that = clone $ this ; $ values ? $ that -> find ( $ criteria , $ values ) : $ that -> findByPK ( $ criteria ) ; return ( $ that -> dry ( ) || $ this -> pkCompare ( $ that -> pkValue ( ) ) ) ; }
Check not existance
9,778
public function next ( ) { if ( ! $ this -> hasError ( ) ) { $ row = $ this -> _stmt -> fetch ( $ this -> _schema [ 'fetch' ] ) ; $ this -> assign ( $ row ? : array_fill_keys ( array_keys ( $ this -> _properties [ 'fields' ] ) , null ) ) ; } return $ this ; }
get next row and assign row to schema values
9,779
public function read ( $ limit = 0 ) { $ this -> limit ( $ limit ) ; $ query = $ this -> buildSelect ( ) ; $ this -> run ( $ query [ 'query' ] , $ query [ 'param' ] ) ; return $ this -> next ( ) ; }
perform select query
9,780
public function insert ( array $ data = array ( ) , $ update = false ) { $ this -> viewCheck ( __FUNCTION__ ) ; $ data = array_merge ( $ this -> _schema [ 'init' ] , array_filter ( $ this -> _schema [ 'values' ] , array ( $ this , 'filterRule' ) ) , array_filter ( $ this -> _schema [ 'others' ] , array ( $ this , 'filterRule' ) ) , $ data ) ; $ params = array ( ) ; foreach ( $ data as $ key => $ value ) if ( in_array ( $ key , $ this -> _properties [ 'primary_key' ] ) && ! $ value ) continue ; elseif ( is_array ( $ value ) ) return false ; elseif ( isset ( $ this -> _properties [ 'fields' ] [ $ key ] ) ) $ params [ ':' . $ key ] = $ value ; if ( empty ( $ params ) || ( $ update && ! $ this -> _properties [ 'primary_key' ] ) ) return false ; $ query = $ this -> buildInsert ( $ params , $ update ) ; if ( ! ( $ query && $ this -> validate ( $ params ) ) ) return false ; $ old = clone $ this ; if ( ! $ this -> beforeInsert ( $ params ) ) return false ; if ( $ result = $ this -> run ( $ query , $ params ) ) $ this -> assign ( $ params ) ; if ( ! $ this -> afterInsert ( $ old ) ) return false ; return $ result ; }
Insert on duplicate key update
9,781
public function update ( array $ data = array ( ) , array $ criteria = array ( ) ) { $ this -> viewCheck ( __FUNCTION__ ) ; $ data = array_merge ( array_filter ( $ this -> _schema [ 'others' ] , array ( $ this , 'filterRule' ) ) , $ data ) ; $ params = array ( ) ; $ values = array_filter ( $ this -> _schema [ 'values' ] ) ; $ others = array_filter ( $ this -> _schema [ 'others' ] ) ; foreach ( $ data as $ key => $ value ) if ( is_array ( $ value ) ) return false ; elseif ( isset ( $ this -> _properties [ 'fields' ] [ $ key ] ) ) if ( isset ( $ values [ $ key ] ) && isset ( $ others [ $ key ] ) && $ values [ $ key ] == $ others [ $ key ] ) continue ; else $ params [ ':' . $ key ] = $ value ; if ( empty ( $ params ) ) return true ; $ query = $ this -> buildUpdate ( $ params , $ criteria ) ; if ( ! ( $ query && $ this -> validate ( $ params ) ) ) return false ; $ old = clone $ this ; if ( ! $ this -> beforeUpdate ( $ params ) ) return false ; if ( $ result = $ this -> run ( $ query , $ params ) ) $ this -> assign ( $ params ) ; if ( ! $ this -> afterUpdate ( $ old ) ) return false ; return $ result ; }
Update only when there is primary key
9,782
public function delete ( array $ criteria = [ ] ) { $ this -> viewCheck ( __FUNCTION__ ) ; $ query = $ this -> buildDelete ( $ criteria ) ; $ old = clone $ this ; if ( ! $ this -> beforeDelete ( $ criteria ) ) return false ; if ( $ result = $ this -> run ( $ query , $ criteria ) ) $ this -> next ( ) ; if ( ! $ this -> afterDelete ( $ old ) ) return false ; return $ result ; }
delete only when there is primary key
9,783
protected function performValidate ( $ key , & $ value ) { if ( ! $ filter = $ this -> _schema [ 'filter' ] [ $ key ] ) return true ; $ validation = Validation :: instance ( ) ; $ moe = Base :: instance ( ) ; $ field = $ this -> _properties [ 'fields' ] [ $ key ] ; foreach ( $ filter as $ func => $ param ) { if ( is_numeric ( $ func ) ) { $ func = $ param ; $ args = array ( ) ; } else $ args = [ $ param ] ; $ function = $ func ; if ( method_exists ( $ validation , $ func ) ) $ func = array ( $ validation , $ func ) ; elseif ( method_exists ( $ this , $ func ) || preg_match ( '/^(' . self :: Magic . ')/' , $ func ) ) $ func = array ( $ this , $ func ) ; elseif ( method_exists ( $ moe , $ func ) ) $ func = array ( $ moe , $ func ) ; array_unshift ( $ args , $ value ) ; if ( false === $ result = $ moe -> call ( $ func , $ args ) ) { $ this -> _messages [ ] = $ validation -> message ( $ function , $ field , $ value , $ param ) ; return false ; } else is_bool ( $ result ) || $ value = $ result ; } return true ; }
Perform validation We can use method in Base class or any method with full name call but you need to define a message to override default message Be aware when use a method
9,784
static function grabFunctionParameters ( $ class , $ function , array $ paramValues ) { $ declaredParams = ( new \ ReflectionMethod ( $ class , $ function ) ) -> getParameters ( ) ; $ paramNames = array_map ( function ( \ ReflectionParameter $ v ) { return $ v -> getName ( ) ; } , $ declaredParams ) ; $ paramDefaults = array_map ( function ( \ ReflectionParameter $ v ) { return $ v -> isOptional ( ) ? $ v -> getDefaultValue ( ) : null ; } , $ declaredParams ) ; return array_combine ( $ paramNames , array_replace ( $ paramDefaults , $ paramValues ) ) ; }
Return array keyed by parameter name of values passed into a class static function
9,785
public function onKernelRequest ( GetResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; foreach ( $ this -> firewalls as $ firewall ) { if ( true === $ firewall -> check ( $ request ) ) { return ; } } }
Respond to a REQUEST KernelEvent by validating the request against the registered firewalls .
9,786
public function getRelativeFileTarget ( $ aspectKernelTarget ) { return fphp \ Helper \ Path :: join ( fphp \ Helper \ Path :: rootPath ( dirname ( $ aspectKernelTarget ) ) , $ this -> fileSpecification -> getTarget ( ) ) ; }
Returns the path of the aspect s target file relative to the aspect kernel s target file .
9,787
public function getClassName ( ) { $ fileSource = $ this -> fileSpecification -> getSource ( ) ; return ( new fphp \ Helper \ PhpParser ( ) ) -> parseFile ( $ fileSource ) -> getExactlyOneClass ( $ fileSource ) -> name ; }
Returns the aspect s class name . For this the aspect s file has to be parsed .
9,788
private function register_ajax_script ( ) { return $ this -> register_script_common ( function ( ) { return [ 'endpoint' => $ this -> apply_filters ( 'admin_ajax' , admin_url ( 'admin-ajax.php' ) ) , 'nonce_key' => $ this -> get_nonce_key ( ) , 'nonce_value' => $ this -> create_nonce ( ) , 'is_admin_ajax' => true , ] ; } ) ; }
register script for admin - ajax . php
9,789
public static function getGlobalValue ( $ name ) { return array_key_exists ( $ name , self :: $ globalValues ) ? self :: $ globalValues [ $ name ] : null ; }
Get global substitution value
9,790
protected function invoke ( $ method_name , $ request_method , array $ arguments = [ ] ) { $ method_name = strtolower ( $ request_method ) . '_' . $ this -> str -> to_snake_case ( $ method_name ) ; if ( ! is_callable ( [ $ this , $ method_name ] ) ) { return false ; } $ reflection = new \ ReflectionMethod ( $ this , $ method_name ) ; if ( ! $ reflection -> isPublic ( ) || $ reflection -> isStatic ( ) ) { return false ; } if ( $ reflection -> getNumberOfRequiredParameters ( ) > count ( $ arguments ) ) { return false ; } $ this -> handle_result ( call_user_func_array ( [ $ this , $ method_name ] , $ arguments ) ) ; return true ; }
Search method and execute if exists .
9,791
public function convert_to_array ( $ raw_data ) { $ xml = new \ SimpleXMLElement ( $ raw_data ) ; $ xml -> registerXPathNamespace ( self :: XML_NAMESPACE , self :: XML_NAMESPACE_URL ) ; $ data = $ xml -> xpath ( self :: XPATH_CURRENCY ) ; $ currencies = array ( ) ; foreach ( $ data as $ currency ) { $ currencies [ ( string ) $ currency -> attributes ( ) -> currency ] = ( string ) $ currency -> attributes ( ) -> rate ; } return $ currencies ; }
Convert raw currency data to array of currencies
9,792
public function indexLocale ( string $ projectKey , string $ localeId , array $ params = [ ] ) { if ( isset ( $ params [ 'tags' ] ) ) { $ params [ 'q' ] = 'tags:' . $ params [ 'tags' ] ; unset ( $ params [ 'tags' ] ) ; } $ response = $ this -> httpGet ( sprintf ( '/api/v2/projects/%s/locales/%s/translations' , $ projectKey , $ localeId ) , $ params ) ; if ( ! $ this -> hydrator ) { return $ response ; } if ( $ response -> getStatusCode ( ) !== 200 && $ response -> getStatusCode ( ) !== 201 ) { $ this -> handleErrors ( $ response ) ; } return $ this -> hydrator -> hydrate ( $ response , Index :: class ) ; }
Index a locale .
9,793
public function create ( string $ projectKey , string $ localeId , string $ keyId , string $ content , array $ params = [ ] ) { $ params [ 'locale_id' ] = $ localeId ; $ params [ 'key_id' ] = $ keyId ; $ params [ 'content' ] = $ content ; $ response = $ this -> httpPost ( sprintf ( '/api/v2/projects/%s/translations' , $ projectKey ) , $ params ) ; if ( ! $ this -> hydrator ) { return $ response ; } if ( $ response -> getStatusCode ( ) !== 200 && $ response -> getStatusCode ( ) !== 201 ) { $ this -> handleErrors ( $ response ) ; } return $ this -> hydrator -> hydrate ( $ response , TranslationCreated :: class ) ; }
Create a translation .
9,794
public function update ( string $ projectKey , string $ translationId , string $ content , array $ params = [ ] ) { $ params [ 'content' ] = $ content ; $ response = $ this -> httpPatch ( sprintf ( '/api/v2/projects/%s/translations/%s' , $ projectKey , $ translationId ) , $ params ) ; if ( ! $ this -> hydrator ) { return $ response ; } if ( $ response -> getStatusCode ( ) !== 200 && $ response -> getStatusCode ( ) !== 201 ) { $ this -> handleErrors ( $ response ) ; } return $ this -> hydrator -> hydrate ( $ response , TranslationUpdated :: class ) ; }
Update a translation .
9,795
public function indexKey ( string $ projectKey , string $ keyId , array $ params = [ ] ) { if ( isset ( $ params [ 'tags' ] ) ) { $ params [ 'q' ] = 'tags:' . $ params [ 'tags' ] ; unset ( $ params [ 'tags' ] ) ; } $ response = $ this -> httpGet ( sprintf ( '/api/v2/projects/%s/keys/%s/translations' , $ projectKey , $ keyId ) , $ params ) ; if ( ! $ this -> hydrator ) { return $ response ; } if ( $ response -> getStatusCode ( ) !== 200 && $ response -> getStatusCode ( ) !== 201 ) { $ this -> handleErrors ( $ response ) ; } return $ this -> hydrator -> hydrate ( $ response , Index :: class ) ; }
List translations for a specific key .
9,796
protected function transformTranslation ( LocaleAwareInterface $ translation , $ fields , & $ values ) { foreach ( $ fields as $ field ) { $ values [ $ translation -> getLocale ( ) ] [ $ field ] = $ this -> propertyAccessor -> getValue ( $ translation , $ field ) ; } }
Transforms single translation
9,797
private function isOAuth2 ( RequestInterface $ request , array $ options ) { if ( ! isset ( $ options [ 'auth' ] ) || $ options [ 'auth' ] !== 'oauth2' ) { return false ; } if ( $ this -> provider -> getBaseAccessTokenUrl ( [ ] ) === $ request -> getUri ( ) ) { return false ; } return true ; }
Check if a request is configured to use OAuth2 .
9,798
private function authenticateRequest ( RequestInterface $ request , AccessToken $ token ) { foreach ( $ this -> provider -> getHeaders ( $ token -> getToken ( ) ) as $ name => $ value ) { $ request = $ request -> withHeader ( $ name , $ value ) ; } return $ request ; }
Add authentication to an HTTP request .
9,799
private function getAccessToken ( AccessToken $ invalid = null ) { if ( ! isset ( $ this -> accessToken ) || $ this -> accessToken -> hasExpired ( ) || ( $ invalid && $ this -> accessToken === $ invalid ) ) { $ this -> accessToken = $ this -> acquireAccessToken ( ) ; if ( is_callable ( $ this -> tokenSave ) ) { call_user_func ( $ this -> tokenSave , $ this -> accessToken ) ; } } return $ this -> accessToken ; }
Get the current access token .