Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add getPath() to Context, and castor_path() global function #306

Closed

Conversation

TheoD02
Copy link
Contributor

@TheoD02 TheoD02 commented Mar 3, 2024

Description

Implementation of the castor_path() Function

Overview

This pull request introduces the castor_path() function, providing a convenient way to obtain the path of the current context. The function allows users to retrieve the current directory and, optionally, append a string to construct a full path.

Function Signature

use Castor\Attribute\AsTask;
use function Castor\castor_path;

#[AsTask()]
function foo(): void
{
    // Usage examples:
    $currentDirectory = castor_path(); // Gets the current directory path
    $computedPath = castor_path('foo/bar'); // Appends 'foo/bar' to the current directory path
    $computedPathWithContext = castor_path('foo/bar', context: my_tmp_context()); // Uses a specific context for path computation
}

Optional Arguments

  • The castor_path() function accepts an optional string argument, allowing users to append a directory name or path to the current directory.
  • Additionally, users can provide an optional context argument to specify a context other than the current one for path computation.

Method Explanation

The castor_path() function serves as a helpful shortcut for obtaining the current directory of the context, streamlining the process of constructing full paths.

Note on Naming

Please note that the naming of the function/method is subject to discussion. Feedback and suggestions for improvement are welcome.

src/Context.php Show resolved Hide resolved
@TheoD02 TheoD02 closed this Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants