Skip to content

shaunxcode/PHOS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHOS is an alternative php object system 
Some of the principal ideas are borrowed from CLOS, Smalltalk and Ruby
One of my pet peeves w/ development in almost all languages is the lack of ability to modify ONE method at a time w/o the boiler plate and clutter of all the other methods and signatures. Rather than utilizing an image based approach I am trying to utilize the file structure as the image by having each method be its own file.

WHAT IS WORKING:
A class is defined by having a folder beneath the class directory which defines the class name. Beneath that you can have a property directory which will be where all properties (private) are defined as files with the form [propertyname].[type]. This means that there are no dynamic properties. There can be public, private, protected and static directories which would each respectively contain files with the method argument list/bodies defined in them for the given scope. There can also be extend, implement and mixin files which contain class, interface or module names. Here is an example the text in [] is the content of the files:

class/Person/extend [Object]
            /implement [Creature, Playable]
            /mixin [Math, Serializable]
            /property/age.Second
                     /weight.Pound
                     /name.String
                     /actions.LiveList
            /private/recordAction [($action) 
                                   $this->actions->push($action); 
                                   return $this;]
            /public/increaseWeight [($amount)
                                    $this->recordAction('increase weight by' . $amount);
                                    $this->weight->increment($amount);
                                    return $this]
	
The concept of "rest" args now works so you can have an argument list like
	($x, $y = 20 . $restArgs)
	foreach($restArgs as $arg) {
		echo $arg + $x + $y;
	}

Mixins work which means the concept of modules must be introduced. A module can have properties and methods but can not be instantiated. Instead they can be included in a class by way of having a file with the name mixin which contains a comma separated list of which modules should be included. This will merge the properties/methods inline into the generated class. 

TODO:
* add comment parser

* deal with one line methods that start with ( ? Maybe just don't allow that? Or use | | instead i.e. like smalltalk? Or [ ] as that is not a valid way to start any statement in php, however neither is { }

* Standard class/module library 

* constructor expressions for properties i.e. if a property file contains a body of code it will create a private method which is called when instantiating the property in the generated constructor

* how do we handle static properties? right now there are only static methods

* also what about protected properties - right now we only have protected methods

* determine best way to handle generating the classes as they are modified - I imagine at "develop time" it will just regenerate them every time (unless this proves to be insanely slow) - I have considered perhaps doing some sort of checksum on the entirety of the files in the class dir? 
 
FUTURE:
new method which will be merged ito __construct

Namespaces and modules

ability for type declerations i.e.
(Inch $inches, Float $velocity)
return $inches * $velocity; 

Would compile into a function which did type checking on the arguments before the body was reached throwing the appropriate exception. 

What about allowing properties to be "accessbile" ala ruby so it implicitly creates getter/setters? 
properties/weight.Pounds.accessible ?

drag and drop editor meets the smalltalk environment

About

php meta-object system inspired by clos and smalltalk

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published