Monday, July 15, 2013

BuilderFoundation BlobQuery

Blob: A file, or a snippet/section of a file, or syntax-tree like thing. Typically, a blob requires a special parser.

BlobType: A blob has a type so that it can be handled by the appropriate parser.

SubBlobs: A blob in another blob.

BlobType-SubType: BlobTypes are not restricted to just the main blob types, but may define subtypes as well to make working within the syntax tree easier. A SubType is separated by a dash (maybe I should use a dot as the separator like NodeTypes does in TYPO3CR. What do you think?)

Example BlobTypes include: FluidBlob, HtmlBlob, PhpBlob, YamlBlob, TypoScriptBlob. I believe the packageBuilder will need an additional DomainBlob that doesn't map to any particular media-type. A Blob is essentially a generalized syntax tree, and a DomainBlob would be used to create PhpBlobs, it's just a more specialized/focused view of the information.

Example SubTypes (if I match the syntax tree exactly):

  • FluidBlob
    • FluidBlob-Array
    • FluidBlob-Boolean
    • FluidBlob-ObjectAccessor
    • FluidBlob-Numeric
    • FluidBlob-Text
    • FluidBlob-ViewHelper.
  • PhpBlob
    • PhpBlob-Class
    • PhpBlob-Function (PhpBlob-Method within Class)
    • PhpBlob-Interface
    • PhpBlob-Namespace
    • PhpBlob-Property
BlobQuery: This provides a context for FlowQuery. You create a new BlobQuery with a given path (typically a package path), and BlobQuery scans for files (optionally filtered by type), creates a Blob object for each of them, and adds them to an initial set of objects before returning a new FlowQuery instance that's using the set of Blobs.

OK, so here's a portion of the UML diagram I've been creating (in ArgoUML) to figure out what all needs to go in BuilderFoundation.

The OperationResolver expects simple values for priority, shortName, and Final, but I want to have one Operation class, BlobTypeSpecificOperations, that calls a variety of methods on the Blobs. To make this work, I add a BlobTypeSpecificOperationsAspect that calls a specialize initializeObject right after OperationResolver->initializeObject() gets called. This grabs the Cognifire.BuilderFoundation.BlobTypeOperations configuration and adds all of the registered blob operations to the list of operations. That means that if a blob has a special operation that only works for that BlobType, then add it as a method in the Blob itself (makes code organization feel better), and register that method as a BlobOperation in the Settings.yaml file. Whenever that operation gets called, it will go through BlobTypeSpecificOperations->evaluate() which will call the registered method on the blob for that operation.

The reason this is important, is you'll select a set of blobs with BlobQuery/FlowQuery, and then do some operation, and it will do that operation on all of the Blobs.

AOP is awesome!