Add magic getters for backward compatibility
[MAILPOET-3333]
This commit is contained in:
@@ -8,6 +8,7 @@ use MailPoet\Doctrine\EntityTraits\CreatedAtTrait;
|
|||||||
use MailPoet\Doctrine\EntityTraits\DeletedAtTrait;
|
use MailPoet\Doctrine\EntityTraits\DeletedAtTrait;
|
||||||
use MailPoet\Doctrine\EntityTraits\SafeToOneAssociationLoadTrait;
|
use MailPoet\Doctrine\EntityTraits\SafeToOneAssociationLoadTrait;
|
||||||
use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
|
use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
|
||||||
|
use MailPoet\Util\Helpers;
|
||||||
use MailPoetVendor\Doctrine\Common\Collections\ArrayCollection;
|
use MailPoetVendor\Doctrine\Common\Collections\ArrayCollection;
|
||||||
use MailPoetVendor\Doctrine\Common\Collections\Criteria;
|
use MailPoetVendor\Doctrine\Common\Collections\Criteria;
|
||||||
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -157,6 +158,18 @@ class NewsletterEntity {
|
|||||||
$this->queues = new ArrayCollection();
|
$this->queues = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This is here only for backward compatibility with custom shortcodes https://kb.mailpoet.com/article/160-create-a-custom-shortcode
|
||||||
|
* This can be removed after 2021-08-01
|
||||||
|
*/
|
||||||
|
public function __get($key) {
|
||||||
|
$getterName = 'get' . Helpers::underscoreToCamelCase($key, $capitaliseFirstChar = true);
|
||||||
|
$callable = [$this, $getterName];
|
||||||
|
if (is_callable($callable)) {
|
||||||
|
return call_user_func($callable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function __clone() {
|
public function __clone() {
|
||||||
// reset ID
|
// reset ID
|
||||||
$this->id = null;
|
$this->id = null;
|
||||||
|
@@ -7,6 +7,7 @@ use MailPoet\Doctrine\EntityTraits\CreatedAtTrait;
|
|||||||
use MailPoet\Doctrine\EntityTraits\DeletedAtTrait;
|
use MailPoet\Doctrine\EntityTraits\DeletedAtTrait;
|
||||||
use MailPoet\Doctrine\EntityTraits\SafeToOneAssociationLoadTrait;
|
use MailPoet\Doctrine\EntityTraits\SafeToOneAssociationLoadTrait;
|
||||||
use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
|
use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
|
||||||
|
use MailPoet\Util\Helpers;
|
||||||
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
||||||
use MailPoetVendor\Symfony\Component\Validator\Constraints as Assert;
|
use MailPoetVendor\Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
@@ -89,6 +90,18 @@ class SendingQueueEntity {
|
|||||||
*/
|
*/
|
||||||
private $newsletter;
|
private $newsletter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This is here only for backward compatibility with custom shortcodes https://kb.mailpoet.com/article/160-create-a-custom-shortcode
|
||||||
|
* This can be removed after 2021-08-01
|
||||||
|
*/
|
||||||
|
public function __get($key) {
|
||||||
|
$getterName = 'get' . Helpers::underscoreToCamelCase($key, $capitaliseFirstChar = true);
|
||||||
|
$callable = [$this, $getterName];
|
||||||
|
if (is_callable($callable)) {
|
||||||
|
return call_user_func($callable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
|
@@ -7,6 +7,7 @@ use MailPoet\Doctrine\EntityTraits\AutoincrementedIdTrait;
|
|||||||
use MailPoet\Doctrine\EntityTraits\CreatedAtTrait;
|
use MailPoet\Doctrine\EntityTraits\CreatedAtTrait;
|
||||||
use MailPoet\Doctrine\EntityTraits\DeletedAtTrait;
|
use MailPoet\Doctrine\EntityTraits\DeletedAtTrait;
|
||||||
use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
|
use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
|
||||||
|
use MailPoet\Util\Helpers;
|
||||||
use MailPoetVendor\Doctrine\Common\Collections\ArrayCollection;
|
use MailPoetVendor\Doctrine\Common\Collections\ArrayCollection;
|
||||||
use MailPoetVendor\Doctrine\Common\Collections\Collection;
|
use MailPoetVendor\Doctrine\Common\Collections\Collection;
|
||||||
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -129,6 +130,18 @@ class SubscriberEntity {
|
|||||||
$this->subscriberSegments = new ArrayCollection();
|
$this->subscriberSegments = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This is here only for backward compatibility with custom shortcodes https://kb.mailpoet.com/article/160-create-a-custom-shortcode
|
||||||
|
* This can be removed after 2021-08-01
|
||||||
|
*/
|
||||||
|
public function __get($key) {
|
||||||
|
$getterName = 'get' . Helpers::underscoreToCamelCase($key, $capitaliseFirstChar = true);
|
||||||
|
$callable = [$this, $getterName];
|
||||||
|
if (is_callable($callable)) {
|
||||||
|
return call_user_func($callable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
|
@@ -27,6 +27,7 @@ parameters:
|
|||||||
- '/(with|has) no (return )?typehint specified/' # exclude level 6 errors
|
- '/(with|has) no (return )?typehint specified/' # exclude level 6 errors
|
||||||
excludes_analyse:
|
excludes_analyse:
|
||||||
- ../../tests/_support/_generated
|
- ../../tests/_support/_generated
|
||||||
|
- ../../tests/unit/Entities/SubscriberEntityTest.php
|
||||||
|
|
||||||
# exclude level 6 errors
|
# exclude level 6 errors
|
||||||
checkGenericClassInNonGenericObjectType: false
|
checkGenericClassInNonGenericObjectType: false
|
||||||
|
16
tests/unit/Entities/SubscriberEntityTest.php
Normal file
16
tests/unit/Entities/SubscriberEntityTest.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Entities;
|
||||||
|
|
||||||
|
class SubscriberEntityTest extends \MailPoetUnitTest {
|
||||||
|
public function testMagicGetterReturnsData() {
|
||||||
|
$subscriber = new SubscriberEntity();
|
||||||
|
$subscriber->setWpUserId(4);
|
||||||
|
expect($subscriber->wp_user_id)->equals(4);// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMagicGetterReturnsNullForUnknown() {
|
||||||
|
$subscriber = new SubscriberEntity();
|
||||||
|
expect($subscriber->non_existing_property)->null();// phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user