Skip to content

Conversation

@kdambekalns
Copy link
Member

This does some code cleanup and adds a new method fromClassAndMethodName($className, $methodName) to the LogEnvironment.

It be used like this:

LogEnvironment::fromClassAndMethodName(__CLASS__, __METHOD__)

and will return useful data – as opposed to LogEnvironment::fromMethodName(__METHOD__), which only works for static methods (SomeClass::someMethod or closures).

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

This does some code cleanup and adds a new method `fromClassAndMethodName($className, $methodName)` to the `LogEnvironment`.

It be used like this:

    LogEnvironment::fromClassAndMethodName(__CLASS__, __METHOD__)

and will return useful data – as opposed to `LogEnvironment::fromMethodName(__METHOD__)`, which only works for static methods (`SomeClass::someMethod` or closures).
* under the key FLOW_LOG_ENVIRONMENT to be set as part of the
* additional data in an log method call.
*/
public static function fromClassAndMethodName(string $className, string $methodName): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we also allow passing an object instead of the class name? That way you could just pass $this in most cases.

public static function fromClassAndMethodName(string|object $class, string $methodName): array
{
    $className = is_object($class) ? get_class($object) : $className;
...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that make it easier to use? You can even use $this::class if you like…

@robertlemke
Copy link
Member

Why is this a task and not a new (tiny) feature?

@kdambekalns
Copy link
Member Author

Why is this a task and not a new (tiny) feature?

So I can sneak it into 8.3… 😎

@kdambekalns kdambekalns changed the title TASK: Add fromClassAndMethodName() to LogEnvironment FEATURE: Add fromClassAndMethodName() to LogEnvironment Dec 4, 2024
Copy link
Member

@markusguenther markusguenther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, thank you @kdambekalns
It is a tiny tiny feature, but not sure if we should merge it in 8.3 or better 8.4 or so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants