File: ext/phady/core/namespacehandler.zep.c

Recommend this page to a friend!
  Classes of Alien Fernandez  >  Phady Framework  >  ext/phady/core/namespacehandler.zep.c  >  Download  
File: ext/phady/core/namespacehandler.zep.c
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Phady Framework
Web application MVC framework based on Phalcon
Author: By
Last change:
Date: 4 years ago
Size: 9,194 bytes
 

Contents

Class file image Download
#ifdef HAVE_CONFIG_H
#include "../../ext_config.h"
#endif

#include <php.h>
#include "../../php_ext.h"
#include "../../ext.h"

#include <Zend/zend_operators.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>

#include "kernel/main.h"
#include "kernel/object.h"
#include "kernel/memory.h"
#include "kernel/array.h"
#include "ext/spl/spl_exceptions.h"
#include "kernel/exception.h"
#include "kernel/operators.h"
#include "kernel/hash.h"
#include "kernel/string.h"
#include "kernel/concat.h"
#include "kernel/fcall.h"


/**
  * @class Phady\Core\NamespaceHandler -  Namespaces handlers for app
  *
  * @author  Alien Fernández Fuentes <alienfernandez85@gmail.com>
  * @package Core
  * @copyright (c) 2015
  * @version 1.0.0
  */
ZEPHIR_INIT_CLASS(Phady_Core_NamespaceHandler) {

	ZEPHIR_REGISTER_CLASS(Phady\\Core, NamespaceHandler, phady, core_namespacehandler, phady_core_namespacehandler_method_entry, 0);

	/**
	 * @var string scope - Scope of execution [mvc | cli]
	 */
	zend_declare_property_null(phady_core_namespacehandler_ce, SL("scope"), ZEND_ACC_PRIVATE TSRMLS_CC);

	/**
	 * @var string rootDir - Root app
	 */
	zend_declare_property_null(phady_core_namespacehandler_ce, SL("rootDir"), ZEND_ACC_PRIVATE TSRMLS_CC);

	/**
	 * @var array Array modules default namespace
	 */
	zend_declare_property_null(phady_core_namespacehandler_ce, SL("nsModuleDefault"), ZEND_ACC_PRIVATE TSRMLS_CC);

	/**
	 * @var array Array modules default namespace
	 */
	zend_declare_property_null(phady_core_namespacehandler_ce, SL("nsModulePathDefault"), ZEND_ACC_PUBLIC TSRMLS_CC);

	/**
	 * @var array Array of namespace generated by the app
	 */
	zend_declare_property_null(phady_core_namespacehandler_ce, SL("namespaces"), ZEND_ACC_PRIVATE TSRMLS_CC);

	/**
	 * @var array Array of modules of the app
	 */
	zend_declare_property_null(phady_core_namespacehandler_ce, SL("modules"), ZEND_ACC_PRIVATE TSRMLS_CC);

	phady_core_namespacehandler_ce->create_object = zephir_init_properties_Phady_Core_NamespaceHandler;
	/**
	 * Namespace prefix of the app
	 */
	zend_declare_class_constant_string(phady_core_namespacehandler_ce, SL("NS_APP_PREFIX"), "App" TSRMLS_CC);

	return SUCCESS;

}

/**
 * @param string scope - Scope of execution [mvc | cli]
 * @param string rootDir - Root of the app
 * @param array modules Modules app
 */
