Skip to content

Commit

Permalink
Merge pull request #652 from phalcon/3.0.x
Browse files Browse the repository at this point in the history
Bump version
  • Loading branch information
sergeyklay authored Jul 29, 2016
2 parents 6559062 + e9f83b8 commit a72891b
Show file tree
Hide file tree
Showing 209 changed files with 13,685 additions and 3,316 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ composer.phar
Vagrantfile
/build
/tests/_support/_generated/*.php
sample.db
102 changes: 29 additions & 73 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,53 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0

sudo: required
dist: precise
group: edge

services:
- memcached
- mysql
- mongodb
dist: trusty

env:
global:
- TEST_BT_HOST="127.0.0.1"
- TEST_BT_PORT="11300"
- TEST_MC_HOST="127.0.0.1"
- TEST_MC_PORT="11211"
- TEST_AS_HOST="127.0.0.1"
- TEST_AS_PORT="3000"
- TEST_DB_HOST="127.0.0.1"
- TEST_DB_PORT="3306"
- TEST_DB_USER="root"
- TEST_DB_PASSWD=""
- TEST_DB_NAME="incubator_tests"
- TEST_DB_CHARSET="utf8"
- DOCKER_COMPOSE_VERSION="1.7.0" PHALCON_SRC_PATH="${TRAVIS_BUILD_DIR}/cphalcon"
matrix:
- PHALCON_VERSION="2.0.13"
- PHALCON_VERSION="2.0.12"
- PHALCON_VERSION="2.0.11"
- PHALCON_VERSION="2.0.10"
- PHALCON_VERSION="2.0.9"
- PHALCON_VERSION="2.0.8"
- PHALCON_VERSION="2.0.7"
- PHALCON_VERSION="2.0.6"
- PHALCON_VERSION="2.0.5"
- PHALCON_VERSION="2.0.4"
- PHALCON_VERSION="3.0.x"
- PHALCON_VERSION="v3.0.0"

before_install:
- sudo service memcached stop
- sudo service docker stop
# Fix Hash Sum mismatch
- sudo apt-get purge -y google-chrome-stable
- sudo rm -f /etc/apt/sources.list.d/google*
- phpenv config-rm xdebug.ini
- bash tests/_ci/setup_beanstalkd.sh
- beanstalkd -v
- beanstalkd -l ${TEST_BT_HOST} -p ${TEST_BT_PORT} & # start queue listener
- sleep 5
- cd $TRAVIS_BUILD_DIR
- pecl channel-update pecl.php.net
- (CFLAGS="-O1 -g3 -fno-strict-aliasing"; pecl install yaml < /dev/null &)
- phpenv config-add tests/_ci/yaml.ini
- pecl install mongo < /dev/null &
- phpenv config-add tests/_ci/mongo.ini
- phpenv config-add tests/_ci/memcached.ini
- wget -O aerospike.tgz 'http://aerospike.com/download/server/latest/artifact/ubuntu12'
- tar -xvf aerospike.tgz
- cd aerospike-server-community-*-ubuntu12*
- sudo ./asinstall
- sudo service aerospike start
- sudo service aerospike status
- sleep 5
- cd $TRAVIS_BUILD_DIR

install:
- git clone --depth=1 --branch=${PHALCON_VERSION} https://github.com/phalcon/cphalcon.git ${PHALCON_SRC_PATH}
# Install Docker
- sudo apt-get update -qq
- sudo apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y --force-yes docker-engine
- sudo service docker restart
# Install Docker Compose
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
# Install Dependencies
- composer self-update
- git clone -q --depth=1 https://github.com/phalcon/cphalcon.git -b phalcon-v${PHALCON_VERSION}
- (cd cphalcon/ext; export CFLAGS="-g0 -O0 -std=gnu90"; phpize &> /dev/null && ./configure --silent --enable-phalcon &> /dev/null && make --silent -j2 &> /dev/null && make --silent install && phpenv config-add ../unit-tests/ci/phalcon.ini &> /dev/null)
- php --ri phalcon
- travis_retry composer require aerospike/aerospike-client-php "*"
- find vendor/aerospike/aerospike-client-php/ -name "*.sh" -exec chmod +x {} \;
- cd vendor/aerospike/aerospike-client-php
- sudo $(which composer) run-script -q post-install-cmd
- cd $TRAVIS_BUILD_DIR
- echo "extension=${TRAVIS_BUILD_DIR}/vendor/aerospike/aerospike-client-php/src/aerospike/modules/aerospike.so" | tee -a tests/_ci/aerospike.ini
- phpenv config-add tests/_ci/aerospike.ini
- php -m
- travis_retry composer install --prefer-source --no-interaction
- travis_retry composer install --ignore-platform-reqs --prefer-source --no-interaction
- travis_retry composer require --ignore-platform-reqs "duncan3dc/fork-helper:*"
# Pull images
- docker pull phalconphp/php:${TRAVIS_PHP_VERSION}
- docker pull phalconphp/zephir:${TRAVIS_PHP_VERSION}

before_script:
- stty cols 160
- mysql -e 'create database incubator_tests charset=utf8mb4 collate=utf8mb4_unicode_ci;'
- docker-compose -p incubator up -d
- sleep 1

script:
- vendor/bin/phpcs --standard=PSR2 --colors --extensions=php --encoding=utf-8 Library/
- vendor/bin/codecept build
- vendor/bin/codecept run

addons:
apt:
packages:
- libyaml-dev
- libssl-dev
- autoconf
- bash tests/build.sh

notifications:
email:
Expand Down
44 changes: 38 additions & 6 deletions Library/Phalcon/Acl/Adapter/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class Database extends Adapter
*/
protected $rolesInherits;

