twig = $twig; $this->cpt_data = $cpt_data; $this->twig_template = $twig_template; $this->classes = $classes; } /** * @return array */ abstract protected function get_twig_variables( bool $is_for_validation = false ): array; /** * @param array $twig_variables */ abstract protected function render_twig_and_print_html( string $twig_template, array $twig_variables, bool $is_for_validation = false ): bool; /** * @param mixed $php_code_return * * @return array */ abstract protected function get_ajax_response_args( $php_code_return ): array; protected function get_classes(): string { $classes = ''; $classes .= '' !== $this->classes ? $this->classes . ' ' : ''; $classes .= '' !== $this->cpt_data->css_classes ? $this->cpt_data->css_classes . ' ' : ''; return $classes; } /** * @return mixed */ protected function eval_php_code( string $php_code ) { try { // @phpcs:ignore $custom_args = @eval( $php_code ); } catch ( Error $ex ) { return array(); } return $custom_args; } protected function get_twig(): Twig { return $this->twig; } protected function get_twig_template(): string { return $this->twig_template; } protected function set_twig_template( string $twig_template ): void { $this->twig_template = $twig_template; } // @phpstan-ignore-next-line protected function get_container(): ?ContainerInterface { $container = apply_filters( 'acf_views/container', null ); // wrong return check. // @phpstan-ignore-next-line . if ( false === ( $container instanceof ContainerInterface ) && null !== $container ) { return null; } return $container; } /** * @return array */ public function get_ajax_response( string $php_code = '' ): array { return $this->get_ajax_response_args( $this->eval_php_code( $php_code ) ); } public function get_markup_validation_error(): string { $twig_variables_for_validation = $this->get_twig_variables( true ); ob_start(); $this->render_twig_and_print_html( $this->twig_template, $twig_variables_for_validation, true ); $html = (string) ob_get_clean(); preg_match( '/(.*)$/', $html, $error_message ); $error_message = $error_message[1] ?? ''; $error_message = str_replace( '', '', $error_message ); $error_message = trim( $error_message ); return $error_message; } /** * @return array */ public function get_twig_variables_for_validation(): array { return $this->get_twig_variables( true ); } }