tristanpriem / qcal

Automatically exported from code.google.com/p/qcal
0 stars 0 forks source link

Create "with" function #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Because qCal components all at least attempt to maintain a fluent
interface, I would like to include a with() function somewhere in the
library that allows you to do this:

<?php
$qcal = with(new qCal_Component_Vevent(array('dtstart' => '2009-01-01
3:00pm')))
    ->addProperty(new qCal_Property_Dtend('2009-01-01 4:00pm'))
    ->addProperty(new qCal_Property_Summary('An event');
?>

All it does is return whatever is passed to it, so it'd look like:

<?php
function with($obj) {
    return $obj;
}

Original issue reported on code.google.com by Luke.Vis...@gmail.com on 10 Feb 2010 at 2:02

GoogleCodeExporter commented 9 years ago
Remember to wrap the function in a "function_exists":

<?php
if (!function_exists('with')) {
    function with ($obj) {
        return $obj;
    }
}
?>

Or we could put the function inside the qCal class so that we don't have to 
worry
about the function existing:

<?php
class qCal {

    public static function with($obj) {
        return $obj;
    }

}
?>

And then it would look like this:

<?php
$recur = qCal::with(new qCal_DateTime_Recur_Yearly('2012-01-01 10:00pm'))
    ->addRule(new qCal_DateTime_Recur_Rule_ByMonth(array(4,10)))
    ->addRule(new qCal_DateTime_Recur_Rule_ByMonthDay(23))
    ->addRule(new qCal_DateTime_Recur_Rule_ByHour(array(4,8)))
    ->addRule(new qCal_DateTime_Recur_Rule_ByMinute(30));

foreach ($recur as $recurrence) {
    pr($recurrenct->format('Y-m-d H:ia'));
}
?>

Original comment by Luke.Vis...@gmail.com on 10 Feb 2010 at 4:32