From 05a38e51ae7ad221315a65dc6ea25e0a096d3f9b Mon Sep 17 00:00:00 2001
From: Josh Pollock <josh@calderawp.com>
Date: Thu, 5 Apr 2018 21:36:40 -0400
Subject: [PATCH] add a static accessor function for container

---
 Tests/Integration/FunctionsTest.php | 31 +++++++++++++++++++++++++++++
 composer.json                       |  3 ++-
 src/CalderaFormsQueries.php         | 27 +++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 Tests/Integration/FunctionsTest.php
 create mode 100644 src/CalderaFormsQueries.php

diff --git a/Tests/Integration/FunctionsTest.php b/Tests/Integration/FunctionsTest.php
new file mode 100644
index 0000000..44ce160
--- /dev/null
+++ b/Tests/Integration/FunctionsTest.php
@@ -0,0 +1,31 @@
+<?php
+
+
+namespace calderawp\CalderaFormsQuery\Tests\Integration;
+
+
+use function calderawp\CalderaFormsQueries\CalderaFormsQueries;
+use calderawp\CalderaFormsQuery\Features\FeatureContainer;
+
+class FunctionsTest extends IntegrationTestCase
+{
+
+	/**
+	 * Ensure that accessor function returns the right class type
+	 * @covers CalderaFormsQueries()
+	 */
+	public function testGetMainInstance()
+	{
+		$this->assertSame( FeatureContainer::class, get_class(CalderaFormsQueries()) );
+	}
+	/**
+	 * Ensure that accessor function returns the same class instance
+	 * @covers CalderaFormsQueries()
+	 */
+	public function testIsSameInstance()
+	{
+		$this->assertSame( CalderaFormsQueries(), CalderaFormsQueries() );
+		CalderaFormsQueries()->set('sivan', 'roy' );
+		$this->assertEquals( 'roy', CalderaFormsQueries()->get('sivan') );
+	}
+}
\ No newline at end of file
diff --git a/composer.json b/composer.json
index ef179fa..7adef13 100644
--- a/composer.json
+++ b/composer.json
@@ -22,7 +22,8 @@
     "autoload": {
         "psr-4": {
             "calderawp\\CalderaFormsQuery\\": "src"
-        }
+        },
+        "files": ["src/CalderaFormsQueries.php"]
     },
     "scripts" : {
         "tests" : "composer unit-tests && composer wp-tests",
diff --git a/src/CalderaFormsQueries.php b/src/CalderaFormsQueries.php
new file mode 100644
index 0000000..a901472
--- /dev/null
+++ b/src/CalderaFormsQueries.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace calderawp\CalderaFormsQueries;
+
+use calderawp\CalderaContainers\Service\Container;
+use calderawp\CalderaFormsQuery\Features\FeatureContainer;
+
+/**
+ * The CalderaFormsQueries
+ *
+ * Acts as static accessor for feature container
+ *
+ * @return FeatureContainer
+ */
+function CalderaFormsQueries()
+{
+	static $CalderaFormsQueries;
+	if( ! $CalderaFormsQueries ){
+		global $wpdb;
+		$CalderaFormsQueries = new FeatureContainer(
+			new Container(),
+			$wpdb
+		);
+	}
+
+	return $CalderaFormsQueries;
+}
\ No newline at end of file
-- 
GitLab