PHP_METHOD(Phady_Core_NamespaceHandler, __construct) {

	zval *modules = NULL, *_0, *_2;
	zval *scope_param = NULL, *rootDir_param = NULL, *modules_param = NULL, *_1 = NULL;
	zval *scope = NULL, *rootDir = NULL;

	ZEPHIR_MM_GROW();
	zephir_fetch_params(1, 2, 1, &scope_param, &rootDir_param, &modules_param);

	if (unlikely(Z_TYPE_P(scope_param) != IS_STRING && Z_TYPE_P(scope_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'scope' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	if (likely(Z_TYPE_P(scope_param) == IS_STRING)) {
		zephir_get_strval(scope, scope_param);
	} else {
		ZEPHIR_INIT_VAR(scope);
		ZVAL_EMPTY_STRING(scope);
	}
	if (unlikely(Z_TYPE_P(rootDir_param) != IS_STRING && Z_TYPE_P(rootDir_param) != IS_NULL)) {
		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'rootDir' must be a string") TSRMLS_CC);
		RETURN_MM_NULL();
	}

	if (likely(Z_TYPE_P(rootDir_param) == IS_STRING)) {
		zephir_get_strval(rootDir, rootDir_param);
	} else {
		ZEPHIR_INIT_VAR(rootDir);
		ZVAL_EMPTY_STRING(rootDir);
	}
	if (!modules_param) {
		ZEPHIR_INIT_VAR(modules);
		array_init(modules);
	} else {
		zephir_get_arrval(modules, modules_param);
	}


	zephir_update_property_this(this_ptr, SL("scope"), scope TSRMLS_CC);
	zephir_update_property_this(this_ptr, SL("rootDir"), rootDir TSRMLS_CC);
	zephir_update_property_this(this_ptr, SL("modules"), modules TSRMLS_CC);
	ZEPHIR_INIT_VAR(_0);
	zephir_create_array(_0, 7, 0 TSRMLS_CC);
	ZEPHIR_INIT_VAR(_1);
	ZVAL_STRING(_1, "", 1);
	zephir_array_fast_append(_0, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "Controllers", 1);
	zephir_array_fast_append(_0, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "Models\\Entities", 1);
	zephir_array_fast_append(_0, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "Models\\Business", 1);
	zephir_array_fast_append(_0, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "Models\\Repositories\\Repository", 1);
	zephir_array_fast_append(_0, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "Services", 1);
	zephir_array_fast_append(_0, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "Models\\Repositories", 1);
	zephir_array_fast_append(_0, _1);
	zephir_update_property_this(this_ptr, SL("nsModuleDefault"), _0 TSRMLS_CC);
	ZEPHIR_INIT_VAR(_2);
	zephir_create_array(_2, 7, 0 TSRMLS_CC);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "", 1);
	zephir_array_fast_append(_2, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "/controllers", 1);
	zephir_array_fast_append(_2, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "/models/entities", 1);
	zephir_array_fast_append(_2, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "/models/business", 1);
	zephir_array_fast_append(_2, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "/models/repositories", 1);
	zephir_array_fast_append(_2, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "/services", 1);
	zephir_array_fast_append(_2, _1);
	ZEPHIR_INIT_NVAR(_1);
	ZVAL_STRING(_1, "/models/repositories", 1);
	zephir_array_fast_append(_2, _1);
	zephir_update_property_this(this_ptr, SL("nsModulePathDefault"), _2 TSRMLS_CC);
	ZEPHIR_MM_RESTORE();

}

/**
 * @function setModulesNamespace - Namespace modify the modules of the app
 */
PHP_METHOD(Phady_Core_NamespaceHandler, setModulesNamespace) {

	zend_bool _8;
	HashTable *_1, *_5;
	HashPosition _0, _4;
	zval *modules_param = NULL, *modKey = NULL, *key = NULL, *module = NULL, *msModule = NULL, *moduleUcFirst = NULL, *pathModule = NULL, **_2, *_3, **_6, *_7, *_9, *_10, *_11, *_12, *_13, *_14 = NULL;
	zval *modules = NULL;

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

	modules = modules_param;



	zephir_is_iterable(modules, &_1, &_0, 0, 0, "phady/core/namespacehandler.zep", 101);
	for (
	  ; zephir_hash_get_current_data_ex(_1, (void**) &_2, &_0) == SUCCESS
	  ; zephir_hash_move_forward_ex(_1, &_0)
	) {
		ZEPHIR_GET_HVALUE(module, _2);
		ZEPHIR_INIT_NVAR(modKey);
		zephir_array_keys(modKey, module TSRMLS_CC);
		_3 = zephir_fetch_nproperty_this(this_ptr, SL("nsModuleDefault"), PH_NOISY_CC);
		zephir_is_iterable(_3, &_5, &_4, 0, 0, "phady/core/namespacehandler.zep", 100);
		for (
		  ; zephir_hash_get_current_data_ex(_5, (void**) &_6, &_4) == SUCCESS
		  ; zephir_hash_move_forward_ex(_5, &_4)
		) {
			ZEPHIR_GET_HMKEY(key, _5, _4);
			ZEPHIR_GET_HVALUE(msModule, _6);
			_7 = zephir_fetch_nproperty_this(this_ptr, SL("scope"), PH_NOISY_CC);
			_8 = (ZEPHIR_IS_STRING(_7, "mvc"));
			if (_8) {
				_8 = (ZEPHIR_IS_LONG(key, 0));
			}
			if (_8) {
				continue;
			}
			zephir_array_fetch_long(&_9, modKey, 0, PH_NOISY | PH_READONLY, "phady/core/namespacehandler.zep", 92 TSRMLS_CC);
			ZEPHIR_INIT_NVAR(moduleUcFirst);
			zephir_ucfirst(moduleUcFirst, _9);
			_10 = zephir_fetch_nproperty_this(this_ptr, SL("rootDir"), PH_NOISY_CC);
			zephir_array_fetch_long(&_11, modKey, 0, PH_NOISY | PH_READONLY, "phady/core/namespacehandler.zep", 93 TSRMLS_CC);
			_12 = zephir_fetch_nproperty_this(this_ptr, SL("nsModulePathDefault"), PH_NOISY_CC);
			zephir_array_fetch(&_13, _12, key, PH_NOISY | PH_READONLY, "phady/core/namespacehandler.zep", 93 TSRMLS_CC);
			ZEPHIR_INIT_NVAR(pathModule);
			ZEPHIR_CONCAT_VSVV(pathModule, _10, "/../src/", _11, _13);
			ZEPHIR_INIT_LNVAR(_14);
			ZEPHIR_CONCAT_SSVSV(_14, "App", "\\", moduleUcFirst, "\\", msModule);
			zephir_update_property_array(this_ptr, SL("namespaces"), _14, pathModule TSRMLS_CC);
		}
	}
	ZEPHIR_MM_RESTORE();

}

/**
 * @function getAllNamespaceApp - Get all the app ns
 */
PHP_METHOD(Phady_Core_NamespaceHandler, getAllNamespaceApp) {

	int ZEPHIR_LAST_CALL_STATUS;
	zval *_0;

	ZEPHIR_MM_GROW();

	_0 = zephir_fetch_nproperty_this(this_ptr, SL("modules"), PH_NOISY_CC);
	ZEPHIR_CALL_METHOD(NULL, this_ptr, "setmodulesnamespace", NULL, 0, _0);
	zephir_check_call_status();
	RETURN_MM_MEMBER(this_ptr, "namespaces");

}

static zend_object_value zephir_init_properties_Phady_Core_NamespaceHandler(zend_class_entry *class_type TSRMLS_DC) {

		zval *_0, *_1 = NULL, *_2, *_3;

		ZEPHIR_MM_GROW();
	
	{
		zval *this_ptr = NULL;
		ZEPHIR_CREATE_OBJECT(this_ptr, class_type);
		_0 = zephir_fetch_nproperty_this(this_ptr, SL("modules"), PH_NOISY_CC);
		if (Z_TYPE_P(_0) == IS_NULL) {
			ZEPHIR_INIT_VAR(_1);
			array_init(_1);
			zephir_update_property_this(this_ptr, SL("modules"), _1 TSRMLS_CC);
		}
		_2 = zephir_fetch_nproperty_this(this_ptr, SL("namespaces"), PH_NOISY_CC);
		if (Z_TYPE_P(_2) == IS_NULL) {
			ZEPHIR_INIT_NVAR(_1);
			array_init(_1);
			zephir_update_property_this(this_ptr, SL("namespaces"), _1 TSRMLS_CC);
		}
		_3 = zephir_fetch_nproperty_this(this_ptr, SL("nsModulePathDefault"), PH_NOISY_CC);
		if (Z_TYPE_P(_3) == IS_NULL) {
			ZEPHIR_INIT_NVAR(_1);
			array_init(_1);
			zephir_update_property_this(this_ptr, SL("nsModulePathDefault"), _1 TSRMLS_CC);
		}
		ZEPHIR_MM_RESTORE();
		return Z_OBJVAL_P(this_ptr);
	}

}


For more information send a message to info at phpclasses dot org.