public function notify(Observable &$subject, $eventType, IEventArguments $arguments) { if ($subject instanceof SlimSystem && $subject->get("root_class") != __CLASS__) { return; } $arguments->renderclass->setParent($this); }
public function setSubject(Observable &$subject) { $this->subject =& $subject; $this->subject->register($this, Observable::EVENT_COMPONENT_INCLUDED); $this->loadSettingsFromDirectory(SlimSystem::getInstance()->getFsBaseDir()); $this->notify($subject, Observable::EVENT_COMPONENT_INCLUDED, new EventComponentIncludedArguments($subject, "", get_class($subject), $subject)); }
/** * Creates the observer and attaches it to the observable subject object * * @param Observable $subject The observable object to attach the observer to */ function __construct(Observable &$subject) { // Attach this observer to the subject $subject->attach($this); // Store a reference to the subject object $this->subject = $subject; }
/** * Trigger observer function fired by observable * @param Observable $observable */ public function update(Observable $observable) { // looks for an observer method with the state name if (method_exists($this, $observable->getState())) { call_user_func_array(array($this, $observable->getState()), array($observable)); } }
public function update(Observable $speedo) { if ($speedo->getCurrentSpeed() <= 10) { $this->gear = 1; } elseif ($speedo->getCurrentSpeed() <= 20) { $this->gear = 2; } elseif ($speedo->getCurrentSpeed() <= 30) { $this->gear = 3; } else { $this->gear = 4; } }
/** * Intially sets up the page */ public function setupPage($login = false) { //Allow Plugins. Observable::Observable(); $this->login = $login; //Initial value for each variable $this->titlePage = $this->openFile("data/config/site_title.dat"); $this->titleName = "Impropery Loaded Page"; $this->leftTitle = "Left Column"; $this->leftContent = ""; $this->content = ""; $this->thePage = ""; $this->columns = 2; $this->tempOverride = null; if (empty($this->meta)) { //Setup Meta Class $this->meta = new Meta(); } $this->error_type = null; $this->redirect = null; //Setup the location of this file $this->base = ""; //Get left title $this->setLeftTitle(""); //Get left content $this->setLeftContent(""); //Check if any error messages are to be displayed $this->checkError(); }
public function Send($template_name = null, $mail_args = null, $email = null, $name = null) { if ($template_name && is_array($mail_args) && $email) { if (class_exists("Log", false)) Log::Log("Sending email '{$template_name}' to '{$email}'", E_USER_NOTICE); $this->ClearAddresses(); $this->SmartyBody = array($template_name, $mail_args); $this->AddAddress($email, $name); $this->Observable->Fire('BeforeSend', $this); } if (!parent::Send() && class_exists("Log", false)) Log::Log("Cannot send email:".$this->ErrorInfo, E_ERROR); $this->ClearAddresses(); }
public function __construct(Observable $observerClass, UserAddress $affectedClass) { $this->observerClass = $observerClass; $this->affectedClass = $affectedClass; $observerClass->register($this); }
/** * */ public function testOverrideObservers() { $observable = new Observable(); $observable->attachObserver('foo', function () { return 'foo'; }); $observable->attachObserver('foo', function () { return 'bar'; }); $this->assertEquals(['foo', 'bar'], $observable->notifyFoo('foo')); $observable->overrideObservers('foo', function () { return 'baz'; }); $this->assertEquals(['baz'], $observable->notifyFoo('foo')); }
//============================ class KillBot implements SplObserver { public function update(SplSubject $subject) { echo __CLASS__ . " says kill all humans." . PHP_EOL; } } class LoveBot implements SplObserver { public function update(SplSubject $subject) { echo __CLASS__ . " says kiss all humans." . PHP_EOL; } } // load the observable (SPLSubject) $robots = new Observable(); // load some observers $killbot = new KillBot(); $lovebot = new LoveBot(); // add the observers to the observable $robots->addObserver($killbot); $robots->addObserver($lovebot); // notify the observers of an event $robots->notify(); /* Observers output: KillBot says kill all humans LoveBot says kiss all humans */
/** * Starts the controller of the classes system */ public function GeneralSettingsModel() { //Allow Plugins. Observable::Observable(); }
/** * Override of the base AttachObserver so that when an observer is attached, it * will also be attached to all child objects. Note that some initialization * messages won't be observed unless you provide it in the Phreezer constructor */ public function AttachObserver($observer) { parent::AttachObserver($observer); $this->DataAdapter->AttachObserver($observer); }
/*---------- Design Patterns: Iterator Pattern ----------*/ /*$blogposts = getAllPosts(); $posts = new Posts($blogposts); foreach ($posts as $post) { echo($post->getTitle()); echo($post->getAuthor()); echo($post->getDate()); echo($post->getContent()); $comments = new Comments($post->getComments()); foreach ($comments as $comment) { echo($comment->getAuthor()); echo($comment->getContent()); } }*/ /*---------- Design Patterns: Observer Pattern ----------*/ $postmonitor = new Observable(); $ym = new YMNotifier(); $em = new EmailNotifier2(); $s = new stdClass(); $postmonitor->register($ym); $postmonitor->register($em); $postmonitor->register($s); $postmonitor->stateChange(); /*---------- Design Patterns: Proxy Pattern or Lazy Loading ----------*/ /*$client = new IXR_Client('http://localhost/exercises/php_exercises/chapter4/server.php'); if (!$client->query('time.getGMTTime')) { die("Something went wrong - " . $client->getErrorCode() . $client->getErrorMessage()); } echo($client->getResponse());*/ /*---------- Design Patterns: Decorator Pattern ----------*/
public function update(Observable $observable_in) { echo "Received update!\n"; var_dump($observable_in->getState()); }
return $this->state; } public function setState($value) { $this->state = $value; $this->setChanged(); $this->notifyObservers(); } } class ObserverFoo extends ObserverAbstract { public function update(ObservableInterface $observableObject, $arg) { echo 'Foo: ' . $observableObject->getState(); echo '<br/>'; } } class ObserverBar extends ObserverAbstract { public function update(ObservableInterface $observableObject, $arg) { echo 'Bar: ' . $observableObject->getState(); echo '<br/>'; } } $observableObject = new \Observable(); // hook observer $observableObject->addObserver(new \ObserverFoo()); $observableObject->addObserver(new \ObserverBar()); // notify $observableObject->setState('todo');
public function SEOModel() { Observable::Observable(); }
public function PageListModel() { Observable::Observable(); }
public function ModulesModel() { Observable::Observable(); }
public function setSubject(Observable &$subject) { $subject->register($this, Observable::EVENT_COMPONENT_INCLUDED); }
public function notifyObservers() { $this->observable->notifyObservers(); }
public function ModulesInstallModel() { Observable::Observable(); }
/** * Override of the base AttachObserver so that when an observer is attached, it * will also be attached to all child objects. Note that some initialization * messages won't be observed unless you provide it in the Phreezer constructor */ public function AttachObserver($observer) { parent::AttachObserver($observer); foreach ($this->DataAdapters as $adapter) { $adapter->AttachObserver($observer); } }
public function TemplateModel() { Observable::Observable(); }
public function ModuleUpdateModel() { Observable::Observable(); }
/** * @param mixed $notificationType * @param \Observable $caller * @return void */ public function notify($notificationType, \Observable $caller) { if ($notificationType == \Model::TAG_CHANGED) { \EventHandler::trigger('etag.change', [$caller->getLastReturnTag()]); } }
public function UsersModel() { Observable::Observable(); }
function Base() { Observable::Observable(); }
/** * @param \Amp\Observable $observable * @param callable(mixed $value): bool $filter * * @return \Amp\Observable */ function filter(Observable $observable, callable $filter) : Observable { $postponed = new Postponed(); $pending = true; $observable->subscribe(function ($value) use(&$pending, $postponed, $filter) { if ($pending) { try { if (!$filter($value)) { return null; } return $postponed->emit($value); } catch (\Throwable $exception) { $pending = false; $postponed->fail($exception); } } return null; }); $observable->when(function ($exception, $value) use(&$pending, $postponed) { if (!$pending) { return; } $pending = false; if ($exception) { $postponed->fail($exception); return; } $postponed->resolve($value); }); return $postponed->observe(); }
/** * Starts the controller of the classes system */ public function DashModel() { Observable::Observable(); }
public function EditorModel() { Observable::Observable(); }