startComponent{$expression}; ?>"; } /** * Get a new component hash for a component name. * * @param string $component * @return string */ public static function newComponentHash(string $component) { static::$componentHashStack[] = $hash = sha1($component); return $hash; } /** * Compile a class component opening. * * @param string $component * @param string $alias * @param string $data * @param string $hash * @return string */ public static function compileClassComponentOpening(string $component, string $alias, string $data, string $hash) { return implode("\n", [ '', 'getIterator() : [])); ?>', 'withName('.$alias.'); ?>', 'shouldRender()): ?>', 'startComponent($component->resolveView(), $component->data()); ?>', ]); } /** * Compile the end-component statements into valid PHP. * * @return string */ protected function compileEndComponent() { return 'renderComponent(); ?>'; } /** * Compile the end-component statements into valid PHP. * * @return string */ public function compileEndComponentClass() { $hash = array_pop(static::$componentHashStack); return $this->compileEndComponent()."\n".implode("\n", [ '', '', '', '', '', ]); } /** * Compile the slot statements into valid PHP. * * @param string $expression * @return string */ protected function compileSlot($expression) { return "slot{$expression}; ?>"; } /** * Compile the end-slot statements into valid PHP. * * @return string */ protected function compileEndSlot() { return 'endSlot(); ?>'; } /** * Compile the component-first statements into valid PHP. * * @param string $expression * @return string */ protected function compileComponentFirst($expression) { return "startComponentFirst{$expression}; ?>"; } /** * Compile the end-component-first statements into valid PHP. * * @return string */ protected function compileEndComponentFirst() { return $this->compileEndComponent(); } /** * Compile the prop statement into valid PHP. * * @param string $expression * @return string */ protected function compileProps($expression) { return " onlyProps{$expression} as \$__key => \$__value) { \$\$__key = \$\$__key ?? \$__value; } ?> exceptProps{$expression}; ?> \$__value) { \$\$__key = \$\$__key ?? \$__value; } ?> \$__value) { if (array_key_exists(\$__key, \$__defined_vars)) unset(\$\$__key); } ?> "; } /** * Compile the aware statement into valid PHP. * * @param string $expression * @return string */ protected function compileAware($expression) { return " \$__value) { \$__consumeVariable = is_string(\$__key) ? \$__key : \$__value; \$\$__consumeVariable = is_string(\$__key) ? \$__env->getConsumableComponentData(\$__key, \$__value) : \$__env->getConsumableComponentData(\$__value); } ?>"; } /** * Sanitize the given component attribute value. * * @param mixed $value * @return mixed */ public static function sanitizeComponentAttribute($value) { if ($value instanceof CanBeEscapedWhenCastToString) { return $value->escapeWhenCastingToString(); } return is_string($value) || (is_object($value) && ! $value instanceof ComponentAttributeBag && method_exists($value, '__toString')) ? e($value) : $value; } }