Tiger_Model_Code

@api Β· extends Tiger_Model_Table

Tiger_Model_Code β€” the Tiger Code store (executable PHP + client CSS/JS/HTML).

The DB row is the source of truth; Tiger_Code_Runtime compiles active rows into a cached bundle and executes/ships that (never this table per request). This model owns the table: transactional save() with a version snapshot, the compiler's load query, PHP syntax linting, and error-marking for the auto-deactivate rail.

SECURITY: php rows are server-executed β€” the service restricts them to the platform scope (org_id = '') and the code.execute ACL. css/js/html are client-injected.

Methods

save()

save(array $data, $id = null)

Save (insert/update) + snapshot to code_version, transactionally.

  • $data array β€” the code row fields
  • $id string|null β€” the code_id to update, or null to insert

Returns string β€” the code_id

Throws Throwable β€” on any failure (the transaction is rolled back and the error rethrown)

activeForLoad()

activeForLoad($language, $location, $orgId = '')

The compiler's rebuild query: active rows for a language + run location + org scope, in load order. Hits ix_code_load. Only ever called during a (rare) bundle rebuild.

  • $language string β€” the code language (php/phtml/js/css/html)
  • $location string β€” the run location
  • $orgId string β€” the org scope ('' = platform/global)

Returns Zend_Db_Table_Rowset_Abstract β€” the matching active rows, in load order

activeClient()

activeClient($runLocation, $orgId = '')

Active client-injected rows (css/js/html/phtml) for a run location + org scope, in load order β€” the source for the injection manifest + asset bundles (Tiger_Code_Runtime). PHP (the bootstrap bundle) is handled separately by activeForLoad().

  • $runLocation string β€” the run location
  • $orgId string β€” the org scope ('' = platform/global)

Returns Zend_Db_Table_Rowset_Abstract β€” the matching active client rows, in load order

lint()

lint($code)

Lint PHP source with php -l (out-of-process, never executed). Returns {ok:bool, error:?string}. The safety gate before any PHP row can go active.

  • $code string β€” the PHP source to lint (a code body, no opening tag needed)

Returns array{ok:bool,error:?string} β€” lint result

normalize()

normalize($code)

Strip a leading <?php/<?/BOM and a trailing ?> so stored code is a clean body.

  • $code string β€” the raw code

Returns string β€” the normalized code body

markError()

markError($id, $msg)

Flag a row inactive with the error that killed it (the auto-deactivate rail).

  • $id string β€” the code_id
  • $msg string β€” the error message (truncated to 2000 chars)

setActive()

setActive($id, $active)

Toggle active state (service lints PHP before activating). Clears last_error on activate.

  • $id string β€” the code_id
  • $active bool β€” whether the row should be active

restoreVersion()

restoreVersion($id, $version)

Restore a prior version (does NOT auto-reactivate β€” safer for executable code).

  • $id string β€” the code_id
  • $version int β€” the version number to restore

Returns string β€” the code_id

Throws RuntimeException β€” when the requested version doesn't exist