GeezerVison is showing github.com — Merge pull request #62 from contentstack/enh/DX-5364 · contentstack/contentstack-php@83a775f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Cursor (optional) | | 2 | + | | 3 | +**Cursor** users: start at the repo root **[`AGENTS.md`](../../AGENTS.md)**. All conventions live in **`skills/*/SKILL.md`** (universal for any editor or tool). | | 4 | + | | 5 | +This folder only points contributors here so nothing editor-specific duplicates the canonical docs. |
Collapse file Copy file name to clipboard +49Lines changed: 49 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Contentstack PHP SDK – Agent guide | | 2 | + | | 3 | +**Universal entry point** for anyone automating or assisting work in this repo—AI agents (Cursor, Copilot, CLI tools), reviewers, and contributors. Conventions and detailed guidance live in **`skills/*/SKILL.md`**, not in editor-specific config, so the same instructions apply whether or not you use Cursor. | | 4 | + | | 5 | +## What this repo is | | 6 | + | | 7 | +- **Name:** [contentstack-php](https://github.com/contentstack/contentstack-php) | | 8 | +- **Purpose:** PHP library for the Contentstack **Delivery API**—stack initialization, content types, entries, assets, queries, sync, live preview config, and RTE rendering via the optional **`contentstack/utils`** package. | | 9 | +- **Out of scope:** This package is not the Management API client; it focuses on read/delivery patterns documented in the SDK README. | | 10 | + | | 11 | +## Tech stack (at a glance) | | 12 | + | | 13 | +| Area | Details | | | 14 | +|------|---------| | | 15 | +| Language | PHP (see `composer.json` `require.php`; supports legacy 5.5+ per package) | | | 16 | +| Layout | PSR-4 `Contentstack\` → `src/`; helper `src/Support/helper.php` | | | 17 | +| Tests | PHPUnit 10 → `test/` (`phpunit.xml`) | | | 18 | +| Docs | Doctum → `composer run generate:docs` (`config.php`) | | | 19 | +| Dependency | `contentstack/utils` for `Utils`, `Option`, RTE rendering helpers | | | 20 | + | | 21 | +## Commands (quick reference) | | 22 | + | | 23 | +```bash | | 24 | +composer install | | 25 | +composer test | | 26 | +# or: vendor/bin/phpunit | | 27 | +composer run generate:docs | | 28 | +``` | | 29 | + | | 30 | +Coverage and reports (when configured in `phpunit.xml`) write under `./tmp/`. | | 31 | + | | 32 | +## Where the real documentation lives: skills | | 33 | + | | 34 | +Read these **`SKILL.md` files** for full conventions—**this is the source of truth** for implementation and review: | | 35 | + | | 36 | +| Skill | Path | What it covers | | | 37 | +|-------|------|----------------| | | 38 | +| **Development workflow** | [`skills/dev-workflow/SKILL.md`](skills/dev-workflow/SKILL.md) | Branches, CI expectations, Composer test/docs, PR notes | | | 39 | +| **Contentstack PHP SDK / Utils** | [`skills/contentstack-utils/SKILL.md`](skills/contentstack-utils/SKILL.md) | `Contentstack::Stack`, `Stack`, queries, entries, assets, regions, `contentstack/utils`, semver | | | 40 | +| **PHP style & repo layout** | [`skills/php-style/SKILL.md`](skills/php-style/SKILL.md) | PSR-4, namespaces, docblocks, `src/` layout, PHP version constraints | | | 41 | +| **Testing** | [`skills/testing/SKILL.md`](skills/testing/SKILL.md) | PHPUnit, `test/` layout, constants/helpers, credentials hygiene | | | 42 | +| **Code review** | [`skills/code-review/SKILL.md`](skills/code-review/SKILL.md) | PR checklist (API, errors, deps/SCA, tests), Blocker/Major/Minor | | | 43 | +| **Framework / build** | [`skills/framework/SKILL.md`](skills/framework/SKILL.md) | `composer.json`, autoload, Doctum, optional CI workflows | | | 44 | + | | 45 | +An index with short “when to use” hints is in [`skills/README.md`](skills/README.md). | | 46 | + | | 47 | +## Using Cursor | | 48 | + | | 49 | +If you use **Cursor**, [`.cursor/rules/README.md`](.cursor/rules/README.md) only points to **`AGENTS.md`**—same source of truth as everyone else; no separate `.mdc` rule files. |
Collapse file Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Skills – Contentstack PHP SDK | | 2 | + | | 3 | +**This directory is the source of truth** for conventions (workflow, SDK API, style, tests, review, build). Read **`AGENTS.md`** at the repo root for the index and quick commands; each skill is a folder with **`SKILL.md`** (YAML frontmatter: `name`, `description`). | | 4 | + | | 5 | +## When to use which skill | | 6 | + | | 7 | +| Skill folder | Use when | | | 8 | +|--------------|----------| | | 9 | +| **dev-workflow** | Branches, `composer test` / docs, GitHub workflows, PR expectations | | | 10 | +| **contentstack-utils** | `Contentstack`, `Stack`, queries, entries, assets, sync, Composer `contentstack/utils` | | | 11 | +| **php-style** | PSR-4, namespaces, docblocks, `src/` structure, PHP compatibility | | | 12 | +| **testing** | PHPUnit, `test/` helpers, offline vs live tests, secrets | | | 13 | +| **code-review** | PR checklist, Blocker/Major/Minor, API and dependency gates | | | 14 | +| **framework** | `composer.json`, autoload, Doctum, dev dependencies | | | 15 | + | | 16 | +## How to use these docs | | 17 | + | | 18 | +- **Humans / any AI tool:** Start at **`AGENTS.md`**, then open the relevant **`skills/<name>/SKILL.md`**. | | 19 | +- **Cursor users:** **`.cursor/rules/README.md`** only points to **`AGENTS.md`** so guidance stays universal—no duplicate `.mdc` rule sets. |
Collapse file Copy file name to clipboard +56Lines changed: 56 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +name: code-review | | 3 | +description: PR checklist—API stability, docs, errors, compatibility, dependencies/SCA, tests; Blocker/Major/Minor. | | 4 | +--- | | 5 | + | | 6 | +# Code review – Contentstack PHP SDK | | 7 | + | | 8 | +## When to use | | 9 | + | | 10 | +- Reviewing a PR, self-review before submit, or automated review prompts. | | 11 | + | | 12 | +## Instructions | | 13 | + | | 14 | +Work through the checklist below. Optionally tag findings: **Blocker**, **Major**, **Minor**. | | 15 | + | | 16 | +### API design and stability | | 17 | + | | 18 | +- [ ] **Public API:** New or changed public methods/classes under `src/` are necessary, semver-conscious, and documented (`README.md` / `CHANGELOG.md` when user-visible). | | 19 | +- [ ] **Backward compatibility:** No breaking changes unless explicitly justified (e.g. major version). Prefer additive options and default config shapes. | | 20 | +- [ ] **Naming:** Matches existing SDK terminology (`Stack`, `ContentType`, `Query`, `Entry`, regions, etc.). | | 21 | + | | 22 | +### Error handling and robustness | | 23 | + | | 24 | +- [ ] **Errors:** New failure paths use or extend `CSException` / domain messages where appropriate; callers get actionable context. | | 25 | +- [ ] **Input:** Validate or document preconditions for public parameters; avoid silent failures on malformed API responses where the SDK should surface errors. | | 26 | +- [ ] **HTTP / JSON:** Parsing stays tolerant of documented Delivery API shapes; regressions for edge payloads are called out. | | 27 | + | | 28 | +### Dependencies and security | | 29 | + | | 30 | +- [ ] **Dependencies:** `composer.json` changes are justified; versions do not introduce known vulnerabilities. | | 31 | +- [ ] **SCA:** Address security findings (e.g. Snyk, org scanners) in the PR or via an agreed follow-up. | | 32 | + | | 33 | +### Testing | | 34 | + | | 35 | +- [ ] **Coverage:** New or modified behavior in `src/` has tests under `test/` when feasible. | | 36 | +- [ ] **Quality:** Tests are readable, deterministic, and follow existing helper/constants patterns. | | 37 | + | | 38 | +### Severity (optional) | | 39 | + | | 40 | +| Level | Examples | | | 41 | +|-------|----------| | | 42 | +| **Blocker** | Breaking public API without approval; security issue; no tests for new code where tests are practical | | | 43 | +| **Major** | Inconsistent errors; README examples that do not match real APIs | | | 44 | +| **Minor** | Style; minor docs | | | 45 | + | | 46 | +### Detailed review themes | | 47 | + | | 48 | +- **API:** Breaking public signatures without semver / CHANGELOG alignment. | | 49 | +- **Errors:** Exception changes that confuse callers without a version strategy. | | 50 | +- **README:** Examples must match real `Contentstack::Stack` and query APIs. | | 51 | +- **Dependencies:** New packages need justification and license awareness. | | 52 | + | | 53 | +## References | | 54 | + | | 55 | +- `skills/testing/SKILL.md` | | 56 | +- `skills/contentstack-utils/SKILL.md` |
Collapse file Copy file name to clipboard +47Lines changed: 47 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +name: contentstack-utils | | 3 | +description: PHP Delivery SDK API—Contentstack::Stack, queries, entries, assets, regions, sync; RTE via Composer package contentstack/utils. | | 4 | +--- | | 5 | + | | 6 | +# Contentstack PHP SDK (and Utils integration) | | 7 | + | | 8 | +## When to use | | 9 | + | | 10 | +- Implementing or changing Delivery API behavior, query builders, entries, assets, or sync. | | 11 | +- Updating `README.md` / `CHANGELOG.md` for user-visible behavior. | | 12 | +- Assessing semver impact of public API changes or **`contentstack/utils`** usage. | | 13 | + | | 14 | +## Main entry (consumer API) | | 15 | + | | 16 | +- Consumers use **`Contentstack\Contentstack::Stack(...)`** to obtain a **`Contentstack\Stack\Stack`** instance (API key, delivery token, environment, optional region / branch / live preview config). | | 17 | +- Query and fetch patterns flow through **content types**, **queries**, **entries**, and **assets** under `src/Stack/`. | | 18 | +- **RTE / JSON rendering:** `Contentstack::renderContent` and related helpers delegate to the **`contentstack/utils`** Composer package (`Contentstack\Utils\*`, `Option`). Do not reimplement utils behavior inside this SDK without strong reason. | | 19 | + | | 20 | +## Customization and options | | 21 | + | | 22 | +- Stack **config** array supports region, branch, live preview host/enable flags—preserve backward compatibility when extending keys. | | 23 | +- **ContentstackRegion** (or string region values per existing API) must stay consistent with documented Contentstack regions. | | 24 | + | | 25 | +## Data and HTTP | | 26 | + | | 27 | +- The SDK builds requests to Contentstack Delivery endpoints; keep URL construction, headers, and query parameters aligned with product documentation. | | 28 | +- **Result** parsing should match documented JSON shapes; guard against missing keys where the API allows omission. | | 29 | + | | 30 | +## Errors | | 31 | + | | 32 | +- Use **`Contentstack\Error\CSException`** and **`ErrorMessages`** patterns for domain failures. | | 33 | +- Avoid suppressing errors on public code paths without documentation. | | 34 | + | | 35 | +## Related package | | 36 | + | | 37 | +- **`contentstack/utils`** is a required dependency for RTE features shipped through this repo’s public surface; version ranges in `composer.json` should stay coherent with utils releases. | | 38 | + | | 39 | +## Docs and versioning | | 40 | + | | 41 | +- Follow **semver** for public API changes; update **CHANGELOG** and tag/release process per team norms. | | 42 | + | | 43 | +## References | | 44 | + | | 45 | +- [Contentstack](https://www.contentstack.com/) | | 46 | +- [PHP Delivery SDK docs](https://www.contentstack.com/docs/developers/sdks/content-delivery-sdk/php) | | 47 | +- `skills/php-style/SKILL.md`, `skills/framework/SKILL.md` |
Collapse file Copy file name to clipboard +39Lines changed: 39 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +name: dev-workflow | | 3 | +description: Branches, CI expectations, Composer test/docs, PR hygiene for Contentstack PHP SDK. | | 4 | +--- | | 5 | + | | 6 | +# Development workflow – Contentstack PHP SDK | | 7 | + | | 8 | +## When to use | | 9 | + | | 10 | +- Setting up locally, opening a PR, or aligning with repository automation. | | 11 | +- Answering “how do we run tests?” or “why did the branch check fail?” | | 12 | + | | 13 | +## Branches | | 14 | + | | 15 | +- Use feature branches (e.g. `feat/...`, `fix/...`, ticket branches). | | 16 | +- **`.github/workflows/check-branch.yml`** blocks pull requests into **`master`** unless the head branch is **`staging`** (SRE policy). Prefer PRs to **`staging`** when targeting a master release train. | | 17 | +- **Policy / SCA** workflows may run on PRs (see `.github/workflows/policy-scan.yml`, `sca-scan.yml`). | | 18 | + | | 19 | +## Running tests and build | | 20 | + | | 21 | +- **Install:** `composer install` | | 22 | +- **Tests:** `composer test` or `vendor/bin/phpunit` (config: `phpunit.xml`, suite under `test/`). | | 23 | +- Tests may require Contentstack credentials or mocks as documented in `test/README.md`—do not commit secrets. | | 24 | + | | 25 | +## Documentation generation | | 26 | + | | 27 | +- **Doctum:** `composer run generate:docs` (see `config.php`, output per Doctum defaults). | | 28 | + | | 29 | +## Pull requests | | 30 | + | | 31 | +- Build/tests pass locally where applicable (`composer test`). | | 32 | +- Follow the **code-review** skill (`skills/code-review/SKILL.md`) before merge. | | 33 | +- Prefer backward-compatible public API; call out breaking changes and semver. | | 34 | +- Update **`CHANGELOG.md`** when behavior visible to integrators changes. | | 35 | + | | 36 | +## References | | 37 | + | | 38 | +- `skills/testing/SKILL.md` | | 39 | +- `skills/code-review/SKILL.md` |
Collapse file Copy file name to clipboard +35Lines changed: 35 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +name: framework | | 3 | +description: Composer package, PSR-4 autoload, Doctum docs, PHP version constraints, dev dependencies. | | 4 | +--- | | 5 | + | | 6 | +# Framework / build – Contentstack PHP SDK | | 7 | + | | 8 | +## When to use | | 9 | + | | 10 | +- Editing `composer.json`, autoload blocks, or scripts. | | 11 | +- Changing minimum PHP version or required packages (e.g. `contentstack/utils`, PHPUnit). | | 12 | +- Updating documentation generation (`config.php`, Doctum). | | 13 | + | | 14 | +## Composer | | 15 | + | | 16 | +- **Package name:** `contentstack/contentstack` (see `composer.json`). | | 17 | +- **Autoload:** PSR-4 `Contentstack\` → `src/` plus `files` entry for `src/Support/helper.php`—keep in sync when moving classes. | | 18 | +- **Scripts:** `test` → PHPUnit; `generate:docs` → Doctum. | | 19 | + | | 20 | +## PHP version | | 21 | + | | 22 | +- `require.php` sets minimum language level; raising it is a **compatibility decision**—document in CHANGELOG and coordinate releases. | | 23 | + | | 24 | +## Documentation | | 25 | + | | 26 | +- **Doctum** scans `./src` per `config.php`; adjust only when layout changes. | | 27 | + | | 28 | +## CI / automation | | 29 | + | | 30 | +- This repo may not define a dedicated PHPUnit workflow file; still run **`composer test`** before merge. Branch and policy workflows live under `.github/workflows/`. | | 31 | + | | 32 | +## References | | 33 | + | | 34 | +- `skills/php-style/SKILL.md` | | 35 | +- `skills/dev-workflow/SKILL.md` |
Collapse file Copy file name to clipboard +42Lines changed: 42 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +name: php-style | | 3 | +description: PSR-4 layout, namespaces, docblocks, PHP compatibility, src/ structure for this SDK. | | 4 | +--- | | 5 | + | | 6 | +# PHP style and repo layout – Contentstack PHP SDK | | 7 | + | | 8 | +## When to use | | 9 | + | | 10 | +- Editing any PHP under `src/` or `test/`. | | 11 | +- Adding classes or changing namespace boundaries. | | 12 | + | | 13 | +## Layout | | 14 | + | | 15 | +- **Library code:** `src/` with namespace **`Contentstack\...`** matching PSR-4 paths. | | 16 | +- **Stack / Delivery:** `src/Stack/` (e.g. `Stack.php`, `ContentType/`, `Assets.php`, `BaseQuery.php`). | | 17 | +- **Config / errors / support:** `src/Config/`, `src/Error/`, `src/Support/`. | | 18 | +- **Entry point:** `src/Contentstack.php` exposes static factory and utils-facing helpers. | | 19 | + | | 20 | +## PHP language | | 21 | + | | 22 | +- Honor **minimum PHP** from `composer.json`; avoid syntax and standard-library features unavailable on that floor unless the constraint is explicitly raised. | | 23 | +- **`#[\AllowDynamicProperties]`** and legacy patterns may exist for backward compatibility—do not remove without a semver plan. | | 24 | + | | 25 | +## Documentation blocks | | 26 | + | | 27 | +- Existing files use **PHPDoc** (`@param`, `@return`, `@package`, etc.); new public APIs should include equivalent documentation for IDEs and Doctum. | | 28 | + | | 29 | +## Naming | | 30 | + | | 31 | +- **Classes:** `PascalCase` matching file names under PSR-4. | | 32 | +- **Methods:** `camelCase` consistent with surrounding code. | | 33 | +- Preserve established **public** names even when imperfect unless doing a **semver-major** cleanup with maintainer agreement. | | 34 | + | | 35 | +## Imports and visibility | | 36 | + | | 37 | +- Prefer `use` statements for classes in other namespaces; keep **public** surface explicit (public methods on classes intended for consumers). | | 38 | + | | 39 | +## References | | 40 | + | | 41 | +- `skills/framework/SKILL.md` (Composer, autoload) | | 42 | +- `skills/testing/SKILL.md` |
Collapse file Copy file name to clipboard +38Lines changed: 38 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +name: testing | | 3 | +description: PHPUnit—test/ layout, helpers, constants, coverage output, secrets hygiene. | | 4 | +--- | | 5 | + | | 6 | +# Testing – Contentstack PHP SDK | | 7 | + | | 8 | +## When to use | | 9 | + | | 10 | +- Adding or changing tests under `test/`. | | 11 | +- Debugging failing tests or coverage gaps. | | 12 | + | | 13 | +## Runner and config | | 14 | + | | 15 | +- **PHPUnit 10** via `vendor/bin/phpunit` or `composer test`. | | 16 | +- Configuration: **`phpunit.xml`**—suite directory `test/`, source coverage for `src/`, reports under `./tmp/` when generated. | | 17 | + | | 18 | +## Layout and naming | | 19 | + | | 20 | +- Tests live as `*Test.php` (e.g. `EntriesTest.php`, `AssetsTest.php`, `SyncTest.php`) alongside helpers such as `constants.php`, `utility.php`, `REST.php`. | | 21 | +- Reuse existing helpers before introducing parallel fixtures. | | 22 | + | | 23 | +## Integration vs unit | | 24 | + | | 25 | +- Some tests may exercise HTTP against Contentstack (see `test/README.md` **Prerequisite**); treat credentials as **local-only** or CI secrets—never commit API keys or tokens. | | 26 | + | | 27 | +## Coverage | | 28 | + | | 29 | +- Clover/HTML/text reports are configured in `phpunit.xml`; ensure `tmp/` (or chosen output dirs) stays out of version control if generated locally (see `.gitignore`). | | 30 | + | | 31 | +## Secrets | | 32 | + | | 33 | +- Tests must not embed real **delivery tokens** or **API keys** in the repository. | | 34 | + | | 35 | +## References | | 36 | + | | 37 | +- `skills/dev-workflow/SKILL.md` | | 38 | +- `skills/code-review/SKILL.md` |
|