Exemple #1
0
/**
 * Changes internal pointer to a specific position in the resultset
 * Set new position if required and set this->_row
 */
PHP_METHOD(Phalcon_Mvc_Model_Resultset, seek) {

	zephir_fcall_cache_entry *_9 = NULL;
	zend_bool _1, _6;
	zval *position_param = NULL, *result, *row, *_0, *_2, *_3, *_4, *_5, *_7 = NULL, *_8;
	int position, ZEPHIR_LAST_CALL_STATUS;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 1, 0, &position_param);

	position = zephir_get_intval(position_param);


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_pointer"), PH_NOISY_CC);
	_1 = !ZEPHIR_IS_LONG(_0, position);
	if (!(_1)) {
		_2 = zephir_fetch_nproperty_this(this_ptr, SL("_row"), PH_NOISY_CC);
		_1 = Z_TYPE_P(_2) == IS_NULL;
	}
	if (_1) {
		ZEPHIR_OBS_VAR(_3);
		zephir_read_property_this(&_3, this_ptr, SL("_rows"), PH_NOISY_CC);
		if (Z_TYPE_P(_3) == IS_ARRAY) {
			ZEPHIR_OBS_VAR(row);
			_4 = zephir_fetch_nproperty_this(this_ptr, SL("_rows"), PH_NOISY_CC);
			if (zephir_array_isset_long_fetch(&row, _4, position, 0 TSRMLS_CC)) {
				zephir_update_property_this(this_ptr, SL("_row"), row TSRMLS_CC);
			}
			ZEPHIR_INIT_ZVAL_NREF(_5);
			ZVAL_LONG(_5, position);
			zephir_update_property_this(this_ptr, SL("_pointer"), _5 TSRMLS_CC);
			zephir_update_property_this(this_ptr, SL("_activeRow"), ZEPHIR_GLOBAL(global_null) TSRMLS_CC);
			RETURN_MM_NULL();
		}
		ZEPHIR_OBS_VAR(result);
		zephir_read_property_this(&result, this_ptr, SL("_result"), PH_NOISY_CC);
		_4 = zephir_fetch_nproperty_this(this_ptr, SL("_row"), PH_NOISY_CC);
		_6 = Z_TYPE_P(_4) == IS_NULL;
		if (_6) {
			_5 = zephir_fetch_nproperty_this(this_ptr, SL("_pointer"), PH_NOISY_CC);
			_6 = ZEPHIR_IS_LONG_IDENTICAL(_5, 0);
		}
		if (_6) {
			ZEPHIR_CALL_METHOD(&_7, result, "fetch", NULL, 0);
			zephir_check_call_status();
			zephir_update_property_this(this_ptr, SL("_row"), _7 TSRMLS_CC);
		}
		_4 = zephir_fetch_nproperty_this(this_ptr, SL("_pointer"), PH_NOISY_CC);
		if (ZEPHIR_GT_LONG(_4, position)) {
			ZEPHIR_INIT_VAR(_8);
			ZVAL_LONG(_8, position);
			ZEPHIR_CALL_METHOD(NULL, result, "dataseek", NULL, 0, _8);
			zephir_check_call_status();
			ZEPHIR_CALL_METHOD(&_7, result, "fetch", NULL, 0);
			zephir_check_call_status();
			zephir_update_property_this(this_ptr, SL("_row"), _7 TSRMLS_CC);
			ZEPHIR_INIT_ZVAL_NREF(_5);
			ZVAL_LONG(_5, position);
			zephir_update_property_this(this_ptr, SL("_pointer"), _5 TSRMLS_CC);
		}
		while (1) {
			_4 = zephir_fetch_nproperty_this(this_ptr, SL("_pointer"), PH_NOISY_CC);
			if (!(ZEPHIR_LT_LONG(_4, position))) {
				break;
			}
			ZEPHIR_CALL_METHOD(&_7, result, "fetch", &_9, 0);
			zephir_check_call_status();
			zephir_update_property_this(this_ptr, SL("_row"), _7 TSRMLS_CC);
			RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("_pointer") TSRMLS_CC));
		}
		ZEPHIR_INIT_ZVAL_NREF(_4);
		ZVAL_LONG(_4, position);
		zephir_update_property_this(this_ptr, SL("_pointer"), _4 TSRMLS_CC);
		zephir_update_property_this(this_ptr, SL("_activeRow"), ZEPHIR_GLOBAL(global_null) TSRMLS_CC);
	}
	ZEPHIR_MM_RESTORE();

}
/* Sets the TPM to the right state for the next test run.
 *
 * Functionally correct ordering is tricky.  Optimal ordering is even trickier
 * (no claim to this).  May succeed only partially and require a reboot to
 * continue (if the TPM was deactivated at boot).
 */
