Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F28878595
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
tstarling
May 1 2019, 2:10 AM
2019-05-01 02:10:05 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
<?php
class Templates {
private $treesByLength = [];
public function findConflict( $node, $parts, $index = 0 ) {
if ( $index >= count( $parts ) ) {
// If we reached the leaf node then a conflict is detected
return '';
}
$part = $parts[$index];
$result = false;
if ( $part === '*' ) {
foreach ( $node as $key => $childNode ) {
$result = $this->findConflict( $childNode, $parts, $index + 1 );
if ( $result !== false ) {
$result = "$key/$result";
}
}
} else {
if ( isset( $node[$part] ) ) {
$result = $this->findConflict( $node[$part], $parts, $index + 1 );
if ( $result !== false ) {
$result = "$part/$result";
}
}
if ( $result === false && isset( $node['*'] ) ) {
$result = $this->findConflict( $node['*'], $parts, $index + 1 );
if ( $result !== false ) {
$result = "*/$result";
}
}
}
return $result;
}
public function add( $template ) {
$parts = explode( '/', $template );
$length = count( $parts );
if ( !isset( $this->treesByLength[$length] ) ) {
$this->treesByLength[$length] = [];
}
$tree =& $this->treesByLength[$length];
$conflict = $this->findConflict( $tree, $parts );
if ( $conflict !== false ) {
echo "Found conflict in template $template with existing template $conflict\n";
return false;
}
foreach ( $parts as $index => $part ) {
if ( !isset( $tree[$part] ) ) {
$tree[$part] = [];
}
$tree =& $tree[$part];
}
}
}
$templates = new Templates;
while ( false !== ( $line = fgets( STDIN ) ) ) {
$templates->add( trim( $line ) );
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7387715
Default Alt Text
raw.txt (1 KB)
Attached To
Mode
P8463 detect-template-ambiguity.php
Attached
Detach File
Event Timeline
Log In to Comment