Browse Source

Update PHP/phalcon to v3 (#2179)

* upgrade phalcon to v3

* install php7-compatible mongodb library for phalcon with composer

* MongoDB working with Phalcon incubator
knewmanTE 8 years ago
parent
commit
f786bd67d9

+ 1 - 0
frameworks/PHP/phalcon/.gitignore

@@ -2,6 +2,7 @@
 /app/logs
 /app/logs
 /app/compiled-templates/*.compiled
 /app/compiled-templates/*.compiled
 /bin
 /bin
+/vendor
 /vendors
 /vendors
 /build
 /build
 /dist
 /dist

+ 3 - 3
frameworks/PHP/phalcon/app/controllers/MongobenchController.php

@@ -8,18 +8,18 @@ class MongobenchController extends BenchController
 
 
     protected function getRandomWorld()
     protected function getRandomWorld()
     {
     {
-        return WorldsCollection::findFirst(array(array('_id' => mt_rand(1, 10000))));
+        return MongoWorldsCollection::findFirst(array(array('_id' => mt_rand(1, 10000))));
     }
     }
 
 
     protected function getFortunesArray()
     protected function getFortunesArray()
     {
     {
-        return FortunesCollection::find();
+        return MongoFortunesCollection::find();
     }
     }
 
 
     protected function buildFortune()
     protected function buildFortune()
     {
     {
         $fortune = parent::buildFortune();
         $fortune = parent::buildFortune();
-        $newFortune = new FortunesCollection();
+        $newFortune = new MongoFortunesCollection();
         $newFortune->_id = $fortune['id'];
         $newFortune->_id = $fortune['id'];
         $newFortune->message = $fortune['message'];
         $newFortune->message = $fortune['message'];
         return $newFortune;
         return $newFortune;

+ 14 - 0
frameworks/PHP/phalcon/app/models/MongoFortunesCollection.php

@@ -0,0 +1,14 @@
+<?php
+
+class MongoFortunesCollection extends \Phalcon\Mvc\MongoCollection
+{
+
+    public $_id;
+    public $message;
+
+    public function getSource()
+    {
+        return "fortune";
+    }
+
+}

+ 14 - 0
frameworks/PHP/phalcon/app/models/MongoWorldsCollection.php

@@ -0,0 +1,14 @@
+<?php
+
+class MongoWorldsCollection extends \Phalcon\Mvc\MongoCollection
+{
+
+    public $_id;
+    public $randomNumber;
+
+    public function getSource()
+    {
+        return "world";
+    }
+
+}

+ 1 - 1
frameworks/PHP/phalcon/benchmark_config.json

@@ -1,5 +1,5 @@
 {
 {
-  "framework": "php-phalcon",
+  "framework": "phalcon",
   "tests": [{
   "tests": [{
     "default": {
     "default": {
       "setup_file": "setup",
       "setup_file": "setup",

+ 6 - 0
frameworks/PHP/phalcon/composer.json

@@ -0,0 +1,6 @@
+{
+   "require": {
+   	"mongodb/mongodb" : "1.0.2",
+   	"phalcon/incubator": "3.0.2"
+   }
+}

+ 5 - 4
frameworks/PHP/phalcon/public/index.php

@@ -1,6 +1,7 @@
 <?php
 <?php
 
 
 define('APP_PATH', realpath('..'));
 define('APP_PATH', realpath('..'));
+require APP_PATH . "/vendor/autoload.php";
 
 
 try {
 try {
 
 
@@ -75,11 +76,11 @@ try {
     // Setting up the mongodb connection
     // Setting up the mongodb connection
     $di->set('mongo', function() use ($config) {
     $di->set('mongo', function() use ($config) {
         $mongodbConfig = $config->mongodb;
         $mongodbConfig = $config->mongodb;
-        
-        $mongo = new \MongoClient($mongodbConfig->url);
-        return $mongo->{$mongodbConfig->db};
+
+        $mongo = new \Phalcon\Db\Adapter\MongoDB\Client($mongodbConfig->url);
+        return $mongo->selectDatabase($mongodbConfig->db);
     });
     });
-    
+
     //Registering the collectionManager service
     //Registering the collectionManager service
     $di->set('collectionManager', function() {
     $di->set('collectionManager', function() {
         // Setting a default EventsManager
         // Setting a default EventsManager

+ 1 - 1
frameworks/PHP/phalcon/setup.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 #!/bin/bash
 
 
-fw_depends php5 phalcon nginx
+fw_depends php7 phalcon nginx composer
 
 
 sed -i 's|mongodb://localhost|mongodb://'"${DBHOST}"'|g' app/config/config.php
 sed -i 's|mongodb://localhost|mongodb://'"${DBHOST}"'|g' app/config/config.php
 sed -i 's|localhost|'"${DBHOST}"'|g' app/config/config.php
 sed -i 's|localhost|'"${DBHOST}"'|g' app/config/config.php

+ 7 - 12
toolset/setup/linux/frameworks/phalcon.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 #!/bin/bash
 
 
-fw_depends php5
+fw_depends php7
 
 
 RETCODE=$(fw_exists ${IROOT}/phalcon.installed)
 RETCODE=$(fw_exists ${IROOT}/phalcon.installed)
 [ ! "$RETCODE" == 0 ] || { \
 [ ! "$RETCODE" == 0 ] || { \
@@ -10,17 +10,12 @@ RETCODE=$(fw_exists ${IROOT}/phalcon.installed)
 # Enable the PHP phalcon extension
 # Enable the PHP phalcon extension
 sed -i 's|;extension=phalcon.so|extension=phalcon.so|g' $PHP_HOME/lib/php.ini
 sed -i 's|;extension=phalcon.so|extension=phalcon.so|g' $PHP_HOME/lib/php.ini
 
 
-fw_get -O https://github.com/phalcon/cphalcon/archive/phalcon-v2.0.13.tar.gz
-fw_untar phalcon-v2.0.13.tar.gz
-cd cphalcon-phalcon-v2.0.13/build/64bits 
-$PHP_HOME/bin/phpize
-# For some reason we have to point to php-config 
-# explicitly, it's not found by the prefix settings
-./configure --prefix=$PHP_HOME --exec-prefix=$PHP_HOME \
-  --with-php-config=$PHP_HOME/bin/php-config \
-  --enable-phalcon --quiet
-make --quiet
-make install
+VERSION="3.0.2"
+
+fw_get -O https://github.com/phalcon/cphalcon/archive/v${VERSION}.tar.gz
+fw_untar v${VERSION}.tar.gz
+cd cphalcon-${VERSION}/build
+./install
 
 
 echo "" > $IROOT/phalcon.installed
 echo "" > $IROOT/phalcon.installed