| Server IP : 89.108.64.180 / Your IP : 216.73.217.95 Web Server : Apache/2.4.41 (Ubuntu) System : Linux 89-108-64-180.cloudvps.regruhosting.ru 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-root ( 1010) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/poseidon-gagra.ru/wp-content/plugins/awebooking/inc/Model/ |
Upload File : |
<?php
namespace AweBooking\Model;
use Awethemes\WP_Object\WP_Object;
abstract class Model extends WP_Object {
/**
* Mark the object readonly.
*
* @var bool
*/
protected $readonly = false;
/**
* Constructor.
*
* @param mixed $object The room-type based object or ID.
*/
public function __construct( $object = null ) {
$this->setup_attributes();
$this->map_attributes();
parent::__construct( $object );
}
/**
* Get an attribute from this object.
*
* @param string $key Attribute key name.
* @return mixed|null
*/
public function get( $key ) {
if ( array_key_exists( $key, $this->attributes ) ) {
return apply_filters( $this->prefix( "get_{$key}" ), $this->get_attribute( $key ), $this );
}
_doing_it_wrong(
__CLASS__ . '::' . __FUNCTION__,
sprintf( "Unknown attribute '%s' of %s", esc_html( $key ), esc_html( static::class ) ),
'3.1.0'
);
}
/**
* Flush object caches.
*
* @return void
*/
public function flush_cache() {
$this->clean_cache();
}
/**
* Do something before doing save.
*
* @return void
* @throws \RuntimeException
*/
protected function before_save() {
if ( true === $this->readonly ) {
throw new \RuntimeException( sprintf( 'Can\'t save a read-only object [%s]', static::class ) );
}
if ( method_exists( $this, 'saving' ) ) {
$this->saving();
}
$call_method = $this->exists() ? 'updating' : 'inserting';
if ( method_exists( $this, $call_method ) ) {
$this->$call_method();
}
}
/**
* Setup WP Core Object based on ID and object-type.
*
* @return void
*/
protected function setup_instance() {
switch ( $this->wp_type ) {
case 'awebooking_rooms':
if ( ! is_null( $room = abrs_get_raw_room( $this->id ) ) ) {
$this->set_instance( $room );
}
break;
case 'awebooking_item':
if ( ! is_null( $booking_item = abrs_get_raw_booking_item( $this->id ) ) ) {
$this->set_instance( $booking_item );
}
break;
default:
parent::setup_instance();
break;
}
}
/**
* Setup the attributes.
*
* @return void
*/
protected function setup_attributes() {}
/**
* Setup map meta data with attributes.
*
* @return void
*/
protected function map_attributes() {}
/**
* {@inheritdoc}
*/
protected function prefix( $hook_name ) {
return sprintf( 'abrs_%s_%s', $this->object_type, $hook_name );
}
/**
* Handle dynamic calls to get attributes.
*
* @param string $method The method name.
* @param array $parameters The method parameters.
* @return $this
*
* @throws \BadMethodCallException
*/
public function __call( $method, $parameters ) {
if ( 0 === strpos( $method, 'get_' ) ) {
return $this->get( substr( $method, 4 ) );
}
throw new \BadMethodCallException( sprintf( 'Method %s::%s does not exist.', static::class, $method ) );
}
}