/**
* Default action for no arguments is allow
* @var int
*/
protected $noArgumentsDefaultAction = Acl::ALLOW;

/**
* Class constructor.
*
Expand Down Expand Up @@ -98,8 +104,10 @@ public function __construct(array $options)
* {@inheritdoc}
*
* Example:
* <code>$acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor');</code>
* <code>$acl->addRole('administrator', 'consultor');</code>
* <code>
* $acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor');
* $acl->addRole('administrator', 'consultor');
* </code>
*
* @param \Phalcon\Acl\Role|string $role
* @param string $accessInherits
Expand Down Expand Up @@ -342,8 +350,9 @@ public function dropResourceAccess($resourceName, $accessList)
* @param string $roleName
* @param string $resourceName
* @param array|string $access
* @param mixed $func
*/
public function allow($roleName, $resourceName, $access)
public function allow($roleName, $resourceName, $access, $func = null)
{
$this->allowOrDeny($roleName, $resourceName, $access, Acl::ALLOW);
}
Expand All @@ -366,9 +375,10 @@ public function allow($roleName, $resourceName, $access)
* @param string $roleName
* @param string $resourceName
* @param array|string $access
* @param mixed $func
* @return boolean
*/
public function deny($roleName, $resourceName, $access)
public function deny($roleName, $resourceName, $access, $func = null)
{
$this->allowOrDeny($roleName, $resourceName, $access, Acl::DENY);
}
Expand All @@ -386,10 +396,10 @@ public function deny($roleName, $resourceName, $access)
* @param string $role
* @param string $resource
* @param string $access
*
* @param array $parameters
* @return bool
*/
public function isAllowed($role, $resource, $access)
public function isAllowed($role, $resource, $access, array $parameters = null)
{
$sql = implode(' ', [
"SELECT " . $this->connection->escapeIdentifier('allowed') . " FROM {$this->accessList} AS a",
Expand Down Expand Up @@ -425,6 +435,28 @@ public function isAllowed($role, $resource, $access)
return $this->_defaultAccess;
}

/**
* Returns the default ACL access level for no arguments provided
* in isAllowed action if there exists func for accessKey
*
* @return int
*/
public function getNoArgumentsDefaultAction()
{
return $this->noArgumentsDefaultAction;
}

/**
* Sets the default access level for no arguments provided
* in isAllowed action if there exists func for accessKey
*
* @param int $defaultAccess Phalcon\Acl::ALLOW or Phalcon\Acl::DENY
*/
public function setNoArgumentsDefaultAction($defaultAccess)
{
$this->noArgumentsDefaultAction = intval($defaultAccess);
}

/**
* Inserts/Updates a permission in the access list
*
Expand Down
45 changes: 38 additions & 7 deletions Library/Phalcon/Acl/Adapter/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class Mongo extends Adapter
*/
protected $options;

/**
* Default action for no arguments is allow
* @var int
*/
protected $noArgumentsDefaultAction = Acl::ALLOW;

/**
* Class constructor.
*
Expand Down Expand Up @@ -161,8 +167,8 @@ public function isResource($resourceName)
* $acl->addResource(new Phalcon\Acl\Resource('customers'), 'search');
* $acl->addResource('customers', 'search');
* //Add a resource with an access list
* $acl->addResource(new Phalcon\Acl\Resource('customers'), array('create', 'search'));
* $acl->addResource('customers', array('create', 'search'));
* $acl->addResource(new Phalcon\Acl\Resource('customers'), ['create', 'search']);
* $acl->addResource('customers', ['create', 'search']);
* </code>
*
* @param \Phalcon\Acl\Resource $resource
Expand Down Expand Up @@ -280,7 +286,7 @@ public function dropResourceAccess($resourceName, $accessList)
* //Allow access to guests to search on customers
* $acl->allow('guests', 'customers', 'search');
* //Allow access to guests to search or create on customers
* $acl->allow('guests', 'customers', array('search', 'create'));
* $acl->allow('guests', 'customers', ['search', 'create']);
* //Allow access to any role to browse on products
* $acl->allow('*', 'products', 'browse');
* //Allow access to any role to browse on any resource
Expand All @@ -290,8 +296,9 @@ public function dropResourceAccess($resourceName, $accessList)
* @param string $roleName
* @param string $resourceName
* @param mixed $access
* @param mixed $func
*/
public function allow($roleName, $resourceName, $access)
public function allow($roleName, $resourceName, $access, $func = null)
{
$this->allowOrDeny($roleName, $resourceName, $access, Acl::ALLOW);
}
Expand All @@ -305,7 +312,7 @@ public function allow($roleName, $resourceName, $access)
* //Deny access to guests to search on customers
* $acl->deny('guests', 'customers', 'search');
* //Deny access to guests to search or create on customers
* $acl->deny('guests', 'customers', array('search', 'create'));
* $acl->deny('guests', 'customers', ['search', 'create']);
* //Deny access to any role to browse on products
* $acl->deny('*', 'products', 'browse');
* //Deny access to any role to browse on any resource
Expand All @@ -315,9 +322,10 @@ public function allow($roleName, $resourceName, $access)
* @param string $roleName
* @param string $resourceName
* @param mixed $access
* @param mixed $func
* @return boolean
*/
public function deny($roleName, $resourceName, $access)
public function deny($roleName, $resourceName, $access, $func = null)
{
$this->allowOrDeny($roleName, $resourceName, $access, Acl::DENY);
}
Expand All @@ -336,9 +344,10 @@ public function deny($roleName, $resourceName, $access)
* @param string $role
* @param string $resource
* @param string $access
* @param array $parameters
* @return boolean
*/
public function isAllowed($role, $resource, $access)
public function isAllowed($role, $resource, $access, array $parameters = null)
{
$accessList = $this->getCollection('accessList');
$access = $accessList->findOne([
Expand Down Expand Up @@ -367,6 +376,28 @@ public function isAllowed($role, $resource, $access)
return $this->_defaultAccess;
}

/**
* Returns the default ACL access level for no arguments provided
* in isAllowed action if there exists func for accessKey
*
* @return int
*/
public function getNoArgumentsDefaultAction()
{
return $this->noArgumentsDefaultAction;
}

/**
* Sets the default access level for no arguments provided
* in isAllowed action if there exists func for accessKey
*
* @param int $defaultAccess Phalcon\Acl::ALLOW or Phalcon\Acl::DENY
*/
public function setNoArgumentsDefaultAction($defaultAccess)
{
$this->noArgumentsDefaultAction = intval($defaultAccess);
}

/**
* Returns a mongo collection
*
Expand Down
2 changes: 1 addition & 1 deletion Library/Phalcon/Acl/Adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ $acl->setDefaultAction(Phalcon\Acl::DENY);
$acl->addRole(new Phalcon\Acl\Role('Admins'));

// Create the resource with its accesses
$acl->addResource('Products', array('insert', 'update', 'delete'));
$acl->addResource('Products', ['insert', 'update', 'delete']);

// Allow Admins to insert products
$acl->allow('Admin', 'Products', 'insert');
Expand Down
Loading

0 comments on commit a72891b

Please sign in to comment.