/** * Attempts to serialize $var according to $format, setting the * proper content type and returning the serialization. * TODO: improve content type. * * @return string */ public function renderSerialized($var, $format) { if (is_string($var)) { $serialized = $var; } elseif (is_object($var)) { $toMethod = 'to' . ucFirst($format); if ($var instanceof \Rails\ActiveRecord\Relation) { $serialized = $var->records()->{$toMethod}(); } else { if (is_callable([$var, $toMethod])) { $serialized = $var->{$toMethod}(); } } } elseif (is_array($var)) { if ($format == 'json') { $serialized = json_encode($var); } } if (!isset($serialized)) { if (is_object($var)) { $message = sprintf("Can't serialize object of class %s to format %s", get_class($var), $format); } else { $message = sprintf("Can't serialize variable of type %s to format %s", gettype($var), $format); } throw new Exception\RuntimeException($message); } $this->controller->response()->setContentType(MimeTypes::getMimeType($format)); return $serialized; }
public function parse($request) { if ($this->method && !$request->isMethod($this->method)) { return false; } if ($this->secure && !$request->isSecure()) { return false; } // parse url stuff $uri = substr($request->path, strlen(Router::base())); if (!preg_match($this->compile(), (string) $uri, $found)) { return false; } foreach ($found as $index => $match) { if (is_int($index)) { unset($found[$index]); } } $result = $found + $this->params; if (!strstr($result['controller'], '\\')) { if ($result['controller'] !== 'Controller') { $append = 'Controller'; } else { $append = ''; } $result['controller'] = trim($result['namespace'], '\\') . '\\' . ucFirst($result['controller']) . $append; } unset($result['namespace']); return $result; }
public function testEntityConfigurator() { $utils = new Utils(); $router = $this->_kernel->getContainer()->get('router'); $translator = $this->_kernel->getContainer()->get('translator'); $entityName = 'entityconfigurator'; $route = $router->generate('entitygen'); $crawler = $this->client->request('GET', $route); //navigate to index page $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), 'Server error on index ' . $entityName); $this->assertGreaterThan(0, $crawler->filter('h1:contains("' . $translator->trans($entityName . '.indextitle') . '")')->count(), 'Navigate to index form of' . $entityName); //select and click on Add link $link = $crawler->selectLink($translator->trans('buttons.add'))->link(); $crawler = $this->client->click($link); $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), 'Server error on creation ' . $entityName); $this->assertGreaterThan(0, $crawler->filter('h1:contains("' . $translator->trans($entityName . '.newtitle') . '")')->count(), 'Navigate to Creation form of' . $entityName); $buttonCrawlerNode = $crawler->selectButton($translator->trans('buttons.save')); $form = $buttonCrawlerNode->form(); $var = $utils->getRandomVariable(6, 'string'); $category = $this->_kernel->getContainer()->get('doctrine')->getEntityManager()->getRepository('LowbiConfiguratorBundle:Category')->findOneByName('Defaut'); $crawler = $this->client->submit($form, array('lowbi_configuratorbundle_entityconfiguratortype[tableName]' => 'test_' . $var, 'lowbi_configuratorbundle_entityconfiguratortype[bundleName]' => 'LowbiSystemBundle', 'lowbi_configuratorbundle_entityconfiguratortype[entityName]' => 'Entity' . ucFirst($var), 'lowbi_configuratorbundle_entityconfiguratortype[category]' => $category->getId(), 'lowbi_configuratorbundle_entityconfiguratortype[routePrefix]' => $var, 'lowbi_configuratorbundle_entityconfiguratortype[security]' => '1', 'lowbi_configuratorbundle_entityconfiguratortype[administrable]' => '1')); /* $this->assertEquals(200,$this->client->getResponse()->getStatusCode(),'Server error on details '.$entityName); $this->assertGreaterThan(0,$crawler->filter('h1:contains("'.$translator->trans($entityName.'.edittitle').'")')->count(),'Navigate to Show form of'.$entityName); //Add fields to the entity $var = $utils->getRandomVariable(6, 'string'); $crawler = $this->client->submit($form, array( 'lowbi_configuratorbundle_entityconfiguratortype[fields][0][fieldName]' => 'field'.$var, 'lowbi_configuratorbundle_entityconfiguratortype[fields][0][fieldType]' => 'string', 'lowbi_configuratorbundle_entityconfiguratortype[fields][0][fragment]' => 'text', 'lowbi_configuratorbundle_entityconfiguratortype[fields][0][length]' => '50', 'lowbi_configuratorbundle_entityconfiguratortype[fields][0][search]' => '1', 'lowbi_configuratorbundle_entityconfiguratortype[fields][0][required]' => '1', 'lowbi_configuratorbundle_entityconfiguratortype[fields][1][fieldName]' => 'fieldOther'.$var, 'lowbi_configuratorbundle_entityconfiguratortype[fields][1][fieldType]' => 'integer', 'lowbi_configuratorbundle_entityconfiguratortype[fields][1][fragment]' => 'number', 'lowbi_configuratorbundle_entityconfiguratortype[fields][1][length]' => '5', 'lowbi_configuratorbundle_entityconfiguratortype[fields][1][search]' => '1', 'lowbi_configuratorbundle_entityconfiguratortype[fields][1][required]' => '1', )); $this->assertEquals(200,$this->client->getResponse()->getStatusCode(),'Server error on details '.$entityName); $this->assertGreaterThan(0,$crawler->filter('h1:contains("'.$translator->trans($entityName.'.showtitle').'")')->count(),'Navigate to Show form of'.$entityName); //select and click on Edit link $link = $crawler->selectLink($translator->trans('entityconfigurator.loadentity'))->link(); $crawler = $this->client->click($link); $this->assertEquals(200,$this->client->getResponse()->getStatusCode(),'Server error on edition '.$entityName); $this->assertGreaterThan(0,$crawler->filter('h1:contains("'.$translator->trans($entityName.'.showtitle').'")')->count(),'Navigate to Show form of'.$entityName); $link = $crawler->selectLink($translator->trans('entityconfigurator.loadfield'))->link(); $crawler = $this->client->click($link); $this->assertEquals(200,$this->client->getResponse()->getStatusCode(),'Server error on index '.$entityName); $this->assertGreaterThan(0,$crawler->filter('h1:contains("'.$translator->trans($entityName.'.showtitle').'")')->count(),'Navigate to Show form of'.$entityName); */ }
function statistics() { // load Model ForumCategory App::import('Model', 'ForumCategory'); // Initialize $this->ForumCategory object $this->ForumCategory = new ForumCategory(); // get data $stat['user'] = $this->ForumCategory->StaffInformation->find('count'); $stat['category'] = $this->ForumCategory->find('count'); $stat['topic'] = $this->ForumCategory->ForumTopic->find('count'); $stat['reply'] = $this->ForumCategory->ForumTopic->ForumReply->find('count'); // generate HTML for statistics $html1 = "\n <div id='sidebar'>\n <h2>Statistics</h2>\n <ol style='list-style-type:none; margin-left:-20px'>\n "; // $html1 // Foreach foreach ($stat as $k => $v) { // generate <li>key : value</li> html tag $html2[] = $this->Html->tag('li', sprintf("%s : %s", ucFirst($k), $v)); } // Convert Array to String using implode() | php.net/implode $html2 = implode(' ', $html2); $html3 = "\n </ol>\n </div>\n "; // $html3 echo $html1 . $html2 . $html3; // combine all 3 variables and return }
public function outputConstructor(ClassEntity $entity) { // Get the property names $propertyNames = array(); foreach ($entity->getMembers() as $member) { if ($member->getType() == 'property') { $propertyNames[] = $member->getName(); } } // Create the code block line by line $lines = array(); if (count($propertyNames) == 0) { $lines[] = "public function __construct()"; } else { $lines[] = "public function __construct(\$" . implode(", \$", $propertyNames) . ")"; } $lines[] = "{"; foreach ($entity->getMembers() as $member) { if ($member->getType() == 'setter') { $lines[] = $this->getIndentation() . '$this->set' . ucFirst($member->getName()) . '($' . $member->getName() . ');'; } } $lines[] = '}'; foreach ($lines as $key => $line) { $lines[$key] = $this->getIndentation() . $line; } return implode("\n", $lines); }
/** * Get the organization entered in the Structed data admin if any */ private function getOrganization() { if (!is_null($this->Org)) { return $this->Org; } $options = get_option('_settingsSettingsStructuredData', true); if (isset($options['homepage']) && isset($options['homepage']['Organization']) && isset($options['homepage']['Organization']['legalName']) && isset($options['homepage']['Organization']['url']) && !empty($options['homepage']['Organization']['legalName']) && !empty($options['homepage']['Organization']['url'])) { $Org = Schema\OrganizationSchema::factory(); $add = array('legalName', 'url', 'email', 'telephone', 'faxNumber'); foreach ($add as $key) { if (!empty($options['homepage']['Organization'][$key])) { $func = "set" . ucFirst($key); $Org->{$func}($options['homepage']['Organization'][$key]); // Name is also required in some cases, so duplicate legalName if ($key === 'legalName') { $Org->setName($options['homepage']['Organization'][$key]); } } } if (intval($options['homepage']['Organization']['logo']['id']) > 0) { $logo = wp_get_attachment_image_src($options['homepage']['Organization']['logo']['id'], 'full'); $Org->setLogo($logo[0]); } // Make Organization available for singular items $this->Org = $Org; } else { $this->Org = false; } return $this->Org; }
public function invoke(Scaffolding $scaffolding) { $name = ucFirst($this->in->getArgument('name')); $file = $scaffolding->createUnitTest($name); $this->writeCreatedFilesHeader(); $this->writeCreatedFile($file); }
/** * Returns the singular form of a word * * If the method can't determine the form with certainty, an array of the * possible singulars is returned. * * @param string $plural A word in plural form * @return string|array The singular form or an array of possible singular * forms */ public static function singularify($plural) { $pluralRev = strrev($plural); $lowerPluralRev = strtolower($pluralRev); $pluralLength = strlen($lowerPluralRev); // The outer loop $i iterates over the entries of the plural table // The inner loop $j iterates over the characters of the plural suffix // in the plural table to compare them with the characters of the actual // given plural suffix for ($i = 0, $numPlurals = count(self::$pluralMap); $i < $numPlurals; ++$i) { $suffix = self::$pluralMap[$i][self::PLURAL_SUFFIX]; $suffixLength = self::$pluralMap[$i][self::PLURAL_SUFFIX_LENGTH]; $j = 0; // Compare characters in the plural table and of the suffix of the // given plural one by one while ($suffix[$j] === $lowerPluralRev[$j]) { // Let $j point to the next character ++$j; // Successfully compared the last character // Add an entry with the singular suffix to the singular array if ($j === $suffixLength) { // Is there any character preceding the suffix in the plural string? if ($j < $pluralLength) { $nextIsVocal = false !== strpos('aeiou', $lowerPluralRev[$j]); if (!self::$pluralMap[$i][self::PLURAL_SUFFIX_AFTER_VOCAL] && $nextIsVocal) { break; } if (!self::$pluralMap[$i][self::PLURAL_SUFFIX_AFTER_CONS] && !$nextIsVocal) { break; } } $newBase = substr($plural, 0, $pluralLength - $suffixLength); $newSuffix = self::$pluralMap[$i][self::SINGULAR_SUFFIX]; // Check whether the first character in the plural suffix // is uppercased. If yes, uppercase the first character in // the singular suffix too $firstUpper = ctype_upper($pluralRev[$j - 1]); if (is_array($newSuffix)) { $singulars = array(); foreach ($newSuffix as $newSuffixEntry) { $singulars[] = $newBase . ($firstUpper ? ucfirst($newSuffixEntry) : $newSuffixEntry); } return $singulars; } return $newBase . ($firstUpper ? ucFirst($newSuffix) : $newSuffix); } // Suffix is longer than word if ($j === $pluralLength) { break; } } } // Convert teeth to tooth, feet to foot if (false !== ($pos = strpos($plural, 'ee'))) { return substr_replace($plural, 'oo', $pos, 2); } // Assume that plural and singular is identical return $plural; }
/** * @param array $values * * @return Page */ protected function createPage(array $values = array()) { $page = new Page(); foreach ($values as $key => $value) { $page->{'set' . ucFirst($key)}($value); } return $page; }
protected function modify(Menu $menu) { $requete = $this->dao->prepare('UPDATE menus SET name = :name, slug = :slug WHERE id = :id'); $requete->bindValue(':name', ucFirst($menu->name()), \PDO::PARAM_STR); $requete->bindValue(':slug', strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|copy|th|tilde|uml);~i', '$1', htmlentities($menu->name(), ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-')), \PDO::PARAM_STR); $requete->bindValue(':id', $menu->id(), \PDO::PARAM_INT); $requete->execute(); }
/** * Tests the type detector methods * * @dataProvider typesProvider * @return void */ public function testDetectors($type) { $event = new SendgridEvent(); $event->set(array('event' => $type, 'email' => '*****@*****.**')); $this->assertTrue($event->{'is' . ucFirst($type)}()); $event->type = 'foo'; $this->assertFalse($event->{'is' . ucFirst($type)}()); }
/** * Returns the class that overrides the default One_Model * * @param One_Scheme $scheme * @return One_Model */ public function onCreateModel(One_Scheme $scheme) { $options = $scheme->get('behaviorOptions.class'); $className = $options['className']; if (!$className) { $className = 'One_Model_' . ucFirst($scheme->getName()); } return new $className($scheme); }
public function run() { class_exists('gapi') or (require dirname(__FILE__) . '/../../../vendor/gapi/gapi.class.php'); $ga = new gapi($this->email, $this->password); $ga->requestReportData($this->profile_id, array('date'), array($this->metric), null, null, date('Y-m-d', strtotime('yesterday')), date('Y-m-d', strtotime('-' . $this->time))); $methodName = 'get' . ucFirst($this->metric); $this->result = $ga->{$methodName}(); return parent::afterConstruct(); }
public function handle($what) { $f = 'handle' . ucFirst(str_replace(['-', '_'], '', $what)); if (!$what || !method_exists($this, $f)) { return null; } Util::sendNoCacheHeader(); return $this->{$f}(); }
/** * génère une version string * @return string */ public function __toString() { $method = 'toString' . ucFirst($this->_tag); $html = $this->{$method}(); if (!is_null($this->_tooltip)) { $html .= Vue::tooltip($this->_tooltip); } return $html; }
public function hydrate(array $data) { foreach ($data as $key => $value) { $method = "set" . ucFirst($key); if (method_exists($this, $method)) { $this->{$method}($value); } } }
/** * Gets the simple class name of the given page id. * * This method doesn't check its parameter. For example, "delete_article" * would turn into "DeleteArticlePage", even if no such page would exist. * @param string $pageName The page id. * @return string The simple class name. */ private function getPageClassName($pageName) { $pageParts = explode("_", $pageName); $pageClassName = 'Rcms\\Page\\'; foreach ($pageParts as $part) { $pageClassName .= ucFirst($part); } $pageClassName .= "Page"; return $pageClassName; }
/** * @dataProvider getSetterAndGetterProvider */ public function testSetterAndGetter($name, $before, $value) { $this->assertNotEquals($before, $value); $get = 'get' . ucFirst($name); $set = 'set' . ucFirst($name); $this->assertEquals($before, $this->testClass->{$get}()); $this->testClass->{$set}($value); $this->assertNotEquals($before, $this->testClass->{$get}()); $this->assertEquals($value, $this->testClass->{$get}()); }
private function __construct() { $this->driver = substr(DBNAME, 0, strpos(DBNAME, ":")); $helper = __NAMESPACE__ . "\\" . ucFirst($this->driver) . "Helper"; if (class_exists($helper, true)) { $this->helper = new $helper(DBNAME, DBLOGIN, DBPASSWORD); } else { $this->helper = new PDOHelper(DBNAME, DBLOGIN, DBPASSWORD); } }
/** * {@inheritdoc} */ public function rewrite(FunctionCallNode $call, TargetInterface $target) { $arguments = $call->getArguments(); if ($arguments[0] instanceof StringNode) { $handler_type = $arguments[0]->toValue(); if ($handler_type == 'validate' || $handler_type == 'submit') { return ClassMethodCallNode::create('\\Drupal', 'formBuilder')->appendMethodCall('execute' . ucFirst($handler_type) . 'Handlers')->appendArgument(clone $arguments[1])->appendArgument(clone $arguments[2]); } } }
function controller($controller) { $file = CONTROLLER . $controller . '.php'; if (file_exists($file)) { require_once $file; $class = 'Controller' . ucFirst(preg_replace('/[^a-zA-z0-9_]/', '', $controller)); return new $class($this->registry); } else { trigger_error("下载controller:" . $controller . '失败'); } }
/** * For Continent * * @static * @access public * @return array time zones applicable for the "continent" * @param string $continent Europe|America|Africa|Asia|Pacific|Australia| * Indian|Atlantic|Antartica */ function forContinent($continent) { $continent = ucFirst(strToLower($continent)); if (!count($GLOBALS['_I18Nv2_Continental_Timezones'])) { foreach (I18Nv2_Timezone::getAll(true) as $tz) { $cn = current($a = explode('/', $tz, 2)); $GLOBALS['_I18Nv2_Continental_Timeszones'][$cn][] = $tz; } } return isset($GLOBALS['_I18Nv2_Continental_Timeszones'][$continent]) ? $GLOBALS['_I18Nv2_Continental_Timeszones'][$continent] : array(); }
public function getText($varname, $default = null) { $languageId = I18n::locale(); $languageModelName = 'Text' . ucFirst(substr($languageId, 0, 2)); if (!isset($this->{$languageModelName})) { $languageModelName = 'Text' . ucfirst(substr(Registry::get('I18n.language'), 0, 2)); } if ($this->{$languageModelName} instanceof Model && $this->{$languageModelName}->hasField($varname)) { return coalesce($this->{$languageModelName}->get($varname), $default, false); } }
public function rules() { $method = 'rules' . ucFirst($this->action); if (method_exists($this, $method)) { $this->{$method}(); } elseif ($this->admin) { $this->rulesAdmin(); } else { throw new \Exception(ErrorMessage::controllers(1, $method, get_class($this))); } }
/** * @return Nano_Helper * @param string $name * @param boolean $isClass */ protected function search($name, $isClass) { if ($isClass) { $className = $name; } else { $className = ucFirst($name) . 'Helper'; } if (!class_exists($className)) { return null; } return new $className(); }
/** * Decorates the cell with formatted information about the module in it * @param zibo\library\html\table\Cell $cell The cell to decorate * @param zibo\library\html\table\Row $row The row containing the cell * @param integer $rowNumber The number of the current row * @param array $remainingValues Array with the values of the remaining rows * @return null */ public function decorate(Cell $cell, Row $row, $rowNumber, array $remainingValues) { $html = ''; $module = $cell->getValue(); $id = $module['name'] . ucFirst($module['namespace']); $html .= $this->getModulesHtml($module['dependencies'], $id, 'dependencies', 'modules.label.depends.module', 'modules.label.depends.modules'); $html .= $this->getModulesHtml($module['usage'], $id, 'usage', 'modules.label.used.module', 'modules.label.used.modules'); if ($html != '') { $html = '<div class="info">' . $html . '</div>'; } $html = '<span class="module">' . $this->getNameHtml($module) . '</span>' . $html; $cell->setValue($html); }
protected function hydrate(array $tab) { foreach ($tab as $key => $value) { //Si il y a un point devant la chaine if ($pos = strpos($key, '.')) { $key = substr($key, $pos, -1); } $method = 'set' . ucFirst($key); if (method_exists($this, $method)) { $this->{$method}($value); } } }
/** * @param $model * @param string $id * @return \Illuminate\Http\JsonResponse */ public function delete($model, $id = '') { $modelClass = 'App\\' . ucFirst($model); $object = $modelClass::whereId($id)->first(); if (is_object($object)) { $object->delete(); $this->responseContainer['status'] = 'ok'; $this->responseContainer['message'] = 'data has been deleted'; } else { $this->responseContainer['error'] = 'data not found'; } return $this->responseHandler(); }
protected function writeCalendars(StreamInterface $stream) { $text = $this->text; for ($i = 1; $i <= 12; $i++) { $month = DateTime::createFromFormat("Y n j", $this->year->format("Y") . ' ' . $i . ' 1'); $calendarTemplate = new CalendarTemplate($text, $month, $this->articlesInYear, $this->createLinks); $monthName = ucFirst($calendarTemplate->getMonthName($month)); $yearNumber = $month->format("Y"); $stream->write('<div class="calender_month_wrapper">'); $stream->write("<h3>{$monthName} {$yearNumber}</h3>"); $calendarTemplate->writeText($stream); $stream->write('</div>'); } }
protected function modify(Item $item) { $requete = $this->dao->prepare('UPDATE items SET name = :name, slug = :slug, href = :href, minAuth = :minAuth, maxAuth = :maxAuth, itemOrder = :itemOrder, menuId = :menuId, className = :className WHERE id = :id'); $requete->bindValue(':name', ucFirst($item->name()), \PDO::PARAM_STR); $requete->bindValue(':slug', strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|copy|th|tilde|uml);~i', '$1', htmlentities($item->name() . $item->menuId(), ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-')), \PDO::PARAM_STR); $requete->bindValue(':href', $item->href(), \PDO::PARAM_STR); $requete->bindValue(':minAuth', $item->minAuth(), \PDO::PARAM_INT); $requete->bindValue(':maxAuth', $item->maxAuth(), \PDO::PARAM_INT); $requete->bindValue(':itemOrder', $item->itemOrder(), \PDO::PARAM_INT); $requete->bindValue(':menuId', $item->menuId(), \PDO::PARAM_INT); $requete->bindValue(':className', $item->className(), \PDO::PARAM_STR); $requete->bindValue(':id', $item->id(), \PDO::PARAM_INT); $requete->execute(); }