Skip to content

Conversation

lonnieezell
Copy link
Member

Description

Adds API Transformers to CodeIgniter. This helps enforce best practices of never providing your entire object's values to the API. Instead, you would use a Transformer to build the API's response objects. This also allows:

  • Custom includes into the object (often for related models, but not required)
  • Allows the API consumer to limit the fields or includes returned
  • Integrates into the API pagination just introduced.
  • a CLI command to create starter Transformers

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn changed the title Api resources feat: API transformers Oct 16, 2025
@michalsn michalsn added new feature PRs for new features 4.7 labels Oct 16, 2025
Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

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

Not sure about the when / whenNot methods - they don't seem to bring much value, since they're basically just short if statement replacements. They could also be confusing at first glance because of our ConditionalTrait. But that might just be a first impression.

Seems like Deptrac rules have to be updated.

Overall, this seems like a really useful feature for people who work with APIs often.

@lonnieezell
Copy link
Member Author

Not sure about the when / whenNot methods - they don't seem to bring much value, since they're basically just short if statement replacements. They could also be confusing at first glance because of our ConditionalTrait. But that might just be a first impression.

No, you're right I think. It's mainly syntactic sugar and not really necessary. I'll remove them for now. I even looked at our ConditionalTrait to see if we could use it and it wouldn't work nicely so it's probably just confusing.

Thanks.

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

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

Looks great!

Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

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

Just reviewed on phone. I'll review again later but here are some comments.

Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@lonnieezell lonnieezell merged commit 05c7217 into codeigniter4:4.7 Oct 19, 2025
50 checks passed
@lonnieezell lonnieezell deleted the api-resources branch October 19, 2025 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.7 new feature PRs for new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants