コード例 #1
0
ファイル: Text.php プロジェクト: alekseynemiro/WebForms.PHP
 /**
  * Determines whether the end of a string matches with a specified string.
  * 
  * @param \string $str The string to check.
  * @param \string $comp The string to compare. 
  * 
  * @return \bool
  */
 public static function EndsWith($str, $comp)
 {
     $str = \Nemiro\Text::ClearUTF8BOM($str);
     return $comp === '' || ($temp = strlen($str) - strlen($comp)) >= 0 && strpos($str, $comp, $temp) !== FALSE;
 }
コード例 #2
0
ファイル: Page.php プロジェクト: alekseynemiro/WebForms.PHP
 private function ParseControlChild($scope, $parent, &$control, $source, $masked, $level)
 {
     if (!preg_match_all('/\\<(?<prefix>[\\w\\d]+):(?<tag>[\\w\\d\\x5F]+)/im', $masked, $matches, PREG_OFFSET_CAPTURE)) {
         return FALSE;
     }
     $maxEndIndex = -1;
     for ($i = 0; $i < count($matches['tag']); $i++) {
         $index = $matches['prefix'][$i][1];
         $endIndex = FALSE;
         if ($index <= $maxEndIndex) {
             continue;
         }
         $prefix = $matches['prefix'][$i][0];
         $name = $matches['tag'][$i][0];
         $nameLen = strlen($prefix) + strlen($name) + 1;
         if (!is_array($control) && !property_exists($control, $name)) {
             # \Nemiro\Console::Warning('Property "%s" not found in the "%s" class.', $name, get_class($control));
             $control->Content = $this->RanderControl($scope, $control->ID, $source);
             continue;
         }
         if (!is_array($control) && !isset($control->{$name})) {
             \Nemiro\Console::Warning('%s->%s can not be NULL.', get_class($control), $name);
             continue;
         }
         # select all before the first triangular brackets (>)
         if (($endOfDeclaration = strpos($masked, '>', $index)) === FALSE) {
             \Nemiro\Console::Warning('Invalid declaration format: <%s>.', $name);
             continue;
         }
         # instance
         if (!is_array($control)) {
             $instance = $control->{$name};
             # set id
             $instance->ID = sprintf('%s_%s%s', $parent != NULL ? $parent->ID : '', $control->TagName, $i + 1);
         } else {
             if (!class_exists($name)) {
                 \Nemiro\Console::Warning('Class %s not found.', $name);
                 continue;
             }
             $instance = new $name();
             $control[] = $instance;
             # set id
             $instance->ID = sprintf('%s_%s%s', $parent != NULL ? $parent->ID : '', $name, $i + 1);
         }
         # get attributes
         if ($endOfDeclaration - ($index + $nameLen + 1) > 0) {
             $attributes = trim(substr($source, $index + $nameLen + 1, $endOfDeclaration - ($index + $nameLen + 1)), ' /');
         } else {
             $attributes = '';
         }
         # set attributes
         if ($attributes != '') {
             $x = new \SimpleXMLElement('<item ' . $attributes . ' />');
             foreach ($x->attributes() as $attrKey => $attrValue) {
                 if (!isset($instance->{$attrKey})) {
                     \Nemiro\Console::Warning('%s->%s->%s can not be NULL.', get_class($control), $name, $attrKey);
                     continue;
                 }
                 if (!property_exists($instance, $attrKey)) {
                     \Nemiro\Console::Warning('Property "%s" not found in the "%s" instance.', $attrKey, $name);
                 }
                 $instance->{$attrKey} = $attrValue->__toString();
             }
         }
         # check the penultimate symbol
         if (substr($source, $endOfDeclaration - 1, 1) != '/') {
             # search closed block
             $endIndex = \Nemiro\Text::SearchEndsBlock($masked, $index + 1, '<' . $prefix . ':' . $name, '</' . $prefix . ':' . $name . '>');
         }
         if ($endIndex !== FALSE) {
             $new_source = substr($source, $endOfDeclaration + 1, $endIndex - $endOfDeclaration - 1);
             $new_masked = substr($masked, $endOfDeclaration + 1, $endIndex - $endOfDeclaration - 1);
             # parse childs of child
             if ($this->ParseControlChild($scope, $control, $instance, $new_source, $new_masked, $level + 1) === FALSE) {
                 if (!is_array($instance) && !property_exists($instance, 'Content')) {
                     \Nemiro\Console::Warning('Property "%s" not found in the "%s" class.', 'Content', get_class($instance));
                 } else {
                     $instance->Content = $this->Execute($new_source);
                 }
             }
             # remeber index
             if ($endIndex > $maxEndIndex) {
                 $maxEndIndex = $endIndex;
             }
         }
         $control->{$name} = $instance;
     }
     return TRUE;
 }
コード例 #3
0
				<php:Items>
					<php:TabItem Key="TabControl" Title="TabControl.php">
						<pre><code class="php"><?php 
echo str_replace("\t", '  ', \Nemiro\Text::HtmlEncode(file_get_contents(\Nemiro\Server::MapPath('~/Controls/TabControl.php'))));
?>
</code></pre>
					</php:TabItem>
					<php:TabItem Key="TabItem" Title="TabItem.php">
						<pre><code class="php"><?php 
echo str_replace("\t", '  ', \Nemiro\Text::HtmlEncode(file_get_contents(\Nemiro\Server::MapPath('~/Controls/TabItem.php'))));
?>
</code></pre>
					</php:TabItem>
					<php:TabItem Key="TabControlHtml" Title="TabControl.html.php">
						<pre><code class="html"><?php 
echo str_replace("\t", '  ', \Nemiro\Text::HtmlEncode(file_get_contents(\Nemiro\Server::MapPath('~/Controls/TabControl.html.php'))));
?>
</code></pre>
					</php:TabItem>
				</php:Items>
			</php:TabControl>
			<p>${ObjectModelText10}</p>
			<p>${ObjectModelText11}</p>
			<pre><code class="html">&lt;php:TabControl&gt;
  &lt;php:Items&gt;
    &lt;php:TabItem Key="Item1" Title="${Tab} #1"&gt;
      ${TabContent} #1
    &lt;/php:TabItem&gt;
    &lt;php:TabItem Key="Item2" Title="${Tab} #2"&gt;
      ${TabContent} #2
    &lt;/php:TabItem&gt;