| 1: | <?php |
| 2: | |
| 3: | namespace Zippy\Html; |
| 4: | |
| 5: | use Zippy\Interfaces\EventReceiver; |
| 6: | use Zippy\WebApplication; |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | abstract class PageFragment extends HtmlContainer implements EventReceiver |
| 17: | { |
| 18: | |
| 19: | |
| 20: | |
| 21: | public function Render() { |
| 22: | |
| 23: | $htmltag = $this->getTag(); |
| 24: | |
| 25: | $template = WebApplication::getApplication()->getTemplate(get_class($this)); |
| 26: | $dom = (new \DOMWrap\Document())->html($template); |
| 27: | |
| 28: | $body=$dom->find('body')->first()->html(); |
| 29: | $htmltag->html($body); |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | $this->beforeRender(); |
| 35: | |
| 36: | parent::RenderImpl(); |
| 37: | $this->afterRender(); |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | public function RequestHandle() { |
| 45: | $this->beforeRequest(); |
| 46: | parent::RequestHandle(); |
| 47: | $this->afterRequest(); |
| 48: | } |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | public function beforeRequest() { |
| 54: | |
| 55: | } |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | public function afterRequest() { |
| 61: | |
| 62: | } |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | protected function getOwnerPage() { |
| 69: | $owner = $this->getOwner(); |
| 70: | do { |
| 71: | if ($owner instanceof \Zippy\Html\WebPage) { |
| 72: | return $owner; |
| 73: | } |
| 74: | $owner = $owner->getOwner(); |
| 75: | } while ($owner != null); |
| 76: | |
| 77: | return null; |
| 78: | } |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | public function beforeRequestPage() { |
| 84: | |
| 85: | } |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: | public function afterRequestPage() { |
| 92: | |
| 93: | } |
| 94: | |
| 95: | protected function onAdded() { |
| 96: | $page = $this->getOwnerPage(); |
| 97: | if ($page instanceof \Zippy\Html\WebPage) { |
| 98: | $page->addBeforeRequestEvent($this, 'beforeRequestPage'); |
| 99: | $page->addAfterRequestEvent($this, 'afterRequestPage'); |
| 100: | } |
| 101: | } |
| 102: | final public function RequestMethod($method) { |
| 103: | $p = WebApplication::$app->getRequest()->request_params[$method]; |
| 104: | $post=null; |
| 105: | if($_SERVER["REQUEST_METHOD"]=='POST') { |
| 106: | |
| 107: | if(count($_POST)>0) { |
| 108: | $post = $_POST; |
| 109: | } else { |
| 110: | $post = file_get_contents('php://input'); |
| 111: | } |
| 112: | } |
| 113: | $answer = $this->{$method}($p, $post); |
| 114: | if(strlen($answer)) { |
| 115: | WebApplication::$app->getResponse()->addAjaxResponse($answer) ; |
| 116: | } |
| 117: | |
| 118: | } |
| 119: | } |
| 120: | |