Solar_Mind_Read

By | April 1, 2009

Given yesterday’s news that Honda can now connect thoughts to robotic actuators, we have been given permission to talk about the Solar PHP implementation of that interface: Solar_Mind_Read.

<?php
class Solar_Mind_Read extends Solar_Base {

    protected $_Solar_Mind_Read = array(
        'mind' => null,
    );

    protected $_mind;

    public function __construct($config = null)
    {
        parent::__construct($config);

        $this->_mind = Solar::dependency(
            'Honda_Thought_Interface',
            $this->_config['mind']
        );
    }

    public function fetchIntent($search)
    {
        return $this->_mind->recall($search);
    }

    public function doWhatIMean($subject, $callback)
    {
        $intent = $this->fetchIntent($subject);
        return call_user_func($callback, $intent);
    }

    public function fetchPhpCode($task)
    {
        throw $this->_exception('ERR_NOT_IMPLEMENTED', array(
            'task' => $task,
        ));
    }
}
?>

As you can see, we leverage Solar’s base class and inherited configuration, along with its existing dependency injection functionality, to receive an existing Honda “thought” object at construction time. We can then see what the user’s intent is given a particular subject using the fetchIntent() method.

Even better, we can pass a callback to the doWhatIMean() method. This means that the user will always get what he wants, not merely what he asks for.

Finally, as a developer tool, the fetchPhpCode() method will take a task description and generate PHP code for it. We are waiting on a related patch to the PHP RunKit extension for this to be fully implemented. In the mean time, the automatic exception system finds the right exception class and throws it, with localized translation, and information about the task.

Once Solar_Mind_Read is complete, we believe we will be able to move on to Solar_Mind_Write. Together, these tools should help the developer with convincing his clients that what they really need is something that’s easier to implement, and then with actually implementing it.

Thanks for your attention; we hope this April Fool’s Day article piques your interest in the power of the Solar Framework for PHP 5. Many thanks to Clay Loveless for the subject idea. :-)

5 thoughts on “Solar_Mind_Read

  1. Suter

    Ohhh, yeah!!

    I was waiting for this for a long time now. Thank you.

    I wish you could add one more functinality to Solar…

    DoItAllByYourselfAndDontAskMeHow();

    With that I could even start using frameworks!

    Reply
  2. jeff Moore

    Help!

    I’ve accidentally passed “2009” to the back() method in Solar_Time_Travel. Now, when I try to pass $original_year I receive an exception with an error code of ERR_NOT_YET_IMPLEMENTED. Do you have a spare instance of Solar_Flux_Capacitor?

    Reply
  3. pmjones Post author

    @Jeff Moore: We’re sending a troubleshooter from the future to terminate the instance. He looks like Arnold Schwarzenegger; just do what he says.

    Reply
  4. Jacob Santos

    Is it bad, that I run the code and it came back blank? Then with the second execution, it came back, “Thoughts not found.”

    Should I curl up and cry, because I think I’m going to do that now.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *