From 781dafd5181ec52ae56a41a2f478c1caa1ce0b56 Mon Sep 17 00:00:00 2001 From: Dexter Marks-Barber Date: Wed, 31 Jul 2019 09:05:33 +0100 Subject: [PATCH] Use directory seperator --- src/Apps/PrivateXeroApp.php | 28 ++++++++++++++++++++++++---- src/Utils.php | 29 +++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/Apps/PrivateXeroApp.php b/src/Apps/PrivateXeroApp.php index 1241c61..22a7f08 100644 --- a/src/Apps/PrivateXeroApp.php +++ b/src/Apps/PrivateXeroApp.php @@ -1,4 +1,5 @@ relationshipToModelMap); + sort($relationships); return collect($relationships); @@ -63,9 +66,15 @@ public function getAvailableRelationships() */ public function populateRelationshipToModelMap($modelSubdirectory, $prefix) { - $directory = Utils::getProjectRootDirectory(); + $vendor = Utils::getVendorDirectory(); + + $dependencyDirectory = Utils::normalizePath( + $vendor.'/calcinai/xero-php/src/' + ); - $modelsDirectory = $directory.'/vendor/calcinai/xero-php/src/XeroPHP/Models/'.$modelSubdirectory; + $modelsDirectory = Utils::normalizePath( + $dependencyDirectory.'/XeroPHP/Models/'.$modelSubdirectory + ); $di = new RecursiveDirectoryIterator($modelsDirectory); foreach (new RecursiveIteratorIterator($di) as $filename => $file) { @@ -73,8 +82,19 @@ public function populateRelationshipToModelMap($modelSubdirectory, $prefix) continue; } - $relationship = Str::camel($prefix.Str::plural(str_replace([$modelsDirectory, '.php', '/'], ['', '', ''], $filename))); - $model = str_replace([$directory.'/vendor/calcinai/xero-php/src/', '/', '.php'], ['', '\\', ''], $filename); + $relationship = Str::camel( + $prefix.Str::plural( + str_replace( + [$modelsDirectory, '.php', DIRECTORY_SEPARATOR], '', + $filename + ) + ) + ); + + $model = str_replace( + [$dependencyDirectory, DIRECTORY_SEPARATOR, '.php'], ['', '\\'], + $filename + ); $this->relationshipToModelMap[$relationship] = $model; } diff --git a/src/Utils.php b/src/Utils.php index b8dd673..33ff7b7 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -1,4 +1,5 @@