mixin/polyfill.php - Import. Update comments.
[civicrm-core.git] / Civi / Test / EntityExample.php
CommitLineData
13515f0c
TO
1<?php
2
3namespace Civi\Test;
4
5/**
6 * Helper class for defining entity examples.
7 *
8 * By convention, you should name this class relative to the target workflow,
9 * as in:
10 *
11 * - Entity Name: ContributionRecur
12 * - Example Data: Civi\Test\ExampleData\ContributionRecur\Euro5990
13 * - Example Name: entity/ContributionRecur/Euro5900
14 */
15abstract class EntityExample implements ExampleDataInterface {
16
17 /**
18 * @var string
19 */
20 protected $entityName;
21
22 /**
23 * @var string
24 */
25 protected $exName;
26
27 public function __construct() {
28 if (!preg_match(';^(.*)[_\\\]([a-zA-Z0-9]+)[_\\\]([a-zA-Z0-9]+)$;', static::class, $m)) {
29 throw new \RuntimeException("Failed to parse class: " . static::class);
30 }
31 $this->entityName = $m[2];
32 $this->exName = $m[3];
33 }
34
35 protected function dao(): string {
36 return \CRM_Core_DAO_AllCoreTables::getFullName($this->entityName);
37 }
38
39 protected function bao(): string {
40 return \CRM_Core_DAO_AllCoreTables::getBAOClassName($this->getDAO());
41 }
42
43}