/** * Underscore to camelcase table name to namespaced table gateway classname, * e.g. directus_users => \Directus\Db\TableGateway\DirectusUsersTableGateway */ public static function makeTableGatewayFromTableName($acl, $table, $adapter) { $tableGatewayClassName = Formatting::underscoreToCamelCase($table) . "TableGateway"; $tableGatewayClassName = __NAMESPACE__ . "\\{$tableGatewayClassName}"; if (class_exists($tableGatewayClassName)) { return new $tableGatewayClassName($acl, $adapter); } return new self($acl, $table, $adapter); }
/** * HELPER FUNCTIONS */ public static function makeRowGatewayFromTableName($acl, $table, $adapter, $pkFieldName = 'id') { // Underscore to camelcase table name to namespaced row gateway classname, // e.g. directus_users => \Directus\Db\RowGateway\DirectusUsersRowGateway $rowGatewayClassName = Formatting::underscoreToCamelCase($table) . "RowGateway"; $rowGatewayClassName = __NAMESPACE__ . "\\{$rowGatewayClassName}"; if (class_exists($rowGatewayClassName)) { return new $rowGatewayClassName($acl, $pkFieldName, $table, $adapter); } return new self($acl, $pkFieldName, $table, $adapter); }
/** * @param $table * @param $adapter * @param string $primaryKeyColumn * * @return BaseRowGateway */ public static function makeRowGatewayFromTableNameSkipAcl($table, $adapter, $primaryKeyColumn = 'id') { // Underscore to camelcase table name to namespaced row gateway classname, // e.g. directus_users => \Directus\Db\RowGateway\DirectusUsersRowGateway $rowGatewayClassName = Formatting::underscoreToCamelCase($table) . 'RowGateway'; $rowGatewayClassName = __NAMESPACE__ . '\\' . $rowGatewayClassName; if (class_exists($rowGatewayClassName)) { return new $rowGatewayClassName($primaryKeyColumn, $table, $adapter); } return new self($primaryKeyColumn, $table, $adapter); }
public function testUnderscoreToCamelCase() { $this->assertEquals(Formatting::underscoreToCamelCase('hello_world'), 'HelloWorld'); }