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

unable to set multi-value context without warnings #4

Open
lsloan opened this issue Sep 13, 2023 · 1 comment
Open

unable to set multi-value context without warnings #4

lsloan opened this issue Sep 13, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@lsloan
Copy link
Member

lsloan commented Sep 13, 2023

When emitting an event with custom entities (e.g., a custom action), it's usually necessary to set a new context, or an additional one, on the event to define that entity. There are a couple of problems with that, however.

  1. events\Event::setContext only allows a single value to be set. It doesn't allow multiple values. It should allow multiples.

  2. As a workaround to the problem above, a custom context can be defined with an array of context URIs as its value.

    class CustomContext extends Context {
    	const
    		__default = [
    		'http://example.edu/caliper/context/v1p1_custom.json',
    		'http://purl.imsglobal.org/ctx/caliper/v1p1'];
    }
    
    $event = (new Event())
    	->setContext(new CustomContext());

    However, when that event is serialized to JSON, warnings are raised: Warning: Array to string conversion in umich-caliper-php/src/util/BasicEnum.php on line 104. That occurs when entities' contexts are compared to those of the event. util\BasicEnum::__toString and probably the code making the comparisons need to be updated to support multi-value contexts.

@lsloan lsloan added the bug Something isn't working label Sep 13, 2023
@lsloan lsloan self-assigned this Sep 13, 2023
@lsloan
Copy link
Member Author

lsloan commented Sep 13, 2023

Maybe context doesn't need to be set using enum. Maybe they should just be simple strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant