/PHP/Classes/Plugins/CMS/DataProcessing/Persistence/DAOFactories/ContentDAOFactory.php

https://github.com/GunioRobot/eglooframework · PHP · 114 lines · 49 code · 13 blank · 52 comment · 23 complexity · 5f2aa4b4fbffe66b06ad4752641b30b7 MD5 · raw file

  1. <?php
  2. /**
  3. * ContentDAOFactory Class File
  4. *
  5. * Contains the class definition for the ContentDAOFactory
  6. *
  7. * Copyright 2011 eGloo, LLC
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. * @author George Cooper
  22. * @copyright 2011 eGloo, LLC
  23. * @license http://www.apache.org/licenses/LICENSE-2.0
  24. * @package $package
  25. * @subpackage $subpackage
  26. * @version 1.0
  27. */
  28. /**
  29. * ContentDAOFactory
  30. *
  31. * $short_description
  32. *
  33. * $long_description
  34. *
  35. * @package $package
  36. * @subpackage $subpackage
  37. */
  38. class ContentDAOFactory extends AbstractDAOFactory {
  39. //singleton holder
  40. protected static $singleton;
  41. /**
  42. * This class returns the appropriate DAO factory as specified by
  43. * an external property
  44. *
  45. * @return ConcreteContentDAOFactory a concrete DAO factory
  46. */
  47. private function getAppropriateFactory( $connection_name = 'egDataStore' ) {
  48. $retVal = null;
  49. if ( $connection_name === 'egDataStore' ) {
  50. $retVal = new eGlooDataStoreContentDAOFactory( $connection_name );
  51. } else if ( $connection_name === 'Akamai' ) {
  52. $retVal = new AkamaiContentDAOFactory( $connection_name );
  53. } else if ( $connection_name === 'CloudFront' ) {
  54. $retVal = new CloudFrontContentDAOFactory( $connection_name );
  55. } else if ( $connection_name === 'egCDNPrimary' ) {
  56. // If we didn't match a proper request for a non-DB ContentDAOFactory, we assume DB ContentDAOFactory
  57. $connection_info = eGlooConfiguration::getCDNConnectionInfo($connection_name);
  58. if ( $connection_info['provider'] === eGlooConfiguration::AKAMAI ) {
  59. $retVal = new AkamaiContentDAOFactory( $connection_name );
  60. } else if ( $connection_info['provider'] === eGlooConfiguration::CLOUDFRONT ) {
  61. $retVal = new CloudFrontContentDAOFactory( $connection_name );
  62. } else {
  63. // No connection specified and no default given...
  64. }
  65. } else {
  66. // If we didn't match a proper request for a non-DB ContentDAOFactory, we assume DB ContentDAOFactory
  67. $connection_info = eGlooConfiguration::getDatabaseConnectionInfo($connection_name);
  68. if ( $connection_info['engine'] === eGlooConfiguration::POSTGRESQL ) {
  69. $retVal = new PostgreSQLContentDAOFactory( $connection_name );
  70. } else if ( $connection_info['engine'] === eGlooConfiguration::MYSQLIOOP ) {
  71. $retVal = new MySQLiOOPContentDAOFactory( $connection_name );
  72. } else if ( $connection_info['engine'] === eGlooConfiguration::MYSQLI ) {
  73. $retVal = new MySQLiContentDAOFactory( $connection_name );
  74. } else if ( $connection_info['engine'] === eGlooConfiguration::MYSQL ) {
  75. $retVal = new MySQLContentDAOFactory( $connection_name );
  76. } else if ( $connection_info['engine'] === eGlooConfiguration::DOCTRINE ) {
  77. $retVal = new DoctrineContentDAOFactory( $connection_name );
  78. } else {
  79. // No connection specified and no default given...
  80. }
  81. }
  82. return $retVal;
  83. }
  84. /**
  85. * Singleton access to this AbstractDAOFactory
  86. *
  87. * @return AbstractDAOFactory the singleton reference of the AbstractDAOFactory
  88. */
  89. public static function getInstance() {
  90. if ( !isset(static::$singleton) ) {
  91. static::$singleton = new static( null );
  92. }
  93. return static::$singleton;
  94. }
  95. public function getImageContentDAO( $connection_name = 'egDataStore' ) {
  96. return $this->getAppropriateFactory( $connection_name )->getImageContentDAO();
  97. }
  98. public function getGenericFileContentDAO( $connection_name = 'egDataStore' ) {
  99. return $this->getAppropriateFactory( $connection_name )->getGenericFileContentDAO();
  100. }
  101. }