Skip to content
Closed
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
45 changes: 45 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copilot Instructions for json-api PHP Library

## Overview
This library implements the [JSON API](http://jsonapi.org) specification in PHP 7, focusing on strict validity and immutability of produced documents. The codebase is organized to mirror JSON API concepts directly in PHP classes, making it easy to construct, validate, and test JSON API-compliant payloads.

## Architecture & Key Components
- **src/**: Core library code. Each file represents a JSON API concept (e.g., `ResourceObject`, `DataDocument`, `Error`, `Meta`, etc.).
- Subfolders like `Error/`, `Internal/`, and `Link/` contain specialized classes for error handling, internal data structures, and link objects.
- **examples/**: Runnable PHP scripts demonstrating typical usage. Start with `simple_doc.php` and `compound_doc.php`.
- **test/**: Comprehensive PHPUnit test suite. Each test file targets a specific document type or feature. Use these as references for correct usage and edge cases.

## Developer Workflows
- **Install dependencies**: `composer install`
- **Run tests**: `vendor\bin\phpunit` (or use `phpunit.xml.dist` for config)
- **Debugging**: Use the examples and tests to validate document structure. All objects are immutable; modify by creating new instances.

## Project Conventions
- **Immutability**: All core objects are immutable. Never mutate state; always instantiate new objects for changes.
- **Strict JSON API compliance**: The library enforces the spec rigorously. Invalid structures will throw exceptions early.
- **Constructor-based composition**: Build documents by composing objects via constructors, not setters.
- **Type safety**: Use explicit types for resource objects, identifiers, attributes, and relationships.
- **Error handling**: Use classes in `src/Error/` for structured error documents.

## Integration & Patterns
- **No external API calls**: The library is self-contained; integration is via PHP object composition.
- **Links and relationships**: Use classes in `src/Link/` and relationship objects (`ToOne`, `ToMany`, etc.) to model connections between resources.
- **Meta and pagination**: Use `Meta`, `MetaDocument`, and `Pagination` classes for additional document metadata and pagination links.

## Examples
- See `examples/simple_doc.php` for a minimal document.
- See `test/DataDocument/SingleResourceObjectTest.php` for a test-driven example of primary data construction.

## References
- [README.md](../README.md): Contains installation, usage, and links to examples/tests.
- [JSON API Spec](https://jsonapi.org/format/): Reference for document structure and rules.

---

**For AI agents:**
- Always prefer constructor-based composition and immutability.
- Reference tests for edge cases and correct usage.
- Document structure errors are surfaced early; validate inputs before composing objects.
- Use explicit class names and types as shown in examples/tests.

If any section is unclear or missing, please provide feedback for further refinement.