-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start on adding hostnames to routes (#7)
- Loading branch information
Showing
10 changed files
with
398 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace mattvb91\CaddyPhp; | ||
|
||
use mattvb91\CaddyPhp\Config\Apps\Http\Server\Routes\Match\Host; | ||
use mattvb91\CaddyPhp\Traits\IterableProps; | ||
|
||
/** | ||
* Walk the config objects to find the host we need | ||
* | ||
* TODO this is pretty inefficient there must be a better way to gather this. | ||
*/ | ||
function findHost($objectToWalk, $hostToFind, $path = '') | ||
{ | ||
if ($objectToWalk instanceof Host) { | ||
if ($objectToWalk->getIdentifier() === $hostToFind && str_contains($path, 'routes') && str_contains($path, 'match')) { | ||
return [ | ||
'path' => '/config/apps/http' . str_replace('_', '', $path) . '/host', | ||
'host' => &$objectToWalk, | ||
]; | ||
} | ||
} | ||
|
||
if (is_object($objectToWalk)) { | ||
$canIterate = array_key_exists(IterableProps::class, class_uses($objectToWalk)); | ||
|
||
if ($canIterate) { | ||
$props = $objectToWalk->iterateAllProperties(); | ||
if ($found = findHost($props, $hostToFind, $path)) { | ||
return $found; | ||
} | ||
|
||
} | ||
} | ||
|
||
if (is_array($objectToWalk)) { | ||
foreach ($objectToWalk as $key => $item) { | ||
if ($found = findHost($item, $hostToFind, $path . '/' . $key)) { | ||
return $found; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.