OnClearEventArgs.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the MIT license. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\ORM\Event;
  20. use Doctrine\Common\EventArgs;
  21. use Doctrine\ORM\EntityManager;
  22. use Doctrine\ORM\EntityManagerInterface;
  23. /**
  24. * Provides event arguments for the onClear event.
  25. *
  26. * @link www.doctrine-project.org
  27. */
  28. class OnClearEventArgs extends EventArgs
  29. {
  30. /** @var EntityManagerInterface */
  31. private $em;
  32. /** @var string|null */
  33. private $entityClass;
  34. /**
  35. * @param string|null $entityClass Optional entity class.
  36. */
  37. public function __construct(EntityManagerInterface $em, $entityClass = null)
  38. {
  39. $this->em = $em;
  40. $this->entityClass = $entityClass;
  41. }
  42. /**
  43. * Retrieves associated EntityManager.
  44. *
  45. * @return EntityManager
  46. */
  47. public function getEntityManager()
  48. {
  49. return $this->em;
  50. }
  51. /**
  52. * Name of the entity class that is cleared, or empty if all are cleared.
  53. *
  54. * @return string|null
  55. */
  56. public function getEntityClass()
  57. {
  58. return $this->entityClass;
  59. }
  60. /**
  61. * Checks if event clears all entities.
  62. *
  63. * @return bool
  64. */
  65. public function clearsAllEntities()
  66. {
  67. return $this->entityClass === null;
  68. }
  69. }