Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ Both filenames and file contents support a number of placeholders. These include
- `StubFullyQualifiedTestCaseBase`
- `StubTestCaseBase`

#### Modules Path Helper

The `modules_path` function returns the fully qualified path to your modules' directory. You may also use the `modules_path` function to generate a fully qualified path to a given file relative to the modules' directory.

This function works similarly to the existing `app_path` or `storage_path` helpers, allowing you to generate paths relative to the modules' directory effortlessly.

## Comparison to `nwidart/laravel-modules`

[Laravel Modules](https://nwidart.com/laravel-modules) is a great package that’s been
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
"autoload": {
"psr-4": {
"InterNACHI\\Modular\\": "src/"
}
},
"files": [
"src/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
16 changes: 16 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

if (! function_exists('modules_path')) {
/**
* Get the path to the modules folder.
*
* @param string $path
* @return string
*/
function modules_path($path = '')
{
$directory_name = config('app-modules.modules_directory', 'app-modules');
$path = base_path($directory_name . DIRECTORY_SEPARATOR . ltrim($path, '/\\'));
return str_replace('\\', '/', rtrim($path, '/\\'));
}
}
26 changes: 26 additions & 0 deletions tests/ModulesPathTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace InterNACHI\Modular\Tests;

use Illuminate\Support\Facades\Config;

class ModulesPathTest extends TestCase
{
public function testModulesPathWithoutArgument()
{
Config::set('app-modules.modules_directory', 'app-modules');

$expected = str_replace('\\', '/', base_path('app-modules'));

$this->assertEquals($expected, modules_path());
}

public function testModulesPathWithArgument()
{
Config::set('app-modules.modules_directory', 'app-modules');

$expected = str_replace('\\', '/', base_path('app-modules/module/test.php'));

$this->assertEquals($expected, modules_path('/module/test.php'));
}
}