giginc / cakephp3-driver-cloud-firestore
Cloud Firestore direver for CakePHP 3.5
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: ^5.6|^7.0
- cakephp/cakephp: ^3.5
- google/cloud-firestore: ^1.19
Requires (Dev)
- cakephp/cakephp-codesniffer: ^4.0
- phpunit/phpunit: ^6.0
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2025-03-13 13:57:32 UTC
README
An Cloud Firestore for CakePHP 3.5,3.6,3.7
Installing via composer
Install composer and run:
composer require giginc/cakephp3-driver-cloud-firestore
Defining a connection
Now, you need to set the connection in your config/app.php file:
'Datasources' => [ ... 'cloud-firestore' => [ 'className' => 'Giginc\CloudFirestore\Database\Connection', 'driver' => 'Giginc\CloudFirestore\Database\Driver\CloudFirestore', 'projectId' => env('CLOUD_FIRESTORE_PROJECT_ID', 'project_id'), 'keyFile' => [], // Console. Ex: json_decode(file_get_contents($path), true). 'keyFilePath' => null, //The full path to your service account credentials .json file retrieved. 'retries' => 3, ], ],
Models
After that, you need to load Giginc\CloudFirestore\ORM\Table in your tables class:
Table
//src/Model/Table/ProductsTable.php namespace App\Model\Table; use Giginc\CloudFirestore\ORM\Table; /** * ProductsTable Table * * @uses Table * @package Table */ class ProductsTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->setTable('products'); } public static function defaultConnectionName() { return 'cloud-firestore'; } }
Entity
//src/Model/Entity/Product.php namespace App\Model\Entity; use Cake\ORM\Entity; /** * Product Entity * * @uses Entity * @package Entity */ class Product extends Entity { protected $_accessible = [ '*' => true, 'id' => false, ]; protected $_virtual = [ ]; } ## Controllers ```php namespace App\Controller; use App\Controller\AppController; /** * Pages Controller * * @property \App\Model\Table\PagesTable $Pages * * @method \App\Model\Entity\Review[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = []) */ class PagesController extends AppController { /** * Index method * * @access public * @return \Cake\Http\Response|void */ public function index() { $this->loadModel('Products'); // select $data = $this->Products->find() ->document('1') ->first(); // insert $this->Products->document('1') ->insert([ 'name' => 'iPhoneXR', 'description' => 'iPhoneXR', 'created_at' => '2021-04-21', ]); } }