Skip to content

Instantly share code, notes, and snippets.

@ridinghoodmedia
Last active March 2, 2021 23:19
Show Gist options
  • Save ridinghoodmedia/6ee4161c1c2ca3100b2c0e40a4ee53d2 to your computer and use it in GitHub Desktop.
Save ridinghoodmedia/6ee4161c1c2ca3100b2c0e40a4ee53d2 to your computer and use it in GitHub Desktop.
Schema Planning
<?php
$properties = [
{property, 'name' => 'img'}
{property, 'name' => 'address'}
];
$properties = [
['img' => {property, 'name' => 'img'}],
['address' {property, 'name' => 'address'}]
];
/**
* Get a propery by name
*
* @param string $name Name of the property to find
*
* @return ?SchemaTypeProperty
*/
public function getPropertyByName(string $name) : ? SchemaTypeProperty
{
return $this->properties[$name];
}
/**
* Adds a property to the schema type
*
* @param SchemaTypeProperty $property
*/
public function addProperty(SchemaTypeProperty $property)
{
// See if property already exists, if it exists add expected types to the property and push it to $this->properties array
$propertytemp = $this->getPropertyByName($property->getName());
if (!is_null($propertytemp)) {
$propertytemp->addExpectedTypes($property->getExpectedTypes());
}
array_push($this->properties, (is_null($propertytemp)) ? $property : $propertytemp);
}
// User starts to build a new Schema
1. User: Selects the Person schema type
2. Software: shows new "schema form" with required properties -> Get required properties
$requiredProperties = $form->propertyRepository->getRequiredProperties();
// Add the required property fields to the form as a default
foreach ($requiredProperties as $property) {
$form->addPropertyField($property);
}
3. Software: allows user to add additional *valid* properties -> Get valid properties
$form->propertyBuilder->getValidProperties();
4. User: Fills out required properties
5. User: Adds and fills out 2 additional optional properties
6. User: Saves form
Person [
'properties' => [
'URL' => 'example.com',
]
]
class SchemaPropertyManager()
{
private function getValidProperties()
{
$parentTypes = getParentProperties();
$ownTypes = getOwnProperties();
return $this->validProperties = array_merge($parentTypes, $ownTypes);
}
}
// Belongs to a post or page
class Schema(SchemaType, SchemaTypePropertyRepository)
{
// Array of Property objects
$properties = [];
}
// Can be a value for a SchemaProperty or a standalone Schema object
// Has one or more SchemaProperties
class SchemaType() {
$validProperties = [
'image'
];
$requiredProperties = [
];
}
// Belongs to a SchemaType (e.g. Person > jobTitle)
// Has a value of SchemaType or a DataType (e.g. funder: Organization)
class SchemaProperty () {
$type = 'DataType';
$schemaType = 'jobTitle';
$expectedTypes = [
'Properties' => [
'DefinedTerm'
],
'DataTypes' => [
'Text'
]
];
$value = [
"SchemaType" => "Text"
"data" => []
];
private function getExpectedTypes()
{
$this->db->getExpectedPropertyType($propertyName);
}
}
// Belongs to a SchemaProperty
class SchemaDataType()
{
$value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment