idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
50,300
public function reverse_left_and_right_4value_shorthands ( $ property , $ value ) { $ shorthands = & $ this -> parser -> data [ 'csstidy' ] [ 'shorthands' ] ; if ( isset ( $ shorthands [ $ property ] ) ) { $ property_right = $ shorthands [ $ property ] [ 1 ] ; $ property_left = $ shorthands [ $ property ] [ 3 ] ; $ v = $ this -> dissolve_4value_shorthands ( $ property , $ value ) ; if ( $ v [ $ property_left ] !== $ v [ $ property_right ] ) { $ r = $ v [ $ property_right ] ; $ v [ $ property_right ] = $ v [ $ property_left ] ; $ v [ $ property_left ] = $ r ; $ v = $ this -> merge_4value_shorthands ( $ v ) ; if ( isset ( $ v [ $ property ] ) ) { return $ v [ $ property ] ; } } } return $ value ; }
Reversing 4 values shorthands properties
50,301
public function reverse_left_and_right_4value_radius_shorthands ( $ property , $ value ) { $ shorthands = & $ this -> parser -> data [ 'csstidy' ] [ 'radius_shorthands' ] ; if ( isset ( $ shorthands [ $ property ] ) ) { $ v = $ this -> dissolve_4value_radius_shorthands ( $ property , $ value ) ; if ( $ v [ $ shorthands [ $ property ] [ 0 ] ] !== $ v [ $ shorthands [ $ property ] [ 1 ] ] or $ v [ $ shorthands [ $ property ] [ 2 ] ] !== $ v [ $ shorthands [ $ property ] [ 3 ] ] ) { $ r = array ( $ shorthands [ $ property ] [ 0 ] => $ v [ $ shorthands [ $ property ] [ 1 ] ] , $ shorthands [ $ property ] [ 1 ] => $ v [ $ shorthands [ $ property ] [ 0 ] ] , $ shorthands [ $ property ] [ 2 ] => $ v [ $ shorthands [ $ property ] [ 3 ] ] , $ shorthands [ $ property ] [ 3 ] => $ v [ $ shorthands [ $ property ] [ 2 ] ] , ) ; $ v = $ this -> merge_4value_radius_shorthands ( $ r ) ; if ( isset ( $ v [ $ property ] ) ) { return $ v [ $ property ] ; } } } return $ value ; }
Reversing 4 values radius shorthands properties
50,302
public function reverse_left_and_right_background ( $ value ) { $ values = $ this -> dissolve_short_bg ( $ value ) ; if ( isset ( $ values [ 'background-position' ] ) and $ values [ 'background-position' ] ) { $ v = $ this -> reverse_left_and_right_background_position ( $ values [ 'background-position' ] ) ; if ( $ v !== $ values [ 'background-position' ] ) { if ( $ value == $ values [ 'background-position' ] ) { return $ v ; } else { $ values [ 'background-position' ] = $ v ; $ x = $ this -> merge_bg ( $ values ) ; if ( isset ( $ x [ 'background' ] ) ) { return $ x [ 'background' ] ; } } } } return $ value ; }
Reversing background shorthands
50,303
public function reverse_left_and_right_background_position ( $ value ) { if ( strpos ( $ value , ',' ) !== false ) { $ values = $ this -> explode_ws ( ',' , $ value ) ; if ( count ( $ values ) > 1 ) { foreach ( $ values as $ k => $ v ) { $ values [ $ k ] = $ this -> reverse_left_and_right_background_position ( $ v ) ; } return implode ( ',' , $ values ) ; } } if ( stripos ( $ value , 'left' ) === false and stripos ( $ value , 'right' ) === false ) { $ values = $ this -> explode_ws ( ' ' , trim ( $ value ) ) ; $ values = array_map ( 'trim' , $ values ) ; $ values = array_filter ( $ values ) ; $ values = array_values ( $ values ) ; if ( count ( $ values ) == 1 ) { return "left $value" ; } if ( $ values [ 1 ] == 'top' or $ values [ 1 ] == 'bottom' ) { return 'left ' . implode ( ' ' , $ values ) ; } else { $ last = array_pop ( $ values ) ; return implode ( ' ' , $ values ) . ' left ' . $ last ; } } return $ value ; }
Reversing background position shorthands
50,304
protected function hydrateAssociations ( $ entity , $ data ) { if ( isset ( $ data [ 'relationships' ] ) && is_array ( $ data [ 'relationships' ] ) ) { $ metadata = $ this -> entityManager -> getClassMetadata ( get_class ( $ entity ) ) ; foreach ( $ data [ 'relationships' ] as $ name => $ data ) { if ( ! isset ( $ metadata -> associationMappings [ $ name ] ) ) { throw new \ Exception ( sprintf ( 'Relation `%s` association not found' , $ name ) ) ; } $ mapping = $ metadata -> associationMappings [ $ name ] ; if ( is_array ( $ data [ 'data' ] ) ) { if ( $ resourceId = $ this -> getResourceId ( $ data [ 'data' ] ) ) { $ this -> hydrateToOneAssociation ( $ entity , $ name , $ mapping , $ resourceId ) ; } else { $ this -> hydrateToManyAssociation ( $ entity , $ name , $ mapping , $ this -> mapRelationshipsArray ( $ data [ 'data' ] ) ) ; } } } } return $ entity ; }
Map JSON API resource relations to doctrine entity .
50,305
public function isApprovalRequired ( $ key ) { if ( $ this -> isApprovalNotRequired ( $ key ) ) { return false ; } if ( in_array ( $ key , $ this -> approvalRequired ( ) ) || $ this -> approvalRequired ( ) == [ '*' ] ) { return true ; } return ! empty ( $ this -> approvalNotRequired ( ) ) ; }
Determine if modification of the given attribute requires approval
50,306
public function selectSubjects ( ) { $ this -> defaultData ( ) ; $ memberProperty = $ this -> getProperty ( GroupsService :: PROPERTY_MEMBERS_URI ) ; $ memberForm = tao_helpers_form_GenerisTreeForm :: buildTree ( $ this -> getCurrentInstance ( ) , $ memberProperty ) ; $ memberForm -> setData ( 'title' , __ ( 'Select group test takers' ) ) ; $ this -> setData ( 'tree' , $ memberForm -> render ( ) ) ; $ this -> setView ( 'sas' . DIRECTORY_SEPARATOR . 'generisTreeSelect.tpl' , 'tao' ) ; }
Render the tree to select the group related subjects
50,307
public function isGroupClass ( core_kernel_classes_Class $ clazz ) { return $ clazz -> equals ( $ this -> getRootClass ( ) ) || $ clazz -> isSubClassOf ( $ this -> getRootClass ( ) ) ; }
Check if the Class in parameter is a subclass of the Group Class
50,308
public function getGroups ( User $ user ) { $ groups = $ user -> getPropertyValues ( self :: PROPERTY_MEMBERS_URI ) ; array_walk ( $ groups , function ( & $ group ) { $ group = new core_kernel_classes_Resource ( $ group ) ; } ) ; return $ groups ; }
get the groups of a user
50,309
public function getUsers ( $ groupUri ) { $ subjectClass = TestTakerService :: singleton ( ) -> getRootClass ( ) ; $ users = $ subjectClass -> searchInstances ( array ( self :: PROPERTY_MEMBERS_URI => $ groupUri ) , array ( 'recursive' => true , 'like' => false ) ) ; return $ users ; }
gets the users of a group
50,310
public function addUser ( $ userUri , core_kernel_classes_Resource $ group ) { $ user = new \ core_kernel_classes_Resource ( $ userUri ) ; return $ user -> setPropertyValue ( new core_kernel_classes_Property ( self :: PROPERTY_MEMBERS_URI ) , $ group ) ; }
Add a User to a Group
50,311
public function removeUser ( $ userUri , core_kernel_classes_Resource $ group ) { $ user = new \ core_kernel_classes_Resource ( $ userUri ) ; return $ user -> removePropertyValue ( new core_kernel_classes_Property ( self :: PROPERTY_MEMBERS_URI ) , $ group ) ; }
Remove a User from a Group
50,312
public function badWords ( ) { $ words = explode ( ' ' , $ this -> text ) ; return collect ( $ this -> dictionary ) -> filter ( function ( $ value ) use ( $ words ) { if ( $ this -> strict ) { return str_contains ( strtolower ( $ this -> text ) , strtolower ( $ value [ 'word' ] ) ) ; } return in_array ( strtolower ( $ value [ 'word' ] ) , $ words ) ; } ) -> map ( function ( $ value ) { return [ 'language' => $ value [ 'language' ] , 'word' => strtolower ( $ value [ 'word' ] ) , ] ; } ) -> toArray ( ) ; }
Return the bad words contained in the text .
50,313
public function filter ( ) { $ bad_words = collect ( $ this -> badWords ( ) ) -> pluck ( 'word' ) -> toArray ( ) ; return collect ( explode ( ' ' , $ this -> text ) ) -> map ( function ( $ value ) use ( $ bad_words ) { if ( $ this -> strict ) { return ( str_contains ( strtolower ( $ value ) , $ bad_words ) ) ? $ this -> blockWord ( $ value ) : $ value ; } return in_array ( strtolower ( $ value ) , $ bad_words ) ? $ this -> blockWord ( $ value ) : $ value ; } ) -> implode ( ' ' ) ; }
Filter the string blocking the bad words with the blocker string .
50,314
private function blockWord ( $ word ) { if ( $ this -> strictClean ) { return str_repeat ( $ this -> blocker [ 0 ] , strlen ( $ word ) ) ; } return $ this -> blocker ; }
Returns the blocked word .
50,315
public function register_hooks ( HookProviderInterface $ provider ) { if ( $ provider instanceof PluginAwareInterface ) { $ provider -> set_plugin ( $ this ) ; } $ provider -> register_hooks ( ) ; return $ this ; }
Register a hook provider .
50,316
public static function create ( $ slug , $ filename = '' ) { if ( empty ( $ filename ) ) { $ backtrace = debug_backtrace ( DEBUG_BACKTRACE_PROVIDE_OBJECT , 1 ) ; $ filename = $ backtrace [ 0 ] [ 'file' ] ; } return ( new Plugin ( ) ) -> set_basename ( plugin_basename ( $ filename ) ) -> set_directory ( plugin_dir_path ( $ filename ) ) -> set_file ( $ filename ) -> set_slug ( $ slug ) -> set_url ( plugin_dir_url ( $ filename ) ) ; }
Create a plugin instance .
50,317
protected function add_filter ( $ hook , $ method , $ priority = 10 , $ arg_count = 1 ) { return add_filter ( $ hook , $ this -> map_filter ( $ this -> get_wp_filter_id ( $ hook , $ method , $ priority ) , $ method , $ arg_count ) , $ priority , $ arg_count ) ; }
Add a WordPress filter .
50,318
protected function add_action ( $ hook , $ method , $ priority = 10 , $ arg_count = 1 ) { return $ this -> add_filter ( $ hook , $ method , $ priority , $ arg_count ) ; }
Add a WordPress action .
50,319
protected function remove_filter ( $ hook , $ method , $ priority = 10 , $ arg_count = 1 ) { return remove_filter ( $ hook , $ this -> map_filter ( $ this -> get_wp_filter_id ( $ hook , $ method , $ priority ) , $ method , $ arg_count ) , $ priority , $ arg_count ) ; }
Remove a WordPress filter .
50,320
protected function remove_action ( $ hook , $ method , $ priority = 10 , $ arg_count = 1 ) { return $ this -> remove_filter ( $ hook , $ method , $ priority , $ arg_count ) ; }
Remove a WordPress action .
50,321
protected function map_filter ( $ id , $ method , $ arg_count ) { if ( empty ( $ this -> filter_map [ $ id ] ) ) { $ this -> filter_map [ $ id ] = function ( ) use ( $ method , $ arg_count ) { return call_user_func_array ( [ $ this , $ method ] , array_slice ( func_get_args ( ) , 0 , $ arg_count ) ) ; } ; } return $ this -> filter_map [ $ id ] ; }
Map a filter to a closure that inherits the class internal scope .
50,322
protected function load_textdomain ( ) { $ plugin_rel_path = dirname ( $ this -> plugin -> get_basename ( ) ) . '/languages' ; load_plugin_textdomain ( $ this -> plugin -> get_slug ( ) , false , $ plugin_rel_path ) ; }
Load the text domain to localize the plugin .
50,323
public function addBreadcrumb ( ) { $ this -> updateBreadcrumbNode ( ) ; $ nodeId = $ this -> session -> get ( 'tl_page_node' ) ; if ( $ nodeId < 1 ) { return ; } $ trail = $ this -> getBreadcrumbTrail ( $ nodeId ) ; if ( 0 === count ( $ trail ) ) { $ this -> session -> set ( 'tl_page_node' , 0 ) ; return ; } $ this -> checkTrailAccess ( $ nodeId , $ trail ) ; $ this -> buildBreadcrumb ( $ nodeId , $ trail ) ; }
Override the default breadcrumb menu we want to show folder pages before root pages .
50,324
public function showFallbackWarning ( ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; if ( $ request -> query -> has ( 'act' ) ) { return ; } $ messages = \ System :: importStatic ( 'Messages' ) ; \ Message :: addRaw ( $ messages -> languageFallback ( ) ) ; if ( $ this -> hasInvalidTopLevels ( ) ) { \ Message :: addRaw ( '<p class="tl_error">' . $ GLOBALS [ 'TL_LANG' ] [ 'ERR' ] [ 'topLevelRegular' ] . '</p>' ) ; } }
Show a warning if there is no language fallback page .
50,325
public function configureFolderPage ( $ dc ) { if ( null === $ dc -> activeRecord || 'folder' !== $ dc -> activeRecord -> type ) { return ; } $ this -> db -> update ( 'tl_page' , [ 'alias' => '' , 'noSearch' => '1' , 'sitemap' => 'map_never' , 'published' => '1' , 'start' => '' , 'stop' => '' , ] , [ 'id' => $ dc -> id , ] ) ; }
Sets fixed configuration for a folder page .
50,326
public function onSaveType ( $ value , $ dc ) { if ( 'root' !== $ value && 'folder' !== $ value && $ dc -> activeRecord -> pid === 0 ) { throw new \ Exception ( $ GLOBALS [ 'TL_LANG' ] [ 'ERR' ] [ 'topLevelRoot' ] ) ; } return $ value ; }
Make sure that top - level pages are root pages or folders .
50,327
public function onSavePublished ( $ value , $ dc ) { if ( null !== $ dc -> activeRecord && 'folder' === $ dc -> activeRecord -> type ) { return '1' ; } return $ value ; }
A folder page can never be unpublished .
50,328
public function adjustAlias ( $ value , $ dc ) { if ( ! Config :: get ( 'folderUrl' ) ) { return $ value ; } if ( $ dc -> activeRecord && $ dc -> activeRecord -> type === 'folder' ) { $ childRecords = Database :: getInstance ( ) -> getChildRecords ( [ $ dc -> id ] , 'tl_page' ) ; $ this -> updateChildren ( $ childRecords ) ; return $ value ; } $ tl_page = new \ tl_page ( ) ; $ value = $ this -> cleanAlias ( $ value ) ; try { $ value = $ tl_page -> generateAlias ( $ value , $ dc ) ; } catch ( \ Exception $ e ) { $ value = $ value . '-' . $ dc -> id ; $ value = $ tl_page -> generateAlias ( $ value , $ dc ) ; } return $ value ; }
Adjust the alias of the page .
50,329
public function getPageTypes ( $ dc ) { $ options = [ ] ; $ rootAllowed = true ; if ( $ dc -> activeRecord -> pid > 0 ) { $ rootAllowed = false ; $ parentType = $ this -> db -> fetchColumn ( 'SELECT type FROM tl_page WHERE id=?' , [ $ dc -> activeRecord -> pid ] ) ; if ( $ parentType === 'folder' ) { $ rootAllowed = true ; } } foreach ( array_keys ( $ GLOBALS [ 'TL_PTY' ] ) as $ pty ) { if ( $ pty === 'root' && ! $ rootAllowed ) { continue ; } if ( $ pty === $ dc -> value || $ this -> user -> hasAccess ( $ pty , 'alpty' ) ) { $ options [ ] = $ pty ; } } return $ options ; }
Returns all allowed page types as array .
50,330
private function updateBreadcrumbNode ( ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; if ( $ request -> query -> has ( 'pn' ) ) { $ this -> session -> set ( 'tl_page_node' , ( int ) $ request -> query -> get ( 'pn' ) ) ; $ params = array_merge ( $ request -> get ( '_route_params' ) , $ request -> query -> all ( ) ) ; unset ( $ params [ 'pn' ] ) ; throw new RedirectResponseException ( $ this -> router -> generate ( $ request -> get ( '_route' ) , $ params ) ) ; } }
Sets a new node if input value is given .
50,331
private function updateChildren ( array $ ids ) { if ( count ( $ ids ) < 1 ) { return ; } foreach ( $ ids as $ id ) { $ alias = $ this -> db -> fetchColumn ( 'SELECT alias FROM tl_page WHERE id=?' , [ $ id ] ) ; $ alias = $ this -> cleanAlias ( $ alias ) ; $ this -> db -> update ( 'tl_page' , [ 'alias' => $ alias ] , [ 'id' => $ id ] ) ; } }
Update the children pages .
50,332
public static function decode ( $ hash ) { $ minlng = - 180 ; $ maxlng = 180 ; $ minlat = - 90 ; $ maxlat = 90 ; for ( $ i = 0 , $ c = strlen ( $ hash ) ; $ i < $ c ; $ i ++ ) { $ v = strpos ( self :: $ table , $ hash [ $ i ] ) ; if ( 1 & $ i ) { if ( 16 & $ v ) { $ minlat = ( $ minlat + $ maxlat ) / 2 ; } else { $ maxlat = ( $ minlat + $ maxlat ) / 2 ; } if ( 8 & $ v ) { $ minlng = ( $ minlng + $ maxlng ) / 2 ; } else { $ maxlng = ( $ minlng + $ maxlng ) / 2 ; } if ( 4 & $ v ) { $ minlat = ( $ minlat + $ maxlat ) / 2 ; } else { $ maxlat = ( $ minlat + $ maxlat ) / 2 ; } if ( 2 & $ v ) { $ minlng = ( $ minlng + $ maxlng ) / 2 ; } else { $ maxlng = ( $ minlng + $ maxlng ) / 2 ; } if ( 1 & $ v ) { $ minlat = ( $ minlat + $ maxlat ) / 2 ; } else { $ maxlat = ( $ minlat + $ maxlat ) / 2 ; } } else { if ( 16 & $ v ) { $ minlng = ( $ minlng + $ maxlng ) / 2 ; } else { $ maxlng = ( $ minlng + $ maxlng ) / 2 ; } if ( 8 & $ v ) { $ minlat = ( $ minlat + $ maxlat ) / 2 ; } else { $ maxlat = ( $ minlat + $ maxlat ) / 2 ; } if ( 4 & $ v ) { $ minlng = ( $ minlng + $ maxlng ) / 2 ; } else { $ maxlng = ( $ minlng + $ maxlng ) / 2 ; } if ( 2 & $ v ) { $ minlat = ( $ minlat + $ maxlat ) / 2 ; } else { $ maxlat = ( $ minlat + $ maxlat ) / 2 ; } if ( 1 & $ v ) { $ minlng = ( $ minlng + $ maxlng ) / 2 ; } else { $ maxlng = ( $ minlng + $ maxlng ) / 2 ; } } } return array ( $ minlng , $ maxlng , $ minlat , $ maxlat ) ; }
decode a geohash string to a geographical area
50,333
public function toSql ( ) : string { $ sql = $ this -> queryRelate -> getQuery ( ) -> toSql ( ) ; $ this -> resetQueryRelate ( ) ; return $ sql ; }
return run sql .
50,334
public function setUpperLimitMst ( ) { $ alg = new AlgorithmTspMst ( $ this -> graph ) ; $ this -> upperLimit = $ alg -> getWeight ( ) ; return $ this ; }
automatically sets upper limit to use for branch - and - bound from the MST heuristic
50,335
private function sumEdges ( array $ edges ) { $ sum = 0 ; foreach ( $ edges as $ edge ) { $ sum += $ edge -> getWeight ( ) ; } return $ sum ; }
get sum of weight of given edges
50,336
public function isSimple ( ) { $ vertices = $ this -> walk -> getVertices ( ) -> getVector ( ) ; if ( $ this -> isCycle ( ) ) { unset ( $ vertices [ 0 ] ) ; } return ! $ this -> hasArrayDuplicates ( $ vertices ) ; }
check whether this walk is simple
50,337
private function hasArrayDuplicates ( $ array ) { $ compare = array ( ) ; foreach ( $ array as $ element ) { if ( in_array ( $ element , $ compare , true ) ) { return true ; } else { $ compare [ ] = $ element ; } } return false ; }
checks whether ths given array contains duplicate identical entries
50,338
public function getCycleNegative ( ) { $ verticesVisited = array ( ) ; foreach ( $ this -> graph -> getVertices ( ) -> getMap ( ) as $ vid => $ vertex ) { if ( ! isset ( $ verticesVisited [ $ vid ] ) ) { $ alg = new SpMooreBellmanFord ( $ vertex ) ; try { foreach ( $ alg -> getVertices ( ) -> getIds ( ) as $ vid ) { $ verticesVisited [ $ vid ] = true ; } } catch ( NegativeCycleException $ e ) { return $ e -> getCycle ( ) ; } } } throw new UnderflowException ( 'No negative cycle found' ) ; }
Searches all vertices for the first negative cycle
50,339
private function getVerticesSubtreeRecursive ( Vertex $ vertex , array & $ vertices , Vertex $ ignore = null ) { if ( isset ( $ vertices [ $ vertex -> getId ( ) ] ) ) { throw new UnexpectedValueException ( 'Vertex already visited' ) ; } $ vertices [ $ vertex -> getId ( ) ] = $ vertex ; foreach ( $ this -> getVerticesNeighbor ( $ vertex ) as $ vertexNeighboor ) { if ( $ vertexNeighboor === $ ignore ) { $ ignore = null ; continue ; } $ this -> getVerticesSubtreeRecursive ( $ vertexNeighboor , $ vertices , $ vertex ) ; } }
get subtree for given Vertex and ignore path to parent ignoreVertex
50,340
private function getVerticesNeighbor ( Vertex $ vertex ) { $ vertices = array ( ) ; foreach ( $ vertex -> getEdges ( ) as $ edge ) { if ( ! ( $ edge instanceof UndirectedEdge ) ) { throw new UnexpectedValueException ( 'Directed edge encountered' ) ; } $ vertices [ ] = $ edge -> getVertexToFrom ( $ vertex ) ; } return new Vertices ( $ vertices ) ; }
get neighbor vertices for given start vertex
50,341
protected function checkBalance ( ) { $ alg = new AlgorithmFlow ( $ this -> graph ) ; $ balance = $ alg -> getBalance ( ) ; $ tolerance = 0.000001 ; if ( $ balance >= $ tolerance || $ balance <= - $ tolerance ) { throw new UnexpectedValueException ( 'The given graph is not balanced value is: ' . $ balance ) ; } return $ this ; }
check if balance is okay and throw exception otherwise
50,342
protected function addEdgesSorted ( Edges $ edges , SplPriorityQueue $ sortedEdges ) { foreach ( $ edges as $ edge ) { if ( ! $ edge -> isLoop ( ) ) { $ sortedEdges -> insert ( $ edge , - $ edge -> getWeight ( ) ) ; } } }
helper method to add a set of Edges to the given set of sorted edges
50,343
public function getVertices ( ) { $ visited = array ( ) ; $ todo = array ( $ this -> vertex ) ; while ( $ vertex = array_shift ( $ todo ) ) { if ( ! isset ( $ visited [ $ vertex -> getId ( ) ] ) ) { $ visited [ $ vertex -> getId ( ) ] = $ vertex ; foreach ( array_reverse ( $ this -> getVerticesAdjacent ( $ vertex ) -> getMap ( ) , true ) as $ vid => $ nextVertex ) { $ todo [ ] = $ nextVertex ; } } } return new Vertices ( $ visited ) ; }
calculates an iterative depth - first search
50,344
public function createGraph ( ) { $ newgraph = $ this -> graph -> createGraphCloneEdgeless ( ) ; foreach ( $ this -> graph -> getEdges ( ) as $ edge ) { if ( ! ( $ edge instanceof EdgeDirected ) ) { throw new UnexpectedValueException ( 'Edge is undirected' ) ; } $ flow = $ edge -> getFlow ( ) ; if ( $ flow === NULL ) { throw new UnexpectedValueException ( 'Flow not set' ) ; } $ capacity = $ edge -> getCapacity ( ) ; if ( $ capacity === NULL ) { throw new UnexpectedValueException ( 'Capacity not set' ) ; } if ( $ this -> keepNullCapacity || $ flow < $ capacity ) { $ newEdge = $ newgraph -> createEdgeClone ( $ edge ) -> setFlow ( 0 ) -> setCapacity ( $ capacity - $ flow ) ; if ( $ this -> mergeParallelEdges ) { $ this -> mergeParallelEdges ( $ newEdge ) ; } } if ( $ this -> keepNullCapacity || $ flow > 0 ) { $ newEdge = $ newgraph -> createEdgeCloneInverted ( $ edge ) -> setFlow ( 0 ) -> setCapacity ( $ flow ) ; if ( $ newEdge -> getWeight ( ) !== NULL ) { $ newEdge -> setWeight ( - $ newEdge -> getWeight ( ) ) ; } if ( $ this -> mergeParallelEdges ) { $ this -> mergeParallelEdges ( $ newEdge ) ; } } } return $ newgraph ; }
create residual graph
50,345
private function mergeParallelEdges ( Edge $ newEdge ) { $ parallelEdges = $ newEdge -> getEdgesParallel ( ) ; if ( $ parallelEdges ) { $ mergedCapacity = 0 ; foreach ( $ parallelEdges as $ parallelEdge ) { $ mergedCapacity += $ parallelEdge -> getCapacity ( ) ; } $ newEdge -> setCapacity ( $ newEdge -> getCapacity ( ) + $ mergedCapacity ) ; foreach ( $ parallelEdges as $ parallelEdge ) { $ parallelEdge -> destroy ( ) ; } } }
Will merge all edges that are parallel to to given edge
50,346
public function getVertexRoot ( ) { foreach ( $ this -> graph -> getVertices ( ) as $ vertex ) { if ( $ this -> isVertexPossibleRoot ( $ vertex ) ) { return $ vertex ; } } throw new UnderflowException ( 'No possible root found. Either empty graph or no Vertex with proper degree found.' ) ; }
get root vertex for this in - tree
50,347
public function hasDirected ( ) { foreach ( $ this -> set -> getEdges ( ) as $ edge ) { if ( $ edge instanceof EdgeDirected ) { return true ; } } return false ; }
checks whether the graph has any directed edges
50,348
public function hasUndirected ( ) { foreach ( $ this -> set -> getEdges ( ) as $ edge ) { if ( $ edge instanceof EdgeUndirected ) { return true ; } } return false ; }
checks whether the graph has any undirected edges
50,349
public function createGraph ( ) { $ graphResult = $ this -> startVertex -> getGraph ( ) -> createGraphClone ( ) ; foreach ( $ graphResult -> getEdges ( ) as $ edge ) { if ( ! ( $ edge instanceof EdgeDirected ) ) { throw new UnexpectedValueException ( 'Undirected edges not supported for edmonds karp' ) ; } $ edge -> setFlow ( 0 ) ; } $ idA = $ this -> startVertex -> getId ( ) ; $ idB = $ this -> destinationVertex -> getId ( ) ; do { $ residualAlgorithm = new ResidualGraph ( $ graphResult ) ; $ graphResidual = $ residualAlgorithm -> createGraph ( ) ; $ alg = new BreadthFirst ( $ graphResidual -> getVertex ( $ idA ) ) ; try { $ pathFlow = $ alg -> getWalkTo ( $ graphResidual -> getVertex ( $ idB ) ) ; } catch ( OutOfBoundsException $ e ) { $ pathFlow = NULL ; } if ( $ pathFlow ) { $ maxFlowValue = $ pathFlow -> getEdges ( ) -> getEdgeOrder ( Edges :: ORDER_CAPACITY ) -> getCapacity ( ) ; foreach ( $ pathFlow -> getEdges ( ) as $ edge ) { try { $ originalEdge = $ graphResult -> getEdgeClone ( $ edge ) ; $ originalEdge -> setFlow ( $ originalEdge -> getFlow ( ) + $ maxFlowValue ) ; } catch ( UnderflowException $ e ) { $ originalEdge = $ graphResult -> getEdgeCloneInverted ( $ edge ) ; $ originalEdge -> setFlow ( $ originalEdge -> getFlow ( ) - $ maxFlowValue ) ; } } } } while ( $ pathFlow ) ; return $ graphResult ; }
Returns max flow graph
50,350
public function getFlowMax ( ) { $ resultGraph = $ this -> createGraph ( ) ; $ start = $ resultGraph -> getVertex ( $ this -> startVertex -> getId ( ) ) ; $ maxFlow = 0 ; foreach ( $ start -> getEdgesOut ( ) as $ edge ) { $ maxFlow = $ maxFlow + $ edge -> getFlow ( ) ; } return $ maxFlow ; }
Returns max flow value
50,351
public function getColors ( ) { $ colors = array ( ) ; foreach ( $ this -> graph -> getVertices ( ) -> getMap ( ) as $ vid => $ startVertex ) { if ( ! isset ( $ colors [ $ vid ] ) ) { $ queue = array ( $ startVertex ) ; $ colors [ $ vid ] = 0 ; do { $ vertex = array_shift ( $ queue ) ; $ color = $ colors [ $ vertex -> getId ( ) ] ; $ nextColor = 1 - $ color ; foreach ( $ vertex -> getVerticesEdge ( ) -> getMap ( ) as $ vid => $ nextVertex ) { if ( ! isset ( $ colors [ $ vid ] ) ) { $ colors [ $ vid ] = $ nextColor ; $ queue [ ] = $ nextVertex ; } elseif ( $ colors [ $ vid ] !== $ nextColor ) { throw new UnexpectedValueException ( 'Graph is not bipartit' ) ; } } } while ( $ queue ) ; } } return $ colors ; }
get map of vertex ID to vertex color
50,352
public function getColorVertices ( ) { $ colors = $ this -> getColors ( ) ; $ ret = array ( 0 => array ( ) , 1 => array ( ) ) ; foreach ( $ this -> graph -> getVertices ( ) -> getMap ( ) as $ vid => $ vertex ) { $ ret [ $ colors [ $ vid ] ] [ $ vid ] = $ vertex ; } return $ ret ; }
get groups of vertices per color
50,353
public function createGraphGroups ( ) { $ colors = $ this -> getColors ( ) ; $ graph = $ this -> graph -> createGraphClone ( ) ; foreach ( $ graph -> getVertices ( ) -> getMap ( ) as $ vid => $ vertex ) { $ vertex -> setGroup ( $ colors [ $ vid ] ) ; } return $ graph ; }
create new graph with valid groups set according to bipartition colors
50,354
public function isBalanced ( ) { foreach ( $ this -> graph -> getVertices ( ) as $ vertex ) { if ( $ this -> getDegreeInVertex ( $ vertex ) !== $ this -> getDegreeOutVertex ( $ vertex ) ) { return false ; } } return true ; }
checks whether the indegree of every vertex equals its outdegree
50,355
public function isVertexSource ( Vertex $ vertex ) { foreach ( $ vertex -> getEdges ( ) as $ edge ) { if ( $ edge -> hasVertexTarget ( $ vertex ) ) { return false ; } } return true ; }
checks whether this vertex is a source i . e . its indegree is zero
50,356
public function isVertexSink ( Vertex $ vertex ) { foreach ( $ vertex -> getEdges ( ) as $ edge ) { if ( $ edge -> hasVertexStart ( $ vertex ) ) { return false ; } } return true ; }
checks whether this vertex is a sink i . e . its outdegree is zero
50,357
public function hasCycle ( ) { $ components = new ConnectedComponents ( $ this -> graph ) ; if ( $ components -> isSingle ( ) ) { $ alg = new Degree ( $ this -> graph ) ; foreach ( $ this -> graph -> getVertices ( ) as $ vertex ) { if ( $ alg -> getDegreeVertex ( $ vertex ) & 1 ) { return false ; } } return true ; } return false ; }
check whether this graph has an eulerian cycle
50,358
public function createGraph ( ) { $ newgraph = $ this -> graph -> createGraphCloneEdgeless ( ) ; foreach ( $ this -> graph -> getEdges ( ) as $ edge ) { if ( ! ( $ edge instanceof EdgeDirected ) ) { throw new UnexpectedValueException ( 'Edge is undirected' ) ; } $ newgraph -> createEdgeCloneInverted ( $ edge ) ; } return $ newgraph ; }
create transpose graph
50,359
public function setDirection ( $ direction ) { if ( $ direction !== self :: DIRECTION_FORWARD && $ direction !== self :: DIRECTION_REVERSE && $ direction !== self :: DIRECTION_BOTH ) { throw new InvalidArgumentException ( 'Invalid direction given' ) ; } $ this -> direction = $ direction ; return $ this ; }
set direction in which to follow adjacent vertices
50,360
public function isSingle ( ) { try { $ vertex = $ this -> graph -> getVertices ( ) -> getVertexFirst ( ) ; } catch ( UnderflowException $ e ) { return false ; } $ alg = $ this -> createSearch ( $ vertex ) ; return ( count ( $ this -> graph -> getVertices ( ) ) === count ( $ alg -> getVertices ( ) ) ) ; }
check whether this graph consists of only a single component
50,361
public function getNumberOfComponents ( ) { $ visitedVertices = array ( ) ; $ components = 0 ; foreach ( $ this -> graph -> getVertices ( ) -> getMap ( ) as $ vid => $ vertex ) { if ( ! isset ( $ visitedVertices [ $ vid ] ) ) { $ newVertices = $ this -> createSearch ( $ vertex ) -> getVertices ( ) -> getIds ( ) ; ++ $ components ; foreach ( $ newVertices as $ vid ) { $ visitedVertices [ $ vid ] = true ; } } } return $ components ; }
count number of connected components
50,362
public function createGraphsComponents ( ) { $ visitedVertices = array ( ) ; $ graphs = array ( ) ; foreach ( $ this -> graph -> getVertices ( ) -> getMap ( ) as $ vid => $ vertex ) { if ( ! isset ( $ visitedVertices [ $ vid ] ) ) { $ alg = $ this -> createSearch ( $ vertex ) ; $ newVertices = $ alg -> getVertices ( ) ; foreach ( $ newVertices -> getIds ( ) as $ vid ) { $ visitedVertices [ $ vid ] = true ; } $ graphs [ ] = $ this -> graph -> createGraphCloneVertices ( $ newVertices ) ; } } return $ graphs ; }
separate input graph into separate independant and unconnected graphs
50,363
public function isBipartit ( ) { if ( $ this -> getNumberOfGroups ( ) !== 2 ) { return false ; } foreach ( $ this -> graph -> getVertices ( ) as $ vertex ) { $ group = $ vertex -> getGroup ( ) ; foreach ( $ vertex -> getVerticesEdge ( ) as $ vertexNeighbor ) { if ( $ vertexNeighbor -> getGroup ( ) === $ group ) { return false ; } } } return true ; }
checks whether the input graph s vertex groups are a valid bipartition
50,364
public function getGroups ( ) { $ groups = array ( ) ; foreach ( $ this -> graph -> getVertices ( ) as $ vertex ) { $ groups [ $ vertex -> getGroup ( ) ] = true ; } return array_keys ( $ groups ) ; }
get vector of all group numbers
50,365
public function getVerticesGroup ( $ group ) { $ vertices = array ( ) ; foreach ( $ this -> graph -> getVertices ( ) -> getMap ( ) as $ vid => $ vertex ) { if ( $ vertex -> getGroup ( ) === $ group ) { $ vertices [ $ vid ] = $ vertex ; } } return new Vertices ( $ vertices ) ; }
get set of all Vertices in the given group
50,366
public function isWeighted ( ) { foreach ( $ this -> set -> getEdges ( ) as $ edge ) { if ( $ edge -> getWeight ( ) !== NULL ) { return true ; } } return false ; }
checks whether this graph has any weighted edges
50,367
public function getWeightMin ( ) { $ min = NULL ; foreach ( $ this -> set -> getEdges ( ) as $ edge ) { $ weight = $ edge -> getWeight ( ) ; if ( $ weight !== null && ( $ min === NULL || $ weight < $ min ) ) { $ min = $ weight ; } } return $ min ; }
get minimum weight assigned to all edges
50,368
protected function getParsedResponse ( RequestInterface $ request ) : string { $ response = $ this -> getHttpClient ( ) -> sendRequest ( $ request ) ; $ statusCode = $ response -> getStatusCode ( ) ; if ( 401 === $ statusCode || 403 === $ statusCode ) { throw new InvalidCredentials ( ) ; } elseif ( 429 === $ statusCode ) { throw new QuotaExceeded ( ) ; } elseif ( $ statusCode >= 300 ) { throw InvalidServerResponse :: create ( ( string ) $ request -> getUri ( ) , $ statusCode ) ; } $ body = ( string ) $ response -> getBody ( ) ; if ( empty ( $ body ) ) { throw InvalidServerResponse :: emptyResponse ( ( string ) $ request -> getUri ( ) ) ; } return $ body ; }
Send request and return contents . If content is empty an exception will be thrown .
50,369
public static function block_tags ( $ reset = false ) { if ( empty ( self :: $ block_tags ) || $ reset ) { self :: $ block_tags = \ array_merge ( \ array_flip ( \ array_filter ( \ array_keys ( Elements :: $ html5 ) , function ( $ tag ) { return Elements :: isA ( $ tag , Elements :: BLOCK_TAG ) ; } ) ) , \ array_flip ( [ 'li' , 'td' , 'dt' ] ) ) ; } return self :: $ block_tags ; }
Retrieves an array of block tags .
50,370
public static function inappropriate_tags ( $ reset = false ) { if ( empty ( self :: $ inappropriate_tags ) || $ reset ) { self :: $ inappropriate_tags = \ array_flip ( \ array_merge ( \ array_filter ( \ array_keys ( Elements :: $ html5 ) , function ( $ tag ) { return Elements :: isA ( $ tag , Elements :: VOID_TAG ) || Elements :: isA ( $ tag , Elements :: TEXT_RAW ) || Elements :: isA ( $ tag , Elements :: TEXT_RCDATA ) ; } ) , self :: ADDITIONAL_INAPPROPRIATE_TAGS ) ) ; } return self :: $ inappropriate_tags ; }
Retrieves an array of tags that we should never touch .
50,371
public static function nodelist_to_array ( \ DOMNodeList $ list ) { $ out = [ ] ; foreach ( $ list as $ node ) { $ out [ \ spl_object_hash ( $ node ) ] = $ node ; } return $ out ; }
Converts \ DOMNodeList to array ;
50,372
private static function get_adjacent_chr ( \ DOMNode $ node , $ position , $ length , callable $ get_textnode ) { $ textnode = $ get_textnode ( $ node ) ; if ( isset ( $ textnode ) && isset ( $ textnode -> data ) ) { $ func = Strings :: functions ( $ textnode -> data ) ; if ( ! empty ( $ func ) ) { return \ preg_replace ( '/\p{C}/Su' , '' , $ func [ 'substr' ] ( $ textnode -> data , $ position , $ length ) ) ; } } return '' ; }
Retrieves a character from the given \ DOMNode .
50,373
private static function get_adjacent_textnode ( callable $ iterate , callable $ get_adjacent_parent , \ DOMNode $ node = null ) { if ( ! isset ( $ node ) || self :: is_block_tag ( $ node ) ) { return null ; } $ adjacent = null ; $ iterated_node = $ node ; while ( null !== $ iterated_node && null === $ adjacent ) { $ adjacent = $ iterate ( $ iterated_node ) ; } if ( null === $ adjacent ) { $ adjacent = $ get_adjacent_parent ( $ node -> parentNode ) ; } return $ adjacent ; }
Retrieves an adjacent \ DOMText sibling if there is one .
50,374
public static function get_first_textnode ( \ DOMNode $ node = null , $ recursive = false ) { return self :: get_edge_textnode ( [ __CLASS__ , __FUNCTION__ ] , $ node , $ recursive , false ) ; }
Retrieves the first \ DOMText child of the element . Block - level child elements are ignored .
50,375
public static function get_last_textnode ( \ DOMNode $ node = null , $ recursive = false ) { return self :: get_edge_textnode ( [ __CLASS__ , __FUNCTION__ ] , $ node , $ recursive , true ) ; }
Retrieves the last \ DOMText child of the element . Block - level child elements are ignored .
50,376
private static function get_edge_textnode ( callable $ get_textnode , \ DOMNode $ node = null , $ recursive = false , $ reverse = false ) { if ( ! isset ( $ node ) ) { return null ; } if ( $ node instanceof \ DOMText ) { return $ node ; } elseif ( ! $ node instanceof \ DOMElement || $ recursive && self :: is_block_tag ( $ node ) ) { return null ; } $ edge_textnode = null ; if ( $ node -> hasChildNodes ( ) ) { $ children = $ node -> childNodes ; $ max = $ children -> length ; $ index = $ reverse ? $ max - 1 : 0 ; $ incrementor = $ reverse ? - 1 : + 1 ; while ( $ index >= 0 && $ index < $ max && null === $ edge_textnode ) { $ edge_textnode = $ get_textnode ( $ children -> item ( $ index ) , true ) ; $ index += $ incrementor ; } } return $ edge_textnode ; }
Retrieves an edge \ DOMText child of the element specified by the callable . Block - level child elements are ignored .
50,377
public static function get_block_parent_name ( \ DOMNode $ node ) { $ parent = self :: get_block_parent ( $ node ) ; if ( ! empty ( $ parent ) ) { return $ parent -> tagName ; } else { return '' ; } }
Retrieves the tag name of the nearest block - level parent .
50,378
public static function is_block_tag ( \ DOMNode $ node ) { return $ node instanceof \ DOMElement && isset ( self :: $ block_tags [ $ node -> tagName ] ) ; }
Determines if a node is a block tag .
50,379
public static function get_styled_quotes ( $ style , Settings $ settings ) { if ( isset ( self :: $ styles [ $ style ] ) ) { return new Simple_Quotes ( self :: $ styles [ $ style ] [ self :: _OPEN ] , self :: $ styles [ $ style ] [ self :: _CLOSE ] ) ; } if ( self :: DOUBLE_GUILLEMETS_FRENCH === $ style ) { $ space = $ settings -> no_break_narrow_space ( ) ; return new Simple_Quotes ( U :: GUILLEMET_OPEN . $ space , $ space . U :: GUILLEMET_CLOSE ) ; } return null ; }
Creates a new Quotes object in the given style .
50,380
public function with_value ( $ value ) { if ( $ this -> value === $ value ) { return $ this ; } $ cloned_token = clone $ this ; $ cloned_token -> value = $ value ; return $ cloned_token ; }
Create a new token with the same type but a different value . If the value is unchanged the original token is returned .
50,381
protected function do_hyphenate ( array $ tokens , Settings $ settings , $ hyphen = U :: SOFT_HYPHEN ) { if ( empty ( $ settings [ 'hyphenMinLength' ] ) || empty ( $ settings [ 'hyphenMinBefore' ] ) ) { return $ tokens ; } return $ this -> get_hyphenator ( $ settings ) -> hyphenate ( $ tokens , $ hyphen , ! empty ( $ settings [ 'hyphenateTitleCase' ] ) , $ settings [ 'hyphenMinLength' ] , $ settings [ 'hyphenMinBefore' ] , $ settings [ 'hyphenMinAfter' ] ) ; }
Really hyphenates given text fragment .
50,382
public function get_hyphenator ( Settings $ settings ) { $ lang = $ settings [ 'hyphenLanguage' ] ; $ exceptions = ( array ) $ settings [ 'hyphenationCustomExceptions' ] ; $ hyphenator = $ this -> cache -> get_hyphenator ( $ lang ) ; if ( null === $ hyphenator ) { $ hyphenator = new Hyphenator ( $ lang , $ exceptions ) ; $ this -> cache -> set_hyphenator ( $ lang , $ hyphenator ) ; } else { $ hyphenator -> set_language ( $ lang ) ; $ hyphenator -> set_custom_exceptions ( $ exceptions ) ; } return $ hyphenator ; }
Retrieves the hyphenator instance .
50,383
protected function dewidow ( $ text , array $ func , $ max_pull , $ max_length , $ word_number , $ narrow_space ) { if ( $ word_number < 1 ) { return $ text ; } return \ preg_replace_callback ( self :: REGEX_START . ( $ word_number - 1 ) . self :: REGEX_END , function ( array $ widow ) use ( $ func , $ max_pull , $ max_length , $ word_number , $ narrow_space ) { $ widow [ 'widow' ] = self :: strip_breaking_characters ( $ widow [ 'widow' ] ) ; $ widow [ 'trailing' ] = self :: strip_breaking_characters ( self :: make_space_nonbreaking ( $ widow [ 'trailing' ] , $ narrow_space , $ func [ 'u' ] ) ) ; if ( '' === $ widow [ 'space_before' ] || false !== \ strpos ( $ widow [ 'space_before' ] , U :: NO_BREAK_SPACE ) || $ func [ 'strlen' ] ( $ widow [ 'neighbor' ] ) > $ max_pull || $ func [ 'strlen' ] ( $ widow [ 'widow' ] ) > $ max_length || self :: is_narrow_space ( $ widow [ 'space_between' ] ) ) { return $ widow [ 'space_before' ] . $ widow [ 'neighbor' ] . $ this -> dewidow ( $ widow [ 'space_between' ] . $ widow [ 'widow' ] . $ widow [ 'trailing' ] , $ func , $ max_pull , $ max_length , $ word_number - 1 , $ narrow_space ) ; } return $ widow [ 'space_before' ] . $ widow [ 'neighbor' ] . U :: NO_BREAK_SPACE . self :: make_space_nonbreaking ( $ widow [ 'widow' ] , $ narrow_space , $ func [ 'u' ] ) . $ widow [ 'trailing' ] ; } , $ text ) ; }
Dewidow a given text fragment .
50,384
protected static function is_narrow_space ( $ string ) { return U :: THIN_SPACE === $ string || U :: HAIR_SPACE === $ string || U :: NO_BREAK_NARROW_SPACE === $ string ; }
Is the given string one of the narrow space characters?
50,385
protected static function make_space_nonbreaking ( $ string , $ narrow_space , $ u ) { return \ preg_replace ( [ '/\s*' . U :: THIN_SPACE . '\s*/u' , '/\s*' . U :: NO_BREAK_NARROW_SPACE . '\s*/u' , "/\\s+/$u" , '/' . self :: MASKED_NARROW_SPACE . "/$u" , ] , [ self :: MASKED_NARROW_SPACE , self :: MASKED_NARROW_SPACE , U :: NO_BREAK_SPACE , $ narrow_space , ] , $ string ) ; }
Strip zero - width space and soft hyphens from the given string .
50,386
private static function calc_adjacent_length ( $ current_length , $ adjacent_character , $ haystack , array $ needles , callable $ substr , callable $ strlen , $ reverse = false ) { if ( $ current_length > 0 && $ adjacent_character !== $ substr ( $ haystack , $ reverse ? - $ current_length : 0 , $ current_length ) ) { foreach ( $ needles as $ needle ) { $ len = $ strlen ( $ needle ) ; if ( $ needle === $ substr ( $ haystack , ( $ reverse ? - $ len : 0 ) , $ len ) ) { return $ len ; } } } return $ current_length ; }
Calculates the adjacent character length .
50,387
private function update_smart_quotes_brackets ( $ primary_open , $ primary_close , $ secondary_open , $ secondary_close ) { $ brackets = [ "['" => '[' . $ secondary_open , "{'" => '{' . $ secondary_open , "('" => '(' . $ secondary_open , "']" => $ secondary_close . ']' , "'}" => $ secondary_close . '}' , "')" => $ secondary_close . ')' , '["' => '[' . $ primary_open , '{"' => '{' . $ primary_open , '("' => '(' . $ primary_open , '"]' => $ primary_close . ']' , '"}' => $ primary_close . '}' , '")' => $ primary_close . ')' , "\"'" => $ primary_open . $ secondary_open , "'\"" => $ secondary_close . $ primary_close , ] ; $ this -> brackets_matches = \ array_keys ( $ brackets ) ; $ this -> brackets_replacements = \ array_values ( $ brackets ) ; }
Update smartQuotesBrackets component after quote style change .
50,388
public static function get_http_response_code ( $ url ) { $ curl = curl_init ( ) ; curl_setopt_array ( $ curl , [ CURLOPT_RETURNTRANSFER => true , CURLOPT_URL => $ url , ] ) ; curl_exec ( $ curl ) ; $ response_code = curl_getinfo ( $ curl , CURLINFO_HTTP_CODE ) ; curl_close ( $ curl ) ; return $ response_code ; }
Retrieve a HTTP response code via cURL .
50,389
protected static function remove_adjacent_characters ( $ string , callable $ strlen , callable $ substr , $ prev_length = 0 , $ next_length = 0 ) { if ( $ prev_length > 0 ) { $ string = $ substr ( $ string , $ prev_length , $ strlen ( $ string ) ) ; } if ( $ next_length > 0 ) { $ string = $ substr ( $ string , 0 , $ strlen ( $ string ) - $ next_length ) ; } return $ string ; }
Remove adjacent characters from given string .
50,390
protected static function get_default_node_fixes ( ) { return [ self :: CHARACTERS => [ Node_Fixes \ Smart_Maths_Fix :: class => [ ] , Node_Fixes \ Smart_Diacritics_Fix :: class => [ ] , Node_Fixes \ Smart_Quotes_Fix :: class => [ 'feed' => true ] , Node_Fixes \ Smart_Dashes_Fix :: class => [ 'feed' => true ] , Node_Fixes \ Smart_Ellipses_Fix :: class => [ 'feed' => true ] , Node_Fixes \ Smart_Marks_Fix :: class => [ 'feed' => true ] , ] , self :: SPACING_PRE_WORDS => [ Node_Fixes \ Single_Character_Word_Spacing_Fix :: class => [ ] , Node_Fixes \ Dash_Spacing_Fix :: class => [ ] , Node_Fixes \ Unit_Spacing_Fix :: class => [ ] , Node_Fixes \ Numbered_Abbreviation_Spacing_Fix :: class => [ ] , Node_Fixes \ French_Punctuation_Spacing_Fix :: class => [ ] , ] , self :: SPACING_POST_WORDS => [ Node_Fixes \ Dewidow_Fix :: class => [ ] , Node_Fixes \ Space_Collapse_Fix :: class => [ ] , ] , self :: HTML_INSERTION => [ Node_Fixes \ Smart_Ordinal_Suffix_Fix :: class => [ 'classes' => [ 'ordinal' ] , ] , Node_Fixes \ Smart_Exponents_Fix :: class => [ ] , Node_Fixes \ Smart_Fractions_Fix :: class => [ 'classes' => [ 'numerator' , 'denominator' ] , ] , Node_Fixes \ Style_Caps_Fix :: class => [ 'classes' => [ 'caps' ] , ] , Node_Fixes \ Style_Numbers_Fix :: class => [ 'classes' => [ 'numbers' ] , ] , Node_Fixes \ Style_Ampersands_Fix :: class => [ 'classes' => [ 'amp' ] , ] , Node_Fixes \ Style_Initial_Quotes_Fix :: class => [ 'classes' => [ 'quo' , 'dquo' ] , ] , Node_Fixes \ Style_Hanging_Punctuation_Fix :: class => [ 'classes' => [ 'push-single' , 'push-double' , 'pull-single' , 'pull-double' ] , ] , ] , ] ; }
Returns a configuration array for the default node fixes .
50,391
protected static function get_default_token_fixes ( ) { return [ Token_Fixes \ Wrap_Hard_Hyphens_Fix :: class => [ ] , Token_Fixes \ Smart_Dashes_Hyphen_Fix :: class => [ ] , Token_Fixes \ Hyphenate_Compounds_Fix :: class => [ 'cache' => true ] , Token_Fixes \ Hyphenate_Fix :: class => [ 'cache' => true ] , Token_Fixes \ Wrap_URLs_Fix :: class => [ 'cache' => true ] , Token_Fixes \ Wrap_Emails_Fix :: class => [ ] , ] ; }
Returns a configuration array for the default token fixes .
50,392
public function set_custom_exceptions ( array $ exceptions = [ ] ) { if ( empty ( $ exceptions ) && empty ( $ this -> custom_exceptions ) ) { return ; } $ new_hash = self :: get_object_hash ( $ exceptions ) ; if ( $ this -> custom_exceptions_hash === $ new_hash ) { return ; } $ exception_keys = [ ] ; foreach ( $ exceptions as $ exception ) { $ f = Strings :: functions ( $ exception ) ; if ( empty ( $ f ) ) { continue ; } $ exception = $ f [ 'strtolower' ] ( $ exception ) ; $ exception_keys [ $ exception ] = \ preg_replace ( "#-#{$f['u']}" , '' , $ exception ) ; } $ this -> custom_exceptions = \ array_flip ( $ exception_keys ) ; $ this -> custom_exceptions_hash = $ new_hash ; $ this -> merged_exception_patterns = null ; }
Sets custom word hyphenations .
50,393
public function hyphenate ( array $ parsed_text_tokens , $ hyphen = '-' , $ hyphenate_title_case = false , $ min_length = 2 , $ min_before = 2 , $ min_after = 2 ) { if ( empty ( $ min_length ) || empty ( $ min_before ) || ! isset ( $ this -> pattern_trie ) || ! isset ( $ this -> pattern_exceptions ) ) { return $ parsed_text_tokens ; } if ( ! isset ( $ this -> merged_exception_patterns ) ) { $ this -> merge_hyphenation_exceptions ( ) ; } foreach ( $ parsed_text_tokens as $ key => $ text_token ) { $ parsed_text_tokens [ $ key ] = $ text_token -> with_value ( $ this -> hyphenate_word ( $ text_token -> value , $ hyphen , $ hyphenate_title_case , $ min_length , $ min_before , $ min_after ) ) ; } return $ parsed_text_tokens ; }
Hyphenates parsed text tokens .
50,394
protected function hyphenate_word ( $ word , $ hyphen , $ hyphenate_title_case , $ min_length , $ min_before , $ min_after ) { $ f = Strings :: functions ( $ word ) ; if ( empty ( $ f ) ) { return $ word ; } $ word_length = $ f [ 'strlen' ] ( $ word ) ; if ( $ word_length < $ min_length ) { return $ word ; } $ the_key = $ f [ 'strtolower' ] ( $ word ) ; if ( ! $ hyphenate_title_case && $ the_key !== $ word ) { return $ word ; } if ( isset ( $ this -> merged_exception_patterns [ $ the_key ] ) ) { $ pattern = $ this -> merged_exception_patterns [ $ the_key ] ; } else { $ pattern = $ this -> lookup_word_pattern ( $ the_key , $ f [ 'strlen' ] , $ f [ 'str_split' ] ) ; } $ word_parts = $ f [ 'str_split' ] ( $ word , 1 ) ; $ hyphenated_word = '' ; for ( $ i = 0 ; $ i < $ word_length ; $ i ++ ) { if ( isset ( $ pattern [ $ i ] ) && self :: is_odd ( $ pattern [ $ i ] ) && ( $ i >= $ min_before ) && ( $ i <= $ word_length - $ min_after ) ) { $ hyphenated_word .= $ hyphen ; } $ hyphenated_word .= $ word_parts [ $ i ] ; } return $ hyphenated_word ; }
Hyphenates a single word .
50,395
protected function lookup_word_pattern ( $ key , callable $ strlen , callable $ str_split ) { if ( null === $ this -> pattern_trie ) { return [ ] ; } $ search = '_' . $ key . '_' ; $ search_length = $ strlen ( $ search ) ; $ chars = $ str_split ( $ search ) ; $ word_pattern = [ ] ; for ( $ start = 0 ; $ start < $ search_length ; ++ $ start ) { $ node = $ this -> pattern_trie ; for ( $ step = $ start ; $ step < $ search_length ; ++ $ step ) { if ( ! $ node -> exists ( $ chars [ $ step ] ) ) { break ; } $ node = $ node -> get_node ( $ chars [ $ step ] ) ; foreach ( $ node -> offsets ( ) as $ pattern_offset ) { $ value = $ pattern_offset [ 0 ] ; $ offset = $ pattern_offset [ 1 ] + $ start - 1 ; $ word_pattern [ $ offset ] = isset ( $ word_pattern [ $ offset ] ) ? max ( $ word_pattern [ $ offset ] , $ value ) : $ value ; } } } return $ word_pattern ; }
Lookup the pattern for a word via the trie .
50,396
protected function merge_hyphenation_exceptions ( ) { $ exceptions = [ ] ; if ( ! empty ( $ this -> pattern_exceptions ) && ! empty ( $ this -> custom_exceptions ) ) { $ exceptions = array_merge ( $ this -> custom_exceptions , $ this -> pattern_exceptions ) ; } elseif ( ! empty ( $ this -> pattern_exceptions ) ) { $ exceptions = $ this -> pattern_exceptions ; } elseif ( ! empty ( $ this -> custom_exceptions ) ) { $ exceptions = $ this -> custom_exceptions ; } $ exception_patterns = [ ] ; foreach ( $ exceptions as $ exception_key => $ exception ) { $ exception_patterns [ $ exception_key ] = self :: convert_hyphenation_exception_to_pattern ( $ exception ) ; } $ this -> merged_exception_patterns = $ exception_patterns ; }
Merges hyphenation exceptions from the language file and custom hyphenation exceptions and generates patterns for all of them .
50,397
protected static function convert_hyphenation_exception_to_pattern ( $ exception ) { $ f = Strings :: functions ( $ exception ) ; if ( empty ( $ f ) ) { return null ; } $ lowercase_hyphened_word_parts = $ f [ 'str_split' ] ( $ exception , 1 ) ; $ lowercase_hyphened_word_length = $ f [ 'strlen' ] ( $ exception ) ; $ word_pattern = [ ] ; $ index = 0 ; for ( $ i = 0 ; $ i < $ lowercase_hyphened_word_length ; $ i ++ ) { if ( '-' === $ lowercase_hyphened_word_parts [ $ i ] ) { $ word_pattern [ $ index ] = 9 ; } else { $ index ++ ; } } return $ word_pattern ; }
Generates a hyphenation pattern from an exception .
50,398
public static function mb_str_split ( $ str , $ split_length = 1 ) { $ result = ( array ) \ preg_split ( '//u' , $ str , - 1 , PREG_SPLIT_NO_EMPTY ) ; if ( $ split_length > 1 ) { $ splits = [ ] ; foreach ( \ array_chunk ( $ result , $ split_length ) as $ chunk ) { $ splits [ ] = \ join ( '' , $ chunk ) ; } $ result = $ splits ; } return $ result ; }
Multibyte - safe str_split function .
50,399
public static function uchr ( $ codes ) { if ( \ is_scalar ( $ codes ) ) { $ codes = \ func_get_args ( ) ; } $ json = '"' ; foreach ( $ codes as $ code ) { $ json .= \ sprintf ( '\u%04x' , $ code ) ; } $ json .= '"' ; return \ json_decode ( $ json ) ; }
Converts decimal value to unicode character .