/** * Standard __construct * @param mixed null|object|string|array */ public function __construct($propertyMapperClass = null, $namespace = null) { if (!$namespace) { $namespace = \Bond\get_namespace($this); } $this->namespace = $namespace; // array-ify propertyMapperClasses if (!$propertyMapperClass) { $propertyMapperClass = [PropertyMapperObjectAccess::class]; } elseif (!is_array($propertyMapperClass)) { $propertyMapperClass = [$propertyMapperClass]; } foreach ($propertyMapperClass as $mapper) { $this->reflPropertyMappers[] = new \ReflectionClass($mapper); } }
/** * Standard constructor */ public function __construct($fullyQualifiedClass, array $registrations = []) { $this->class = new PhpClass(\Bond\get_unqualified_class($fullyQualifiedClass), \Bond\get_namespace($fullyQualifiedClass), false); if (!$registrations) { return; } foreach ($registrations as &$registration) { $registration = sprintf("\$em->register( '%s', '%s' );", addslashes($registration[0]), addslashes($registration[1])); } $registrations = new Format($registrations); $this->class->classComponents[] = new FunctionDeclaration('__construct', new Sformatf(<<<'PHP' /** * Register a set of entities with a EntityManager * @inheritDoc */ public function __construct( \Bond\EntityManager $em ) { %s } PHP , $registrations->indent(20))); }
/** * Get object properties that aren't in any way magically determined * * @param string $key */ public function __get($key) { switch ($key) { case 'data': $this->load(); // todo call get() on all the properties to instantiate any child objects return $this->data; case 'keys': return array_keys($this->data); break; // static properties // static properties case 'lateLoadProperty': case 'lateLoad': case 'isReadOnly': case 'inputValidate': case 'unsetableProperties': case 'additionalProperties': return static::${$key}; case 'namespace': return \Bond\get_namespace(get_called_class()); } throw new \InvalidArgumentException("`{$key}` is not known to magic method __get()"); }
public function testgetNamespace() { $this->assertSame(\Bond\get_namespace("Bond\\RecordManager"), "Bond"); $this->assertSame(\Bond\get_namespace("RecordManager"), ""); $this->assertSame(\Bond\get_namespace(new \Some\Weird\WonderFull\stdclass()), 'Some\\Weird\\WonderFull'); $this->assertSame(\Bond\get_namespace(new stdClass()), ""); }