public function addCommandsFromClass($className, $passThrough = null) { $roboTasks = new $className(); $commandNames = array_filter(get_class_methods($className), function ($m) { return !in_array($m, ['__construct']); }); foreach ($commandNames as $commandName) { $command = $this->createCommand(new TaskInfo($className, $commandName)); $command->setCode(function (InputInterface $input) use($roboTasks, $commandName, $passThrough) { // get passthru args $args = $input->getArguments(); array_shift($args); if ($passThrough) { $args[key(array_slice($args, -1, 1, TRUE))] = $passThrough; } $args[] = $input->getOptions(); $res = call_user_func_array([$roboTasks, $commandName], $args); if (is_int($res)) { exit($res); } if (is_bool($res)) { exit($res ? 0 : 1); } if ($res instanceof Result) { exit($res->getExitCode()); } }); $this->add($command); } }
/** * Add all the routes in the router in parameter * @param $router Router */ public function generateRoute(Router $router) { foreach ($this->classes as $class) { $classMethods = get_class_methods($this->namespace . $class . 'Controller'); $rc = new \ReflectionClass($this->namespace . $class . 'Controller'); $parent = $rc->getParentClass(); $parent = get_class_methods($parent->name); $className = $this->namespace . $class . 'Controller'; foreach ($classMethods as $methodName) { if (in_array($methodName, $parent) || $methodName == 'index') { continue; } else { foreach (Router::getSupportedHttpMethods() as $httpMethod) { if (strstr($methodName, $httpMethod)) { continue 2; } if (in_array($methodName . $httpMethod, $classMethods)) { $router->add('/' . strtolower($class) . '/' . $methodName, new $className(), $methodName . $httpMethod, $httpMethod); unset($classMethods[$methodName . $httpMethod]); } } $router->add('/' . strtolower($class) . '/' . $methodName, new $className(), $methodName); } } $router->add('/' . strtolower($class), new $className(), 'index'); } }
/** * Get Route including 404 check * * @see core/CodeIgniter.php * * @return array [class, method, pararms] */ public function getRoute() { $RTR =& load_class('Router', 'core'); $URI =& load_class('URI', 'core'); $e404 = FALSE; $class = ucfirst($RTR->class); $method = $RTR->method; if (empty($class) or !file_exists(APPPATH . 'controllers/' . $RTR->directory . $class . '.php')) { $e404 = TRUE; } else { require_once APPPATH . 'controllers/' . $RTR->directory . $class . '.php'; if (!class_exists($class, FALSE) or $method[0] === '_' or method_exists('CI_Controller', $method)) { $e404 = TRUE; } elseif (method_exists($class, '_remap')) { $params = array($method, array_slice($URI->rsegments, 2)); $method = '_remap'; } elseif (!in_array(strtolower($method), array_map('strtolower', get_class_methods($class)), TRUE)) { $e404 = TRUE; } } if ($e404) { // If 404, CodeIgniter instance is not created yet. So create it here. // Because we need CI->output->_status $CI =& get_instance(); if ($CI instanceof CIPHPUnitTestNullCodeIgniter) { CIPHPUnitTest::createCodeIgniterInstance(); } show_404($RTR->directory . $class . '/' . $method . ' is not found'); } if ($method !== '_remap') { $params = array_slice($URI->rsegments, 2); } return [$class, $method, $params]; }
/** * Dispatch the requested action * * @param string $action Method name of action * @return void */ public function dispatch($action) { $action = str_replace("Action", "", $action); // Notify helpers of action preDispatch state $this->_helper->notifyPreDispatch(); $this->preDispatch(); if ($this->getRequest()->isDispatched()) { if (null === $this->_classMethods) { $this->_classMethods = get_class_methods($this); } // preDispatch() didn't change the action, so we can continue if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) { if ($this->getInvokeArg('useCaseSensitiveActions')) { trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"'); } $this->{$action}(); $this->view->setVars($this->fields); } else { $this->__call($action, array()); $this->view->setVars($this->fields); } $this->postDispatch(); } // whats actually important here is that this action controller is // shutting down, regardless of dispatching; notify the helpers of this // state $this->_helper->notifyPostDispatch(); }
/** * Constructor. * * @param \TokenReflection\IReflection $reflection Inspected reflection * @param \ApiGen\Generator $generator ApiGen generator */ public function __construct(IReflection $reflection = null, Generator $generator = null) { $this->reflectionType = get_class($this); if (!isset(self::$reflectionMethods[$this->reflectionType])) { self::$reflectionMethods[$this->reflectionType] = array_flip(get_class_methods($this)); } }
/** * Update Data Object with the data from array * * @param mixed $dataObject * @param array $data * @param string $interfaceName * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _setDataValues($dataObject, array $data, $interfaceName) { $dataObjectMethods = get_class_methods(get_class($dataObject)); foreach ($data as $key => $value) { /* First, verify is there any setter for the key on the Service Data Object */ $camelCaseKey = \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key); $possibleMethods = ['set' . $camelCaseKey, 'setIs' . $camelCaseKey]; if ($key === CustomAttributesDataInterface::CUSTOM_ATTRIBUTES && $dataObject instanceof ExtensibleDataInterface && is_array($data[$key]) && !empty($data[$key])) { foreach ($data[$key] as $customAttribute) { $dataObject->setCustomAttribute($customAttribute[AttributeInterface::ATTRIBUTE_CODE], $customAttribute[AttributeInterface::VALUE]); } } elseif ($methodNames = array_intersect($possibleMethods, $dataObjectMethods)) { $methodName = array_values($methodNames)[0]; if (!is_array($value)) { if ($methodName === 'setExtensionAttributes' && $value === null) { // Cannot pass a null value to a method with a typed parameter } else { $dataObject->{$methodName}($value); } } else { $getterMethodName = 'get' . $camelCaseKey; $this->setComplexValue($dataObject, $getterMethodName, $methodName, $value, $interfaceName); } } elseif ($dataObject instanceof CustomAttributesDataInterface) { $dataObject->setCustomAttribute($key, $value); } } return $this; }
/** @test */ public function methods() { $needed_methods = array('isValid', 'getRealValue'); $this->assertThat(array_unique(get_class_methods(__NAMESPACE__ . '\\Binding')), new \PHPUnit_Framework_Constraint_Callback(function ($class_methods) use($needed_methods) { return $needed_methods === array_intersect($needed_methods, $class_methods); })); }
/** * ‘ормирует описание переменной, в соответствии с переданным шаблоном оформлени¤ * @param mixed $var переменна¤ * @param string $name заголовок описани¤ * @param array $tmpl шаблон оформлени¤ * @return string */ function _get($var, $name = 'INFO', $tmpl) { $type = gettype($var); switch ($type) { default: $out = $tmpl['value'] . $var . $tmpl['/value']; break; case 'boolean': $out = $tmpl['value'] . ($var ? 'true' : 'false') . $tmpl['/value']; break; case 'string': $out = $tmpl['size'] . strlen($var) . $tmpl['/size'] . $tmpl['value'] . htmlspecialchars($var) . $tmpl['/value']; break; case 'array': $values = Varier::_getSection($var, $tmpl, '+'); $out = $tmpl['size'] . count($var) . $tmpl['/size'] . $values; break; case 'object': $class = get_class($var); $properties = Varier::_getSection(get_object_vars($var), $tmpl, 'properties'); $methods = Varier::_getSection(get_class_methods($class), $tmpl, 'methods'); $out = $tmpl['class_name'] . $class . $tmpl['/class_name'] . $tmpl['properties'] . $properties . $tmpl['/properties'] . $tmpl['methods'] . $methods . $tmpl['/methods']; break; } return $tmpl['element'] . $tmpl['name'] . $name . $tmpl['/name'] . $tmpl['type'] . $type . $tmpl['/type'] . $out . $tmpl['/element']; }
protected function generateGuis($guiController) { $activeTab = $this->getParam("activeTab"); $needTabs = $this->getParam("needTabs"); $gui = new $guiController($this->nodeData); $nodeId = $this->nodeData['tree_id']; $classMethods = get_class_methods($gui); $tabsHeader = '<ul class="tabs">'; $addAccess = K_access::accessTree($nodeId, array('add', 'addremove'), true); $i = 0; foreach ($classMethods as $methodName) { if (strpos($methodName, 'GUI') !== false && $gui->{$methodName}() !== false) { $tabName = substr($methodName, 0, -3); // var_dump( $this->tabAction($tabName)); // var_dump( K_access::accessTree($nodeId,$this->tabAction($tabName))); if ($addAccess || K_access::accessTree($nodeId, $this->tabAction($tabName))) { $i++; if (empty($needTabs) || in_array($tabName, $needTabs)) { echo '<div class="gui-block tab_content ' . $tabName . '" id="tab' . ($i + 1) . '" >' . $gui->{$methodName}() . '</div>'; $tabsHeader .= '<li ' . ($tabName == $activeTab ? 'class="activeTab"' : '') . '><a href="#tab' . ($i + 1) . '" id="tab-' . $tabName . '", >' . (isset($gui->tabs[substr($methodName, 0, -3)]) ? $gui->tabs[substr($methodName, 0, -3)] : '---') . '</a></li>'; } } if ($i == 0) { $this->putAjax("<div style='margin:15px'>Для этого пункта доступен только просмотр"); } } } $tabsHeader .= '</ul>'; echo $tabsHeader; }
static function tpl($group = 'home') { //基本配置 $tpl = self::get_instance(); self::process_view_config($group, $tpl); //网站元信息 $tpl->assign(config(null, 'site')); //设置目录常量 $tpl->assign('url', U_R_L); $dir_data = system::set_url_dir(true); $tpl->assign('dir', $dir_data); //注册全局组件 foreach (array('function', 'modifier') as $type) { $class = 'p_' . $type; include PATH_ROOT . 'plugin/' . $class . '.php'; if (class_exists($class)) { $method_data = get_class_methods($class); foreach ($method_data as $method) { $tpl->registerPlugin($type, $method, array($class, $method)); } } } //处理分组业务 if (defined('GROUP_NAME')) { self::process_group($tpl); } return $tpl; }
public function run() { if (fnmatch('*cli*', php_sapi_name())) { $dir = Config::get('dir.schedules', APPLICATION_PATH . DS . 'schedules'); if (is_dir($dir)) { Timer::start(); Cli::show("Start of execution", 'COMMENT'); $files = glob($dir . DS . '*.php'); foreach ($files as $file) { require_once $file; $object = str_replace('.php', '', Arrays::last(explode(DS, $file))); $class = 'Thin\\' . ucfirst(Inflector::camelize($object . '_schedule')); $instance = lib('app')->make($class); $methods = get_class_methods($instance); Cli::show("Start schedule '{$object}'", 'COMMENT'); foreach ($methods as $method) { $when = $this->getWhen($instance, $method); $isDue = $this->isDue($object, $method, $when); if (true === $isDue) { Cli::show("Execution of {$object}->{$method}", 'INFO'); $instance->{$method}(); } else { Cli::show("No need to execute {$object}->{$method}", 'QUESTION'); } } } Cli::show("Time of execution [" . Timer::get() . " s.]", 'SUCCESS'); Cli::show("end of execution", 'COMMENT'); } } }
/** * Finds the first child that has data matching specific values * * @param array $findSets * @param boolean $caseSensitive OPTIONAL * * @return AbstractDataEntity * * @throws OutOfBoundsException if no matching child is found */ public function findByArray(array $findSets, $caseSensitive = false) { $foundChild = null; $methods = get_class_methods($this->getChildClass()); foreach ($this as $child) { $childMatches = true; foreach ($findSets as $key => $value) { $getter = $this->getFunctionName($key); if (!in_array($getter, $methods)) { $getter = $this->getFunctionName('get_' . $key); } $childValue = $child->{$getter}(); if (!$caseSensitive) { $value = strtolower($value); $childValue = strtolower($childValue); } if ($childValue != $value) { $childMatches = false; break; } } if ($childMatches) { $foundChild = $child; break; } } if ($foundChild === null) { throw new OutOfBoundsException('No matching child found!'); } return $foundChild; }
/** * 架构函数 * @access public */ public function __construct() { //控制器初始化 if (method_exists($this, '_initialize')) { $this->_initialize(); } //导入类库 Vendor('Hprose.HproseHttpServer'); //实例化HproseHttpServer $server = new \HproseHttpServer(); if ($this->allowMethodList) { $methods = $this->allowMethodList; } else { $methods = get_class_methods($this); $methods = array_diff($methods, array('__construct', '__call', '_initialize')); } $server->addMethods($methods, $this); if (APP_DEBUG || $this->debug) { $server->setDebugEnabled(true); } // Hprose设置 $server->setCrossDomainEnabled($this->crossDomain); $server->setP3PEnabled($this->P3P); $server->setGetEnabled($this->get); // 启动server $server->start(); }
/** * Runs the tests * * @return array $results * Returns array of results. A result consists of */ function run() { $results = array(); $this->saveState(); $class = get_class($this); $class_methods = get_class_methods($class); shuffle($class_methods); // execute tests in random order! foreach ($class_methods as $cm) { if (substr($cm, -4) == 'Test') { // Run the test if (is_callable(array($this, 'setUp'))) { $this->setUp(); } //echo "running $class::$cm...\n"; try { $ret = call_user_func(array($this, $cm)); // $ret is not used for now. $results[$class][$cm] = array(self::TEST_SUCCEEDED, 'succeeded'); } catch (Pie_Exception_TestCase $e) { // one of the predefined testcase outcomes occurred $results[$class][$cm] = array($e->getCode(), $e->getMessage()); } catch (Exception $e) { $results[$class][$cm] = array(self::TEST_EXCEPTION, 'exception', $e); } if (is_callable(array($this, 'tearDown'))) { $this->tearDown(); } $this->restoreState(); } } $this->hasToRun = false; return $results; }
private function format_controller_methods($path, $file) { $this->load->helper("url"); $controller = array(); // only show php files if (($extension = substr($file, strrpos($file, ".") + 1)) == "php") { // include the class include_once $path . "/" . $file; $parts = explode(".", $file); $class_lower = $parts["0"]; $class = ucfirst($class_lower); // check if a class actually exists if (class_exists($class) and get_parent_class($class) == "MY_Controller") { // get a list of all methods $controller["name"] = $class; $controller["path"] = base_url() . $class_lower; $controller["methods"] = array(); // get a list of all public methods foreach (get_class_methods($class) as $method) { $reflect = new ReflectionMethod($class, $method); if ($reflect->isPublic()) { // ignore some methods $object = new $class(); if (!in_array($method, $object->internal_methods)) { $method_array = array(); $method_array["name"] = $method; $method_array["path"] = base_url() . $class_lower . "/" . $method; $controller["methods"][] = $method_array; } } } } } return $controller; }
/** * Input construct. * * @param array $name * @param mixed $value * @param array|null $inputConfig * @throws InvalidArgumentException */ public function __construct($name, $value, $inputConfig) { if (!is_array($value)) { if (is_object($value) && in_array("__toString", get_class_methods($value))) { $value = strval($value->__toString()); } else { $value = strval($value); } $value = trim($value); if ($value !== '') { $value = str_replace('"', '"', $value); $value = json_decode($value, true); // strict mode // if (json_last_error() != JSON_ERROR_NONE || !is_array($value)) { // throw new InvalidArgumentException('Invalid string to convert to array'); // } } } if (is_array($value)) { $value = array_merge($this->defaultOptions, $value); } else { $value = $this->defaultOptions; } parent::__construct($name, $value, $inputConfig); }
/** @test */ public function methods() { $needed_methods = array('toArray'); $this->assertThat(array_unique(get_class_methods(__NAMESPACE__ . '\\DbIterator')), new \PHPUnit_Framework_Constraint_Callback(function ($class_methods) use($needed_methods) { return $needed_methods === array_intersect($needed_methods, $class_methods); })); }
/** * Sets up the admin environment and routes the request to the correct * action_xxx method, while making sure the user is logged in. * * @return void */ public function __construct($action = NULL) { // Start a session session_start(); // Set the correct default Content-Type header if (ThumbsUp::is_ajax()) { header('Content-Type: application/json; charset=utf-8'); } else { header('Content-Type: text/html; charset=utf-8'); } // Force the user to login if (!self::logged_in()) { return $this->action_login(); } // If no action is specified, show the dashboard by default if ($action === NULL) { return $this->action_dashboard(); } // Look for a corresponding action_method if (in_array($action = 'action_' . $action, get_class_methods($this))) { return $this->{$action}(); } // Show an error for invalid actions header('HTTP/1.1 404 Not Found'); exit('Page not found'); }
private static function initMethod(string $annotatedClassName, bool $onlyRouteAnnotations = false, string $methodName = null) { $methods = get_class_methods($annotatedClassName); if (isset($methodName)) { $methods = array($methodName); } foreach ($methods as $method) { $reader = new \Framework\Core\Annotations\AnnotationReader($annotatedClassName, $method); $all = $reader->getParameters(); if ($onlyRouteAnnotations === false) { $all = array_filter($all, function ($k) { return !in_array($k, \Framework\Core\Annotations\AnnotationConfig::ROUTE_ANNOTATIONS); }, ARRAY_FILTER_USE_KEY); } else { $all = array_filter($all, function ($k) { return in_array($k, \Framework\Core\Annotations\AnnotationConfig::ROUTE_ANNOTATIONS); }, ARRAY_FILTER_USE_KEY); } foreach ($all as $anon => $anonValue) { $className = AnnotationConfig::ANNOTATION_NAMESPACE . $anon; if (class_exists($className)) { $annotation = new $className(null, $annotatedClassName, $anonValue, null, null, $method); $annotation->execute(); } //let the app continue in case of the loader intercepting regular doc comments } } }
function register($group) { $group = basename($group); $directory = DIR_FS_CATALOG . 'includes/hooks/' . $this->_site . '/' . $group; if (file_exists($directory)) { if ($dir = @dir($directory)) { while ($file = $dir->read()) { if (!is_dir($directory . '/' . $file)) { if (substr($file, strrpos($file, '.')) == '.php') { $code = substr($file, 0, strrpos($file, '.')); $class = 'hook_' . $this->_site . '_' . $group . '_' . $code; include $directory . '/' . $file; $GLOBALS[$class] = new $class(); foreach (get_class_methods($GLOBALS[$class]) as $method) { if (substr($method, 0, 7) == 'listen_') { $this->_hooks[$this->_site][$group][substr($method, 7)][] = $code; } } } } } $dir->close(); } } }
public function load_extra_preloads($dir, $name) { $dir = rtrim($dir, '/'); $extra = array(); if (is_dir($dir . '/events')) { $file_list = XoopsLists::getFileListAsArray($dir . '/events'); foreach ($file_list as $file) { if (preg_match('/(\\.php)$/i', $file)) { $file = substr($file, 0, -4); $extra[] = $file; } } } foreach ($extra as $preload) { include_once $dir . '/events/' . $preload . '.php'; $class_name = ucfirst($name) . ucfirst($preload) . 'Preload'; if (!class_exists($class_name)) { continue; } $class_methods = get_class_methods($class_name); foreach ($class_methods as $method) { if (strpos($method, 'event') === 0) { $event_name = strtolower(str_replace('event', '', $method)); $event = array('class_name' => $class_name, 'method' => $method); $this->_events[$event_name][] = $event; } } } }
public function testFormatJson() { $server = ['HTTP_ACCEPT' => 'application/json', 'REQUEST_METHOD' => 'GET', 'SCRIPT_FILENAME' => 'my/base/path/my/request/uri/filename', 'REQUEST_URI' => 'my/base/path/my/request/uri', 'PHP_SELF' => 'my/base/path']; $request = new Request(["callback" => ""], [], [], [], [], $server); $apiResult = new Result($request); $return = $apiResult->createResponse()->getContent(); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $return); $response = json_decode($return); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $response); $this->assertObjectHasAttribute("meta", $response); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $response->meta); $this->assertObjectHasAttribute("response", $response); $this->assertInternalType(\PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT, $response->response); $this->assertEquals(0, sizeof(get_object_vars($response->response))); $this->assertEquals(0, sizeof(get_class_methods($response->response))); $this->checkResponseFieldMeta($response, "api_version", V1::VERSION, \PHPUnit_Framework_Constraint_IsType::TYPE_STRING); $this->checkResponseFieldMeta($response, "request", "GET my/base/path/my/request/uri", \PHPUnit_Framework_Constraint_IsType::TYPE_STRING); $date = new \DateTime(); $now = $date->format('U'); $dateQuery = \DateTime::createFromFormat(DATE_ATOM, $response->meta->response_time); $nowQuery = $dateQuery->format('U'); $this->assertLessThan(1, $nowQuery - $now); $this->assertDateAtom($response->meta->response_time); $date = new \DateTime(); $nowU = $date->format('U'); $dateResp = \DateTime::createFromFormat(DATE_ATOM, $response->meta->response_time); $respU = $dateResp->format('U'); $this->assertLessThan(3, abs($respU - $nowU), 'No more than 3sec between now and the query'); $this->checkResponseFieldMeta($response, "http_code", 200, \PHPUnit_Framework_Constraint_IsType::TYPE_INT); $this->checkResponseFieldMeta($response, "charset", "UTF-8", \PHPUnit_Framework_Constraint_IsType::TYPE_STRING); $this->assertObjectHasAttribute("error_message", $response->meta); $this->assertNull($response->meta->error_message); $this->assertObjectHasAttribute("error_details", $response->meta); $this->assertNull($response->meta->error_details); }
function is_callable($var, $syntax_only = false) { if ($syntax_only) { /* from The Manual: * If the syntax_only argument is TRUE the function only verifies * that var might be a function or method. It will only reject simple * variables that are not strings, or an array that does not have a * valid structure to be used as a callback. The valid ones are * supposed to have only 2 entries, the first of which is an object * or a string, and the second a string */ return is_string($var) || is_array($var) && count($var) == 2 && is_string(end($var)) && (is_string(reset($var)) || is_object(reset($var))); } else { if (is_string($var)) { return function_exists($var); } else { if (is_array($var) && count($var) == 2 && is_string($method = end($var))) { $obj = reset($var); if (is_string($obj)) { $methods = get_class_methods($obj); return (bool) (is_array($methods) && in_array(strtolower($method), $methods)); } else { if (is_object($obj)) { return method_exists($obj, $method); } } } } return false; } }
public function setUp() { parent::setUp(); $this->subject = new ErrorHandlerCache(); $this->frontendUserMock = $this->getMock('R3H6\\Error404page\\Facade\\FrontendUser', get_class_methods('R3H6\\Error404page\\Facade\\FrontendUser'), array(), '', false); $this->inject($this->subject, 'frontendUser', $this->frontendUserMock); }
function get_class_constructor($classname) { // Caching static $constructors = array(); if (!class_exists($classname)) { return false; } // Tests indicate this doesn't hurt even in PHP5. $classname = strtolower($classname); // Return cached value, if exists if (isset($constructors[$classname])) { return $constructors[$classname]; } // Get a list of methods. After examining several different ways of // doing the check, (is_callable, method_exists, function_exists etc) // it seems that this is the most reliable one. $methods = get_class_methods($classname); // PHP5 constructor? if (phpversion() >= '5') { if (in_array('__construct', $methods)) { return $constructors[$classname] = '__construct'; } } // If we have PHP5 but no magic constructor, we have to lowercase the methods $methods = array_map('strtolower', $methods); if (in_array($classname, $methods)) { return $constructors[$classname] = $classname; } return $constructors[$classname] = NULL; }
/** * Get Global Application CMS accessibility scope. * * @access public * @static * @uses Core\Config() * * @return array */ public static function getAccessibilityScope() { $scope = glob(Core\Config()->paths('mode') . 'controllers' . DIRECTORY_SEPARATOR . '*.php'); $builtin_scope = array('CMS\\Controllers\\CMS'); $builtin_actions = array(); $accessibility_scope = array(); foreach ($builtin_scope as $resource) { $builtin_actions = array_merge($builtin_actions, get_class_methods($resource)); } $builtin_actions = array_filter($builtin_actions, function ($action) { return !in_array($action, array('create', 'show', 'edit', 'delete', 'export'), true); }); foreach ($scope as $resource) { $resource = basename(str_replace('.php', '', $resource)); if ($resource !== 'cms') { $controller_name = '\\CMS\\Controllers\\' . $resource; $controller_class = new \ReflectionClass($controller_name); if (!$controller_class->isInstantiable()) { continue; } /* Create instance only if the controller class is instantiable */ $controller_object = new $controller_name(); if ($controller_object instanceof CMS\Controllers\CMS) { $accessibility_scope[$resource] = array_diff(get_class_methods($controller_name), $builtin_actions); array_push($accessibility_scope[$resource], 'index'); foreach ($accessibility_scope[$resource] as $key => $action_with_acl) { if (in_array($action_with_acl, $controller_object->skipAclFor, true)) { unset($accessibility_scope[$resource][$key]); } } } } } return $accessibility_scope; }
/** * Runs every function in {MODULE}\BootStrap.php function which end with 'Init' or starts with 'pre_' in function's name * @param Request $request */ protected function RunBootstarp(request &$request) { # both possible naming for bootstrap $bsfiles_path = array(); # we really don't want to confuse our selves # $bsfiles_path[] = array($request->module->full_name, $request->module->GetPath()."/{$request->module->full_name}Bootstrap.php"); $bsfiles_path[] = array($request->module->name, $request->module->GetPath() . "/{$request->module->name}Bootstrap.php"); foreach ($bsfiles_path as $bs) { $bs[1] = \zinux\kernel\utilities\fileSystem::resolve_path($bs[1]); if (file_exists($bs[1])) { require_once $bs[1]; $cname = "{$request->module->GetNameSpace()}\\{$bs[0]}Bootstrap"; if (class_exists($cname)) { $c = new $cname(); $m = get_class_methods($c); foreach ($m as $method) { if (\zinux\kernel\utilities\string::endsWith(strtoupper($method), "INIT") || \zinux\kernel\utilities\string::startsWith(strtoupper($method), "PRE_")) { if (!is_callable(array($c, $method))) { trigger_error("The method {$method} found in bootstrap file `{$bs[1]}` but is not callable"); } else { $c->{$method}($request); } } } } } } }
public function getHtmlData() { $htmlDataString = ""; foreach (get_class_methods(get_called_class()) as $method) { if (substr($method, 0, 3) == "get" && $method != "getHtmlData" && $method != "getPK") { $ref = new ReflectionMethod($this, $method); if (sizeOf($ref->getParameters()) == 0) { $field = strtolower(substr($method, 3)); $value = $this->{$method}(); if (is_object($value)) { if (get_class($value) != "Doctrine\\ORM\\PersistentCollection") { $field = "id{$field}"; $pkGetter = "get" . $field; $value = $value->{$pkGetter}(); $data = "data-{$field}=\"" . $value . "\" "; $htmlDataString .= $data; } } else { $data = "data-{$field}=\"" . $value . "\" "; $htmlDataString .= $data; } } } } return $htmlDataString . " data-crud=" . get_called_class() . " data-string=" . $this; }
function initialize(&$controller) { if (!empty($controller->_vars)) { $this->vars = $controller->_vars; } $this->controller = $controller->name; $this->view = $controller->view; $this->views_dir = isset($controller->views_dir) ? $controller->views_dir : 'views'; $this->data = $controller->data; //set helpers properties if (!empty($controller->helpers)) { $controller->helpers = (array) $controller->helpers; foreach ($controller->helpers as $k => $helper) { $config = array(); if (is_string($k)) { $config = $helper; $helper = $k; } $alias = Base::getClassName($helper); $this->{$alias} = new $helper(); if (!empty($config)) { foreach ($config as $k => $v) { $this->{$alias}->{$k} = $v; } } if (property_exists($this->{$alias}, 'view')) { $this->{$alias}->view =& $this; } if (in_array('initialize', get_class_methods($helper))) { $this->{$alias}->initialize(); } } } }
/** * Controller Auto-Router * * @param string $controller eg. 'Admin\\UserController' * @param array $request_methods eg. array('get', 'post', 'put', 'delete') * @param string $prefix eg. admin.users * @param array $disallowed eg. array('private_method that starts with one of request methods) * @return Closure */ public static function autoRoute($controller, $request_methods, $disallowed = array(), $prefix = '') { return function () use($controller, $prefix, $disallowed, $request_methods) { //get all defined functions $methods = get_class_methods(App::make($controller)); //laravel methods to disallow by default $disallowed_methods = array('getBeforeFilters', 'getAfterFilters', 'getFilterer'); //build list of functions to not allow if (is_array($disallowed)) { $disallowed_methods = array_merge($disallowed_methods, $disallowed); } //if there is a index method then lets just bind it and fill the gap in route_names if (in_array('getIndex', $methods)) { Lara::fillRouteGaps($prefix, $controller . '@getIndex'); } //over all request methods, get, post, etc foreach ($request_methods as $type) { //filter functions that starts with request method and not in disallowed list $actions = array_filter($methods, function ($action) use($type, $disallowed_methods) { return Str::startsWith($action, $type) && !in_array($action, $disallowed_methods); }); foreach ($actions as $action) { $controller_route = $controller . '@' . $action; // Admin\\Controller@get_login $url = Str::snake(str_replace($type, '', $action)); // login; snake_case //double check and dont bind to already bound gaps filled index if (in_array($action, $methods) && $action !== 'getIndex') { $route = str_replace('..', '.', $prefix . '.' . Str::snake($action)); Route::$type($url, array('as' => $route, 'uses' => $controller_route)); } } } }; }