Skip to content

Instantly share code, notes, and snippets.

@Isengo1989
Created January 21, 2025 09:48
Show Gist options
  • Save Isengo1989/d77209134b7c178d3ba6e75386b128ee to your computer and use it in GitHub Desktop.
Save Isengo1989/d77209134b7c178d3ba6e75386b128ee to your computer and use it in GitHub Desktop.
Generate Field table for shopware 6 docs
#!/bin/bash
# Directory to search
DIRECTORY="src/Core/Framework/DataAbstractionLayer/Field"
# Print the table header
echo "| Name | Description | Extends | Implements StorageAware |"
echo "|:-----------------------------|:-----------------------------------------|:----------------------|:----------------------|"
# Iterate over each file ending with *Field.php in the specified directory
for FILE in "$DIRECTORY"/*Field.php; do
# Extract the class name
CLASS_NAME=$(grep -oP 'class \K\w+' "$FILE")
# Extract the name minus the "Field"
NAME=${CLASS_NAME%Field}
# Extract the parent class name
PARENT_CLASS=$(grep -oP 'extends \K\w+' "$FILE")
# Check if the class implements StorageAware
if grep -q 'implements StorageAware' "$FILE"; then
STORAGE_AWARE="x"
else
STORAGE_AWARE=""
fi
# Determine the description based on the parent class
case "$PARENT_CLASS" in
JsonField)
DESCRIPTION="Stores a JSON value"
;;
DateTimeField)
DESCRIPTION="Stores a DateTime value"
;;
FkField)
DESCRIPTION="Stores a foreign key value"
;;
IntField)
DESCRIPTION="Stores an integer value"
;;
FloatField)
DESCRIPTION="Stores a floating-point number"
;;
StringField)
DESCRIPTION="Stores a string value"
;;
BoolField)
DESCRIPTION="Stores a boolean value"
;;
BlobField)
DESCRIPTION="Stores a binary large object (BLOB) value"
;;
*)
DESCRIPTION="Stores a ${NAME,,} value"
;;
esac
# Print the class name, description, parent class, and whether it implements StorageAware
echo "| $CLASS_NAME | $DESCRIPTION | $PARENT_CLASS | $STORAGE_AWARE |"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment