Complex classes like View often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use View, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class View implements \ArrayAccess { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var \WP_Post The backing post instance. |
||
| 21 | */ |
||
| 22 | private $post; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var \GV\View_Settings The settings. |
||
| 26 | * |
||
| 27 | * @api |
||
| 28 | * @since 2.0 |
||
| 29 | */ |
||
| 30 | public $settings; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var \GV\Widget_Collection The widets attached here. |
||
| 34 | * |
||
| 35 | * @api |
||
| 36 | * @since 2.0 |
||
| 37 | */ |
||
| 38 | public $widgets; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var \GV\GF_Form|\GV\Form The backing form for this view. |
||
| 42 | * |
||
| 43 | * Contains the form that is sourced for entries in this view. |
||
| 44 | * |
||
| 45 | * @api |
||
| 46 | * @since 2.0 |
||
| 47 | */ |
||
| 48 | public $form; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var \GV\Field_Collection The fields for this view. |
||
| 52 | * |
||
| 53 | * Contains all the fields that are attached to this view. |
||
| 54 | * |
||
| 55 | * @api |
||
| 56 | * @since 2.0 |
||
| 57 | */ |
||
| 58 | public $fields; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var array |
||
| 62 | * |
||
| 63 | * Internal static cache for gets, and whatnot. |
||
| 64 | * This is not persistent, resets across requests. |
||
| 65 | |||
| 66 | * @internal |
||
| 67 | */ |
||
| 68 | private static $cache = array(); |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var \GV\Join[] The joins for all sources in this view. |
||
| 72 | * |
||
| 73 | * @api |
||
| 74 | * @since future |
||
| 75 | */ |
||
| 76 | public $joins = array(); |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The constructor. |
||
| 80 | */ |
||
| 81 | 84 | public function __construct() { |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Register the gravityview WordPress Custom Post Type. |
||
| 89 | * |
||
| 90 | * @internal |
||
| 91 | * @return void |
||
| 92 | */ |
||
| 93 | public static function register_post_type() { |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Add extra rewrite endpoints. |
||
| 200 | * |
||
| 201 | * @return void |
||
| 202 | */ |
||
| 203 | 1 | public static function add_rewrite_endpoint() { |
|
| 221 | |||
| 222 | /** |
||
| 223 | * A renderer filter for the View post type content. |
||
| 224 | * |
||
| 225 | * @param string $content Should be empty, as we don't store anything there. |
||
| 226 | * |
||
| 227 | * @return string $content The view content as output by the renderers. |
||
| 228 | */ |
||
| 229 | 10 | public static function content( $content ) { |
|
| 353 | |||
| 354 | /** |
||
| 355 | * Checks whether this view can be accessed or not. |
||
| 356 | * |
||
| 357 | * @param string[] $context The context we're asking for access from. |
||
| 358 | * Can any and as many of one of: |
||
| 359 | * edit An edit context. |
||
| 360 | * single A single context. |
||
| 361 | * cpt The custom post type single page acessed. |
||
| 362 | * shortcode Embedded as a shortcode. |
||
| 363 | * oembed Embedded as an oEmbed. |
||
| 364 | * rest A REST call. |
||
| 365 | * @param \GV\Request $request The request |
||
| 366 | * |
||
| 367 | * @return bool|\WP_Error An error if this View shouldn't be rendered here. |
||
| 368 | */ |
||
| 369 | 19 | public function can_render( $context = null, $request = null ) { |
|
| 370 | 19 | if ( ! $request ) { |
|
| 371 | 1 | $request = gravityview()->request; |
|
| 372 | } |
||
| 373 | |||
| 374 | 19 | if ( ! is_array( $context ) ) { |
|
| 375 | 5 | $context = array(); |
|
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @filter `gravityview/view/can_render` Whether the view can be rendered or not. |
||
| 380 | * @param bool|\WP_Error $result The result. Default: null. |
||
| 381 | * @param \GV\View $view The view. |
||
| 382 | * @param string[] $context See \GV\View::can_render |
||
| 383 | * @param \GV\Request $request The request. |
||
| 384 | */ |
||
| 385 | 19 | if ( ! is_null( $result = apply_filters( 'gravityview/view/can_render', null, $this, $context, $request ) ) ) { |
|
| 386 | return $result; |
||
| 387 | } |
||
| 388 | |||
| 389 | 19 | if ( in_array( 'rest', $context ) ) { |
|
| 390 | // REST |
||
| 391 | 6 | if ( gravityview()->plugin->settings->get( 'rest_api' ) === '1' && $this->settings->get( 'rest_disable' ) === '1' ) { |
|
| 392 | 1 | return new \WP_Error( 'gravityview/rest_disabled' ); |
|
| 393 | 6 | } elseif ( gravityview()->plugin->settings->get( 'rest_api' ) !== '1' && $this->settings->get( 'rest_enable' ) !== '1' ) { |
|
| 394 | 1 | return new \WP_Error( 'gravityview/rest_disabled' ); |
|
| 395 | } |
||
| 396 | } |
||
| 397 | |||
| 398 | 19 | if ( in_array( 'csv', $context ) ) { |
|
| 399 | 1 | if ( $this->settings->get( 'csv_enable' ) !== '1' ) { |
|
| 400 | 1 | return new \WP_Error( 'gravityview/csv_disabled', 'The CSV endpoint is not enabled for this View' ); |
|
| 401 | } |
||
| 402 | } |
||
| 403 | |||
| 404 | /** |
||
| 405 | * This View is password protected. Nothing to do here. |
||
| 406 | */ |
||
| 407 | 19 | if ( post_password_required( $this->ID ) ) { |
|
| 408 | 3 | gravityview()->log->notice( 'Post password is required for View #{view_id}', array( 'view_id' => $this->ID ) ); |
|
| 409 | 3 | return new \WP_Error( 'gravityview/post_password_required' ); |
|
| 410 | } |
||
| 411 | |||
| 412 | 19 | if ( ! $this->form ) { |
|
| 413 | gravityview()->log->notice( 'View #{id} has no form attached to it.', array( 'id' => $this->ID ) ); |
||
| 414 | return new \WP_Error( 'gravityview/no_form_attached' ); |
||
| 415 | } |
||
| 416 | |||
| 417 | 19 | if ( ! in_array( 'shortcode', $context ) ) { |
|
| 418 | /** |
||
| 419 | * Is this View directly accessible via a post URL? |
||
| 420 | * |
||
| 421 | * @see https://codex.wordpress.org/Function_Reference/register_post_type#public |
||
| 422 | */ |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode? |
||
| 426 | * @deprecated |
||
| 427 | * @param[in,out] boolean `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded. Default: `true` |
||
| 428 | * @param int $view_id The ID of the View currently being requested. `0` for general setting |
||
| 429 | */ |
||
| 430 | 12 | $direct_access = apply_filters( 'gravityview_direct_access', true, $this->ID ); |
|
| 431 | |||
| 432 | /** |
||
| 433 | * @filter `gravityview/request/output/direct` Should this View be directly accessbile? |
||
| 434 | * @since 2.0 |
||
| 435 | * @param[in,out] boolean Accessible or not. Default: accessbile. |
||
| 436 | * @param \GV\View $view The View we're trying to directly render here. |
||
| 437 | * @param \GV\Request $request The current request. |
||
| 438 | */ |
||
| 439 | 12 | if ( ! apply_filters( 'gravityview/view/output/direct', $direct_access, $this, $request ) ) { |
|
| 440 | return new \WP_Error( 'gravityview/no_direct_access' ); |
||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Is this View an embed-only View? If so, don't allow rendering here, |
||
| 445 | * as this is a direct request. |
||
| 446 | */ |
||
| 447 | 12 | if ( $this->settings->get( 'embed_only' ) && ! \GVCommon::has_cap( 'read_private_gravityviews' ) ) { |
|
| 448 | 1 | return new \WP_Error( 'gravityview/embed_only' ); |
|
| 449 | } |
||
| 450 | } |
||
| 451 | |||
| 452 | /** Private, pending, draft, etc. */ |
||
| 453 | 19 | $public_states = get_post_stati( array( 'public' => true ) ); |
|
| 454 | 19 | if ( ! in_array( $this->post_status, $public_states ) && ! \GVCommon::has_cap( 'read_gravityview', $this->ID ) ) { |
|
| 455 | 3 | gravityview()->log->notice( 'The current user cannot access this View #{view_id}', array( 'view_id' => $this->ID ) ); |
|
| 456 | 3 | return new \WP_Error( 'gravityview/not_public' ); |
|
| 457 | } |
||
| 458 | |||
| 459 | 19 | return true; |
|
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Get joins associated with a view |
||
| 464 | * |
||
| 465 | * @param \WP_Post $post GravityView CPT to get joins for |
||
| 466 | * |
||
| 467 | * @since 2.0.11 |
||
| 468 | * |
||
| 469 | * @return \GV\Join[] Array of \GV\Join instances |
||
| 470 | */ |
||
| 471 | 84 | public static function get_joins( $post ) { |
|
| 472 | |||
| 473 | 84 | if ( ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) { |
|
| 474 | gravityview()->log->error( 'Cannot get joined forms; joins feature not supported.' ); |
||
| 475 | return array(); |
||
| 476 | } |
||
| 477 | |||
| 478 | 84 | if ( ! $post || 'gravityview' !== get_post_type( $post ) ) { |
|
| 479 | gravityview()->log->error( 'Only "gravityview" post types can be \GV\View instances.' ); |
||
| 480 | return array(); |
||
| 481 | } |
||
| 482 | |||
| 483 | 84 | $joins_meta = get_post_meta( $post->ID, '_gravityview_form_joins', true ); |
|
| 484 | |||
| 485 | 84 | if ( empty( $joins_meta ) ) { |
|
| 486 | 80 | return array(); |
|
| 487 | } |
||
| 488 | |||
| 489 | 4 | $joins = array(); |
|
| 490 | |||
| 491 | 4 | foreach ( $joins_meta as $meta ) { |
|
| 492 | 4 | if ( ! is_array( $meta ) || count( $meta ) != 4 ) { |
|
| 493 | continue; |
||
| 494 | } |
||
| 495 | |||
| 496 | 4 | list( $join, $join_column, $join_on, $join_on_column ) = $meta; |
|
| 497 | |||
| 498 | 4 | $join = GF_Form::by_id( $join ); |
|
| 499 | 4 | $join_on = GF_Form::by_id( $join_on ); |
|
| 500 | |||
| 501 | 4 | $join_column = is_numeric( $join_column ) ? GF_Field::by_id( $join, $join_column ) : Internal_Field( $join_column ); |
|
| 502 | 4 | $join_on_column = is_numeric( $join_on_column ) ? GF_Field::by_id( $join_on, $join_on_column ) : Internal_Field( $join_on_column ); |
|
| 503 | |||
| 504 | 4 | $joins [] = new Join( $join, $join_column, $join_on, $join_on_column ); |
|
| 505 | } |
||
| 506 | |||
| 507 | 4 | return $joins; |
|
| 508 | } |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Get joined forms associated with a view |
||
| 512 | * |
||
| 513 | * @since 2.0.11 |
||
| 514 | * |
||
| 515 | * @param int $post_id ID of the View |
||
| 516 | * |
||
| 517 | * @return \GV\GF_Form[] Array of \GV\GF_Form instances |
||
| 518 | */ |
||
| 519 | public static function get_joined_forms( $post_id = 0 ) { |
||
| 520 | |||
| 521 | if ( ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) { |
||
| 522 | gravityview()->log->error( 'Cannot get joined forms; joins feature not supported.' ); |
||
| 523 | return array(); |
||
| 524 | } |
||
| 525 | |||
| 526 | if ( empty( $post_id ) ) { |
||
| 527 | gravityview()->log->error( 'Cannot get joined forms; $post_id was empty' ); |
||
| 528 | return array(); |
||
| 529 | } |
||
| 530 | |||
| 531 | $joins_meta = get_post_meta( $post_id, '_gravityview_form_joins', true ); |
||
| 532 | |||
| 533 | if ( empty( $joins_meta ) ) { |
||
| 534 | return array(); |
||
| 535 | } |
||
| 536 | |||
| 537 | $forms_ids = array(); |
||
| 538 | |||
| 539 | foreach ( $joins_meta as $meta ) { |
||
| 540 | if ( ! is_array( $meta ) || count( $meta ) != 4 ) { |
||
| 541 | continue; |
||
| 542 | } |
||
| 543 | |||
| 544 | list( $join, $join_column, $join_on, $join_on_column ) = $meta; |
||
| 545 | |||
| 546 | $forms_ids [] = GF_Form::by_id( $join_on ); |
||
| 547 | } |
||
| 548 | |||
| 549 | return ( !empty( $forms_ids) ) ? $forms_ids : null; |
||
| 550 | } |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Construct a \GV\View instance from a \WP_Post. |
||
| 554 | * |
||
| 555 | * @param \WP_Post $post The \WP_Post instance to wrap. |
||
| 556 | * |
||
| 557 | * @api |
||
| 558 | * @since 2.0 |
||
| 559 | * @return \GV\View|null An instance around this \WP_Post if valid, null otherwise. |
||
| 560 | */ |
||
| 561 | 85 | public static function from_post( $post ) { |
|
| 562 | |||
| 563 | 85 | if ( ! $post || 'gravityview' !== get_post_type( $post ) ) { |
|
| 564 | 2 | gravityview()->log->error( 'Only gravityview post types can be \GV\View instances.' ); |
|
| 565 | 2 | return null; |
|
| 566 | } |
||
| 567 | |||
| 568 | 85 | if ( $view = Utils::get( self::$cache, "View::from_post:{$post->ID}" ) ) { |
|
| 569 | /** |
||
| 570 | * @filter `gravityview/view/get` Override View. |
||
| 571 | * @param \GV\View $view The View instance pointer. |
||
| 572 | * @since 2.1 |
||
| 573 | */ |
||
| 574 | 43 | do_action_ref_array( 'gravityview/view/get', array( &$view ) ); |
|
| 575 | |||
| 576 | 43 | return $view; |
|
| 577 | } |
||
| 578 | |||
| 579 | 85 | $view = new self(); |
|
| 580 | 85 | $view->post = $post; |
|
| 581 | |||
| 582 | /** Get connected form. */ |
||
| 583 | 85 | $view->form = GF_Form::by_id( $view->_gravityview_form_id ); |
|
| 584 | 85 | if ( ! $view->form ) { |
|
| 585 | gravityview()->log->error( 'View #{view_id} tried attaching non-existent Form #{form_id} to it.', array( |
||
| 586 | 'view_id' => $view->ID, |
||
| 587 | 'form_id' => $view->_gravityview_form_id ? : 0, |
||
| 588 | ) ); |
||
| 589 | } |
||
| 590 | |||
| 591 | 85 | $view->joins = $view->get_joins( $post ); |
|
| 592 | |||
| 593 | /** |
||
| 594 | * @filter `gravityview/configuration/fields` Filter the View fields' configuration array. |
||
| 595 | * @since 1.6.5 |
||
| 596 | * |
||
| 597 | * @deprecated Use `gravityview/view/configuration/fields` or `gravityview/view/fields` filters. |
||
| 598 | * |
||
| 599 | * @param $fields array Multi-array of fields with first level being the field zones. |
||
| 600 | * @param $view_id int The View the fields are being pulled for. |
||
| 601 | */ |
||
| 602 | 85 | $configuration = apply_filters( 'gravityview/configuration/fields', (array)$view->_gravityview_directory_fields, $view->ID ); |
|
| 603 | |||
| 604 | /** |
||
| 605 | * @filter `gravityview/view/configuration/fields` Filter the View fields' configuration array. |
||
| 606 | * @since 2.0 |
||
| 607 | * |
||
| 608 | * @param array $fields Multi-array of fields with first level being the field zones. |
||
| 609 | * @param \GV\View $view The View the fields are being pulled for. |
||
| 610 | */ |
||
| 611 | 85 | $configuration = apply_filters( 'gravityview/view/configuration/fields', $configuration, $view ); |
|
| 612 | |||
| 613 | /** |
||
| 614 | * @filter `gravityview/view/fields` Filter the Field Collection for this View. |
||
| 615 | * @since 2.0 |
||
| 616 | * |
||
| 617 | * @param \GV\Field_Collection $fields A collection of fields. |
||
| 618 | * @param \GV\View $view The View the fields are being pulled for. |
||
| 619 | */ |
||
| 620 | 85 | $view->fields = apply_filters( 'gravityview/view/fields', Field_Collection::from_configuration( $configuration ), $view ); |
|
| 621 | |||
| 622 | /** |
||
| 623 | * @filter `gravityview/view/configuration/widgets` Filter the View widgets' configuration array. |
||
| 624 | * @since 2.0 |
||
| 625 | * |
||
| 626 | * @param array $fields Multi-array of widgets with first level being the field zones. |
||
| 627 | * @param \GV\View $view The View the widgets are being pulled for. |
||
| 628 | */ |
||
| 629 | 85 | $configuration = apply_filters( 'gravityview/view/configuration/widgets', (array)$view->_gravityview_directory_widgets, $view ); |
|
| 630 | |||
| 631 | /** |
||
| 632 | * @filter `gravityview/view/widgets` Filter the Widget Collection for this View. |
||
| 633 | * @since 2.0 |
||
| 634 | * |
||
| 635 | * @param \GV\Widget_Collection $widgets A collection of widgets. |
||
| 636 | * @param \GV\View $view The View the widgets are being pulled for. |
||
| 637 | */ |
||
| 638 | 85 | $view->widgets = apply_filters( 'gravityview/view/widgets', Widget_Collection::from_configuration( $configuration ), $view ); |
|
| 639 | |||
| 640 | /** View configuration. */ |
||
| 641 | 85 | $view->settings->update( gravityview_get_template_settings( $view->ID ) ); |
|
| 642 | |||
| 643 | /** Add the template name into the settings. */ |
||
| 644 | 85 | $view->settings->update( array( 'template' => gravityview_get_template_id( $view->ID ) ) ); |
|
| 645 | |||
| 646 | /** View basics. */ |
||
| 647 | 85 | $view->settings->update( array( |
|
| 648 | 85 | 'id' => $view->ID, |
|
| 649 | ) ); |
||
| 650 | |||
| 651 | 85 | self::$cache[ "View::from_post:{$post->ID}" ] = &$view; |
|
| 652 | |||
| 653 | /** |
||
| 654 | * @filter `gravityview/view/get` Override View. |
||
| 655 | * @param \GV\View $view The View instance pointer. |
||
| 656 | * @since 2.1 |
||
| 657 | */ |
||
| 658 | 85 | do_action_ref_array( 'gravityview/view/get', array( &$view ) ); |
|
| 659 | |||
| 660 | 85 | return $view; |
|
| 661 | } |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Flush the view cache. |
||
| 665 | * |
||
| 666 | * @param int $view_id The View to reset cache for. Optional. Default: resets everything. |
||
| 667 | * |
||
| 668 | * @internal |
||
| 669 | */ |
||
| 670 | 95 | public static function _flush_cache( $view_id = null ) { |
|
| 671 | 95 | if ( $view_id ) { |
|
| 672 | 89 | unset( self::$cache[ "View::from_post:$view_id" ] ); |
|
| 673 | 89 | return; |
|
| 674 | } |
||
| 675 | 73 | self::$cache = array(); |
|
| 676 | 73 | } |
|
| 677 | |||
| 678 | /** |
||
| 679 | * Construct a \GV\View instance from a post ID. |
||
| 680 | * |
||
| 681 | * @param int|string $post_id The post ID. |
||
| 682 | * |
||
| 683 | * @api |
||
| 684 | * @since 2.0 |
||
| 685 | * @return \GV\View|null An instance around this \WP_Post or null if not found. |
||
| 686 | */ |
||
| 687 | 44 | public static function by_id( $post_id ) { |
|
| 688 | 44 | if ( ! $post_id || ! $post = get_post( $post_id ) ) { |
|
| 689 | 3 | return null; |
|
| 690 | } |
||
| 691 | 44 | return self::from_post( $post ); |
|
| 692 | } |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Determines if a view exists to begin with. |
||
| 696 | * |
||
| 697 | * @param int|\WP_Post|null $view The WordPress post ID, a \WP_Post object or null for global $post; |
||
| 698 | * |
||
| 699 | * @api |
||
| 700 | * @since 2.0 |
||
| 701 | * @return bool Whether the post exists or not. |
||
| 702 | */ |
||
| 703 | 6 | public static function exists( $view ) { |
|
| 704 | 6 | return get_post_type( $view ) == 'gravityview'; |
|
| 705 | } |
||
| 706 | |||
| 707 | /** |
||
| 708 | * ArrayAccess compatibility layer with GravityView_View_Data::$views |
||
| 709 | * |
||
| 710 | * @internal |
||
| 711 | * @deprecated |
||
| 712 | * @since 2.0 |
||
| 713 | * @return bool Whether the offset exists or not, limited to GravityView_View_Data::$views element keys. |
||
| 714 | */ |
||
| 715 | 13 | public function offsetExists( $offset ) { |
|
| 716 | 13 | $data_keys = array( 'id', 'view_id', 'form_id', 'template_id', 'atts', 'fields', 'widgets', 'form' ); |
|
| 717 | 13 | return in_array( $offset, $data_keys ); |
|
| 718 | } |
||
| 719 | |||
| 720 | /** |
||
| 721 | * ArrayAccess compatibility layer with GravityView_View_Data::$views |
||
| 722 | * |
||
| 723 | * Maps the old keys to the new data; |
||
| 724 | * |
||
| 725 | * @internal |
||
| 726 | * @deprecated |
||
| 727 | * @since 2.0 |
||
| 728 | * |
||
| 729 | * @return mixed The value of the requested view data key limited to GravityView_View_Data::$views element keys. |
||
| 730 | */ |
||
| 731 | 13 | public function offsetGet( $offset ) { |
|
| 732 | |||
| 733 | 13 | gravityview()->log->notice( 'This is a \GV\View object should not be accessed as an array.' ); |
|
| 734 | |||
| 735 | 13 | if ( ! isset( $this[ $offset ] ) ) { |
|
| 736 | return null; |
||
| 737 | } |
||
| 738 | |||
| 739 | 13 | switch ( $offset ) { |
|
| 740 | 13 | case 'id': |
|
| 741 | 13 | case 'view_id': |
|
| 742 | 1 | return $this->ID; |
|
| 743 | 13 | case 'form': |
|
| 744 | 13 | return $this->form; |
|
| 745 | 1 | case 'form_id': |
|
| 746 | 1 | return $this->form ? $this->form->ID : null; |
|
| 747 | 1 | case 'atts': |
|
| 748 | return $this->settings->as_atts(); |
||
| 749 | 1 | case 'template_id': |
|
| 750 | 1 | return $this->settings->get( 'template' ); |
|
| 751 | case 'widgets': |
||
| 752 | return $this->widgets->as_configuration(); |
||
| 753 | } |
||
| 754 | } |
||
| 755 | |||
| 756 | /** |
||
| 757 | * ArrayAccess compatibility layer with GravityView_View_Data::$views |
||
| 758 | * |
||
| 759 | * @internal |
||
| 760 | * @deprecated |
||
| 761 | * @since 2.0 |
||
| 762 | * |
||
| 763 | * @return void |
||
| 764 | */ |
||
| 765 | 1 | public function offsetSet( $offset, $value ) { |
|
| 768 | |||
| 769 | /** |
||
| 770 | * ArrayAccess compatibility layer with GravityView_View_Data::$views |
||
| 771 | * |
||
| 772 | * @internal |
||
| 773 | * @deprecated |
||
| 774 | * @since 2.0 |
||
| 775 | * @return void |
||
| 776 | */ |
||
| 777 | 1 | public function offsetUnset( $offset ) { |
|
| 780 | |||
| 781 | /** |
||
| 782 | * Be compatible with the old data object. |
||
| 783 | * |
||
| 784 | * Some external code expects an array (doing things like foreach on this, or array_keys) |
||
| 785 | * so let's return an array in the old format for such cases. Do not use unless using |
||
| 786 | * for back-compatibility. |
||
| 787 | * |
||
| 788 | * @internal |
||
| 789 | * @deprecated |
||
| 790 | * @since 2.0 |
||
| 791 | * @return array |
||
| 792 | */ |
||
| 793 | 9 | public function as_data() { |
|
| 805 | |||
| 806 | /** |
||
| 807 | * Retrieve the entries for the current view and request. |
||
| 808 | * |
||
| 809 | * @param \GV\Request The request. Unused for now. |
||
| 810 | * |
||
| 811 | * @return \GV\Entry_Collection The entries. |
||
| 812 | */ |
||
| 813 | 28 | public function get_entries( $request = null ) { |
|
| 903 | |||
| 904 | /** |
||
| 905 | * Last chance to configure the output. |
||
| 906 | * |
||
| 907 | * Used for CSV output, for example. |
||
| 908 | * |
||
| 909 | * @return void |
||
| 910 | */ |
||
| 911 | 1 | public static function template_redirect() { |
|
| 1009 | |||
| 1010 | 84 | public function __get( $key ) { |
|
| 1017 | } |
||
| 1018 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.