static uint32_t RollbackTest_SetTPMState(int initialize) {
  uint8_t disable, deactivated;
  int wrong_value = 0;

  /* Initializes if needed */
  if (initialize) {
    TlclLibInit();
    /* Don't worry if we're already started. */
    (void) TlclStartup();
    RETURN_ON_FAILURE(TlclContinueSelfTest());
    RETURN_ON_FAILURE(TlclAssertPhysicalPresence());
  }

  RETURN_ON_FAILURE(RollbackTest_PartiallyAdjustFlags(&disable, &deactivated));
  RETURN_ON_FAILURE(RollbackTest_AdjustIsInitialized());
  RETURN_ON_FAILURE(RollbackTest_AdjustMustUseBackup());
  RETURN_ON_FAILURE(RollbackTest_AdjustKernelVersions(&wrong_value));

  if (RBTS.KERNEL_VERSIONS_exists) {
    /* Adjusting these states only makes sense when the kernel versions space
     * exists. */
    RETURN_ON_FAILURE(RollbackTest_AdjustKernelPermissions(&wrong_value));
    RETURN_ON_FAILURE(RollbackTest_AdjustKernelValue(wrong_value));
    RETURN_ON_FAILURE(RollbackTest_AdjustKernelBackup());
  }

  RETURN_ON_FAILURE(RollbackTest_AdjustDeveloperMode());
  RETURN_ON_FAILURE(RollbackTest_SetOwnership(RBTS.owned));
  /* Do not remove spaces between SetOwnership and AdjustWriteCount, as that
   * might change the ownership state.  Also do not issue any writes from now
   * on, because AdjustWriteCount tries to avoid unneccessary clears, and after
   * that, any writes will obviously change the write count.
   */
  RETURN_ON_FAILURE(RollbackTest_AdjustWriteCount());

  /* Finally, disables and/or deactivates.  Must deactivate before disabling
   */
  if (!deactivated && RBTS.deactivated) {
    RETURN_ON_FAILURE(TlclSetDeactivated(1));
  }
  /* It's better to do this last, even though most commands we use work with
   * the TPM disabled.
   */
  if (!disable && RBTS.disable) {
    RETURN_ON_FAILURE(TlclClearEnable());
  }
  return TPM_SUCCESS;
}
Exemple #3
0
/**
 * Handle the command-line arguments.
 *  
 * 
 * <code>
 * 	$arguments = array(
 * 		'task' => 'taskname',
 * 		'action' => 'action',
 * 		'params' => array('parameter1', 'parameter2')
 * 	);
 * 	$console->handle($arguments);
 * </code>
 *
 * @param array $arguments
 * @return mixed
 */
PHP_METHOD(Phalcon_CLI_Console, handle){

	zval *_arguments = NULL, arguments = {}, dependency_injector = {}, events_manager = {}, event_name = {}, service = {}, router = {}, module_name = {};
	zval status = {}, *modules, exception_msg = {}, module = {}, path = {}, class_name = {}, module_object = {};
	zval namespace_name = {}, task_name = {}, action_name = {}, params = {}, dispatcher = {};

	phalcon_fetch_params(0, 0, 1, &_arguments);

	if (!_arguments) {
		array_init(&arguments);
	} else {
		PHALCON_CPY_WRT(&arguments, _arguments);
	}

	phalcon_return_property(&events_manager, getThis(), SL("_eventsManager"));

	ZVAL_STRING(&service, ISV(router));

	PHALCON_CALL_METHODW(&dependency_injector, getThis(), "getdi");
	if (Z_TYPE(dependency_injector) != IS_OBJECT) {
		PHALCON_THROW_EXCEPTION_FORMATW(phalcon_cli_console_exception_ce, "A dependency injection container is required to access the '%s' service", Z_STRVAL(service));
		return;
	}

	PHALCON_CALL_METHODW(&router, &dependency_injector, "getshared", &service);
	PHALCON_VERIFY_CLASSW(&router, phalcon_cli_router_ce);

	PHALCON_CALL_METHODW(NULL, &router, "handle", &arguments);
	PHALCON_CALL_METHODW(&module_name, &router, "getmodulename");
	if (zend_is_true(&module_name)) {
		if (Z_TYPE(events_manager) == IS_OBJECT) {
			ZVAL_STRING(&event_name, "console:beforeStartModule");

			PHALCON_CALL_METHODW(&status, &events_manager, "fire", &event_name, getThis(), &module_name);
			if (PHALCON_IS_FALSE(&status)) {
				RETURN_FALSE;
			}
		}

		modules = phalcon_read_property(getThis(), SL("_modules"), PH_NOISY);
		if (!phalcon_array_isset_fetch(&module, modules, &module_name)) {
			PHALCON_CONCAT_SVS(&exception_msg, "Module '", &module_name, "' isn't registered in the console container");
			PHALCON_THROW_EXCEPTION_ZVALW(phalcon_cli_console_exception_ce, &exception_msg);
			return;
		}

		if (Z_TYPE_P(&module) != IS_ARRAY) { 
			PHALCON_THROW_EXCEPTION_STRW(phalcon_cli_console_exception_ce, "Invalid module definition path");
			return;
		}

		if (phalcon_array_isset_fetch_str(&path, &module, SL("path"))) {
			convert_to_string_ex(&path);

			if (phalcon_file_exists(&path) == SUCCESS) {
				RETURN_ON_FAILURE(phalcon_require(Z_STRVAL(path)));
			} else {
				zend_throw_exception_ex(phalcon_cli_console_exception_ce, 0, "Modules definition path '%s' does not exist", Z_STRVAL(path));
				return;
			}
		}

		if (!phalcon_array_isset_fetch_str(&class_name, &module, SL("className"))) {
			ZVAL_STRING(&class_name, "Module");
		}

		PHALCON_CALL_METHODW(&module_object, &dependency_injector, "getshared", &class_name);
		PHALCON_CALL_METHODW(NULL, &module_object, "registerautoloaders");
		PHALCON_CALL_METHODW(NULL, &module_object, "registerservices", &dependency_injector);
		if (Z_TYPE(events_manager) == IS_OBJECT) {
			phalcon_update_property_this(getThis(), SL("_moduleObject"), &module_object);

			ZVAL_STRING(&event_name, "console:afterStartModule");

			PHALCON_CALL_METHODW(&status, &events_manager, "fire", &event_name, getThis(), &module_name);
			if (PHALCON_IS_FALSE(&status)) {
				RETURN_FALSE;
			}
		}
	}

	PHALCON_CALL_METHODW(&namespace_name, &router, "getnamespacename");
	PHALCON_CALL_METHODW(&task_name, &router, "gettaskname");
	PHALCON_CALL_METHODW(&action_name, &router, "getactionname");
	PHALCON_CALL_METHODW(&params, &router, "getparams");

	ZVAL_STRING(&service, ISV(dispatcher));

	PHALCON_CALL_METHODW(&dispatcher, &dependency_injector, "getshared", &service);
	PHALCON_VERIFY_INTERFACEW(&dispatcher, phalcon_dispatcherinterface_ce);

	PHALCON_CALL_METHODW(NULL, &dispatcher, "setnamespacename", &namespace_name);
	PHALCON_CALL_METHODW(NULL, &dispatcher, "settaskname", &task_name);
	PHALCON_CALL_METHODW(NULL, &dispatcher, "setactionname", &action_name);
	PHALCON_CALL_METHODW(NULL, &dispatcher, "setparams", &params);
	if (Z_TYPE(events_manager) == IS_OBJECT) {
		ZVAL_STRING(&event_name, "console:beforeHandleTask");

		PHALCON_CALL_METHODW(&status, &events_manager, "fire", &event_name, getThis(), &dispatcher);
		if (PHALCON_IS_FALSE(&status)) {
			RETURN_FALSE;
		}
	}

	PHALCON_CALL_METHODW(&status, &dispatcher, "dispatch");

	if (Z_TYPE(events_manager) == IS_OBJECT) {
		ZVAL_STRING(&event_name, "console:afterHandleTask");
		PHALCON_CALL_METHODW(NULL, &events_manager, "fire", &event_name, getThis(), &status);
	}

	RETURN_CTORW(&status);
}
Exemple #4
0
/**
 * Commits the active transaction in the connection
 */
PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit) {

	int transactionLevel, ZEPHIR_LAST_CALL_STATUS;
	zval *nesting_param = NULL, *pdo, *eventsManager = NULL, *savepointName = NULL, *_0, *_1, *_2 = NULL, *_5 = NULL;
	zend_bool nesting, _3, _4;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 0, 1, &nesting_param);

	if (!nesting_param) {
		nesting = 1;
	} else {
		nesting = zephir_get_boolval(nesting_param);
	}


	ZEPHIR_OBS_VAR(pdo);
	zephir_read_property_this(&pdo, this_ptr, SL("_pdo"), PH_NOISY_CC);
	if (Z_TYPE_P(pdo) != IS_OBJECT) {
		RETURN_MM_BOOL(0);
	}
	ZEPHIR_OBS_VAR(_0);
	zephir_read_property_this(&_0, this_ptr, SL("_transactionLevel"), PH_NOISY_CC);
	transactionLevel = zephir_get_intval(_0);
	if (!(transactionLevel)) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_db_exception_ce, "There is no active transaction", "phalcon/db/adapter/pdo.zep", 626);
		return;
	}
	if (transactionLevel == 1) {
		_1 = zephir_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC);
		ZEPHIR_CPY_WRT(eventsManager, _1);
		if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
			ZEPHIR_INIT_VAR(_2);
			ZVAL_STRING(_2, "db:commitTransaction", ZEPHIR_TEMP_PARAM_COPY);
			ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", NULL, _2, this_ptr);
			zephir_check_temp_parameter(_2);
			zephir_check_call_status();
		}
		RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC));
		ZEPHIR_RETURN_CALL_METHOD(pdo, "commit", NULL);
		zephir_check_call_status();
		RETURN_MM();
	} else {
		_3 = (transactionLevel) ? 1 : 0;
		if (_3) {
			_3 = nesting;
		}
		_4 = _3;
		if (_4) {
			ZEPHIR_CALL_METHOD(&_5, this_ptr, "isnestedtransactionswithsavepoints", NULL);
			zephir_check_call_status();
			_4 = zephir_is_true(_5);
		}
		if (_4) {
			_1 = zephir_fetch_nproperty_this(this_ptr, SL("_eventsManager"), PH_NOISY_CC);
			ZEPHIR_CPY_WRT(eventsManager, _1);
			ZEPHIR_CALL_METHOD(&savepointName, this_ptr, "getnestedtransactionsavepointname", NULL);
			zephir_check_call_status();
			if (Z_TYPE_P(eventsManager) == IS_OBJECT) {
				ZEPHIR_INIT_NVAR(_2);
				ZVAL_STRING(_2, "db:releaseSavepoint", ZEPHIR_TEMP_PARAM_COPY);
				ZEPHIR_CALL_METHOD(NULL, eventsManager, "fire", NULL, _2, this_ptr, savepointName);
				zephir_check_temp_parameter(_2);
				zephir_check_call_status();
			}
			RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC));
			ZEPHIR_RETURN_CALL_METHOD(this_ptr, "releasesavepoint", NULL, savepointName);
			zephir_check_call_status();
			RETURN_MM();
		}
	}
	if (transactionLevel > 0) {
		RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC));
	}
	RETURN_MM_BOOL(0);

}
Exemple #5
0
/**
 * Moves the internal iteration pointer to the next position
 *
 */
PHP_METHOD(Phalcon_Validation_Message_Group, next) {


	RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("_position") TSRMLS_CC));

}
Exemple #6
0
/**
 * Resolves the service
 *
 * @param array $parameters
 * @param Phalcon\DIInterface $dependencyInjector
 * @return object
 */
PHP_METHOD(Phalcon_DI_Service, resolve){

	zval *parameters = NULL, *dependency_injector = NULL, name = {}, shared = {}, shared_instance = {}, definition = {}, builder = {};
	int found = 0, ishared = 0;

	phalcon_fetch_params(0, 0, 2, &parameters, &dependency_injector);

	if (!parameters) {
		parameters = &PHALCON_GLOBAL(z_null);
	}

	if (!dependency_injector) {
		dependency_injector = &PHALCON_GLOBAL(z_null);
	}

	phalcon_return_property(&shared, getThis(), SL("_shared"));
	phalcon_return_property(&shared_instance, getThis(), SL("_sharedInstance"));

	ishared = zend_is_true(&shared);

	/* Check if the service is shared */
	if (ishared && Z_TYPE(shared_instance) != IS_NULL) {
		RETURN_CTORW(&shared_instance);
	}

	phalcon_return_property(&definition, getThis(), SL("_definition"));

	if (Z_TYPE(definition) == IS_STRING) {
		/* String definitions can be class names without implicit parameters */
		if (phalcon_class_exists(&definition, 1) != NULL) {
			found = 1;
			if (Z_TYPE_P(parameters) == IS_ARRAY) {
				RETURN_ON_FAILURE(phalcon_create_instance_params(return_value, &definition, parameters));
			} else {
				RETURN_ON_FAILURE(phalcon_create_instance(return_value, &definition));
			}
		}
	} else if (likely(Z_TYPE(definition) == IS_OBJECT)) {
		/* Object definitions can be a Closure or an already resolved instance */
		found = 1;
		if (instanceof_function_ex(Z_OBJCE(definition), zend_ce_closure, 0)) {
			if (likely(Z_TYPE_P(dependency_injector) == IS_OBJECT)) {
				PHALCON_CALL_CE_STATICW(&definition, zend_ce_closure, "bind", &definition, dependency_injector);
			}
			if (Z_TYPE_P(parameters) == IS_ARRAY) {
				PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &definition, parameters);
			} else {
				PHALCON_CALL_USER_FUNCW(return_value, &definition);
			}
		} else {
			PHALCON_CPY_WRT(return_value, &definition);
		}
	} else if (Z_TYPE(definition) == IS_ARRAY) {
		found = 1;
		/* Array definitions require a 'className' parameter */
		object_init_ex(&builder, phalcon_di_service_builder_ce);

		PHALCON_CALL_METHODW(return_value, &builder, "build", dependency_injector, &definition, parameters);
	}

	if (!EG(exception)) {
		if (found) {
			if (ishared) {
				phalcon_update_property_zval(getThis(), SL("_sharedInstance"), return_value);
			}
			/* Update the shared instance if the service is shared */
			phalcon_update_property_bool(getThis(), SL("_resolved"), 1);
		} else {
			phalcon_return_property(&name, getThis(), SL("_name"));
			PHALCON_THROW_EXCEPTION_FORMATW(phalcon_di_exception_ce, "Service '%s' cannot be resolved", Z_STRVAL(name));
		}
	}
}
Exemple #7
0
/**
 * Create/Returns a new transaction or an existing one
 */
PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getOrCreateTransaction) {

	HashTable *_2$$5;
	HashPosition _1$$5;
	int ZEPHIR_LAST_CALL_STATUS;
	zval *autoBegin_param = NULL, *dependencyInjector = NULL, *transaction = NULL, *transactions = NULL, *_0, *_5, *_6, **_3$$5, *_4$$7 = NULL;
	zend_bool autoBegin;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 0, 1, &autoBegin_param);

	if (!autoBegin_param) {
		autoBegin = 1;
	} else {
		autoBegin = zephir_get_boolval(autoBegin_param);
	}


	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
	ZEPHIR_CPY_WRT(dependencyInjector, _0);
	if (Z_TYPE_P(dependencyInjector) != IS_OBJECT) {
		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM", "phalcon/mvc/model/transaction/manager.zep", 189);
		return;
	}
	_0 = zephir_fetch_nproperty_this(this_ptr, SL("_number"), PH_NOISY_CC);
	if (zephir_is_true(_0)) {
		ZEPHIR_OBS_VAR(transactions);
		zephir_read_property_this(&transactions, this_ptr, SL("_transactions"), PH_NOISY_CC);
		if (Z_TYPE_P(transactions) == IS_ARRAY) {
			zephir_is_iterable(transactions, &_2$$5, &_1$$5, 0, 1, "phalcon/mvc/model/transaction/manager.zep", 201);
			for (
			  ; zephir_hash_get_current_data_ex(_2$$5, (void**) &_3$$5, &_1$$5) == SUCCESS
			  ; zephir_hash_move_backwards_ex(_2$$5, &_1$$5)
			) {
				ZEPHIR_GET_HVALUE(transaction, _3$$5);
				if (Z_TYPE_P(transaction) == IS_OBJECT) {
					ZEPHIR_INIT_NVAR(_4$$7);
					ZVAL_BOOL(_4$$7, 0);
					ZEPHIR_CALL_METHOD(NULL, transaction, "setisnewtransaction", NULL, 0, _4$$7);
					zephir_check_call_status();
					RETURN_CCTOR(transaction);
				}
			}
		}
	}
	ZEPHIR_INIT_NVAR(transaction);
	object_init_ex(transaction, phalcon_mvc_model_transaction_ce);
	_5 = zephir_fetch_nproperty_this(this_ptr, SL("_service"), PH_NOISY_CC);
	ZEPHIR_INIT_VAR(_6);
	if (autoBegin) {
		ZVAL_BOOL(_6, 1);
	} else {
		ZVAL_BOOL(_6, 0);
	}
	ZEPHIR_CALL_METHOD(NULL, transaction, "__construct", NULL, 377, dependencyInjector, _6, _5);
	zephir_check_call_status();
	ZEPHIR_CALL_METHOD(NULL, transaction, "settransactionmanager", NULL, 378, this_ptr);
	zephir_check_call_status();
	zephir_update_property_array_append(this_ptr, SL("_transactions"), transaction TSRMLS_CC);
	RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("_number") TSRMLS_CC));
	RETURN_CCTOR(transaction);

}