switch example

/** @var TraceableEventDispatcher $dispatcher */
        $dispatcher = $this->getContainer()->get('event_dispatcher');

        $eventsToTest = [
            CustomerBeforeLoginEvent::class,
            CustomerLoginEvent::class,
        ];

        foreach ($eventsToTest as $eventClass) {
            $eventDidRun = false;

            switch ($eventClass) {
                case CustomerBeforeLoginEvent::class:
                    $listenerClosure = $this->getEmailListenerClosure($eventDidRun);

                    break;
                case CustomerLoginEvent::class:
                default:
                    $listenerClosure = $this->getCustomerListenerClosure($eventDidRun);
            }

            $this->addEventListener($dispatcher$eventClass$listenerClosure);

            

  protected function checkAccess(EntityInterface $entity$operation, AccountInterface $account) {
    /** @var \Drupal\media\MediaInterface $entity */
    // Allow admin permission to override all operations.     if ($account->hasPermission($this->entityType->getAdminPermission())) {
      return AccessResult::allowed()->cachePerPermissions();
    }

    $type = $entity->bundle();
    $is_owner = ($account->id() && $account->id() === $entity->getOwnerId());
    switch ($operation) {
      case 'view':
        if ($entity->isPublished()) {
          $access_result = AccessResult::allowedIf($account->hasPermission('view media'))
            ->cachePerPermissions()
            ->addCacheableDependency($entity);
          if (!$access_result->isAllowed()) {
            $access_result->setReason("The 'view media' permission is required when the media item is published.");
          }
        }
        elseif ($account->hasPermission('view own unpublished media')) {
          $access_result = AccessResult::allowedIf($is_owner)
            

    function clean_path(string $path): string
    {
        // Resolve relative paths         try {
            $path = realpath($path) ?: $path;
        } catch (ErrorException|ValueError $e) {
            $path = 'error file path: ' . urlencode($path);
        }

        switch (true) {
            case strpos($path, APPPATH) === 0:
                return 'APPPATH' . DIRECTORY_SEPARATOR . substr($pathstrlen(APPPATH));

            case strpos($path, SYSTEMPATH) === 0:
                return 'SYSTEMPATH' . DIRECTORY_SEPARATOR . substr($pathstrlen(SYSTEMPATH));

            case strpos($path, FCPATH) === 0:
                return 'FCPATH' . DIRECTORY_SEPARATOR . substr($pathstrlen(FCPATH));

            case defined('VENDORPATH') && strpos($path, VENDORPATH) === 0:
                return 'VENDORPATH' . DIRECTORY_SEPARATOR . substr($pathstrlen(VENDORPATH));

            
if ($message) {
      $this->messageText = $message;
    }
    else {
      $this->messageText = $this->getMessageFromFile($file);
    }

    // Include structured support info from composer.json.     if ($config_keys = $package_config['drupal-core-project-message']['include-keys'] ?? FALSE) {
      foreach ($config_keys as $config_key) {
        switch ($config_key) {
          case 'name':
            if ($homepage = $this->rootPackage->getName()) {
              $this->messageText[] = ' * Name: ' . $homepage;
            }
            break;

          case 'description':
            if ($homepage = $this->rootPackage->getDescription()) {
              $this->messageText[] = ' * Description: ' . $homepage;
            }
            break;

          
'enabled-auto-update-multi',
    'disabled-auto-update-multi',
    '_error_nonce',
);

$_SERVER['REQUEST_URI'] = remove_query_arg( $query_args_to_remove$_SERVER['REQUEST_URI'] );

wp_enqueue_script( 'updates' );

if ( $action ) {

    switch ( $action ) {
        case 'activate':
            if ( ! current_user_can( 'activate_plugin', $plugin ) ) {
                wp_die( __( 'Sorry, you are not allowed to activate this plugin.' ) );
            }

            if ( is_multisite() && ! is_network_admin() && is_network_only_plugin( $plugin ) ) {
                wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s) );
                exit;
            }

            check_admin_referer( 'activate-plugin_' . $plugin );

            
// Replace tags with regexes.             $match = str_replace( $this->rewritecode, $this->rewritereplace, $struct );

            // Make a list of tags, and store how many there are in $num_toks.             $num_toks = preg_match_all( '/%.+?%/', $struct$toks );

            // Get the 'tagname=$matches[i]'.             $query = ( ! empty( $num_toks ) && isset( $queries[ $num_toks - 1 ] ) ) ? $queries[ $num_toks - 1 ] : '';

            // Set up $ep_mask_specific which is used to match more specific URL types.             switch ( $dirs[ $j ] ) {
                case '%year%':
                    $ep_mask_specific = EP_YEAR;
                    break;
                case '%monthnum%':
                    $ep_mask_specific = EP_MONTH;
                    break;
                case '%day%':
                    $ep_mask_specific = EP_DAY;
                    break;
                default:
                    $ep_mask_specific = EP_NONE;
            }

        }
    }

    private function _endElement($file$name)
    {
        if (($this->_stag === true) and ($name !== 'source')) {
            $this->_scontent .= "</".$name.">";
        } else if (($this->_ttag === true) and ($name !== 'target')) {
            $this->_tcontent .= "</".$name.">";
        } else {
            switch (strtolower($name)) {
                case 'trans-unit':
                    $this->_transunit = null;
                    $this->_langId    = null;
                    $this->_scontent  = null;
                    $this->_tcontent  = null;
                    break;
                case 'source':
                    if ($this->_useId) {
                        if (!empty($this->_scontent) && !empty($this->_langId) &&
                            !isset($this->_data[$this->_source][$this->_langId])) {
                            $this->_data[$this->_source][$this->_langId] = $this->_scontent;
                        }


    /** * Getter. * * @since 4.4.0 * * @param string $key Property to get. * @return mixed Property value. */
    public function __get( $key ) {
        switch ( $key ) {
            case 'data':
                $data    = new stdClass();
                $columns = array( 'term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count' );
                foreach ( $columns as $column ) {
                    $data->{$column} = isset( $this->{$column} ) ? $this->{$column} : null;
                }

                return sanitize_term( $data$data->taxonomy, 'raw' );
        }
    }
}

        else
        {
            $options = explode(',', $options);
            foreach($options as $option)
            {
                $opt = explode(':', $option, 2);
                if (isset($opt[0]$opt[1]))
                {
                    $opt[0] = trim($opt[0]);
                    $opt[1] = trim($opt[1]);
                    switch ($opt[0])
                    {
                        case 'audio':
                            $audio = $opt[1];
                            break;

                        case 'video':
                            $video = $opt[1];
                            break;

                        case 'alt':
                            $alt = $opt[1];
                            

    private function getRequestBody(Request $request): array
    {
        $contentType = $request->headers->get('CONTENT_TYPE', '');
        $semicolonPosition = mb_strpos($contentType, ';');

        if ($semicolonPosition !== false) {
            $contentType = mb_substr($contentType, 0, $semicolonPosition);
        }

        try {
            switch ($contentType) {
                case 'application/vnd.api+json':
                    return $this->serializer->decode($request->getContent(), 'jsonapi');
                case 'application/json':
                    return $request->request->all();
            }
        } catch (InvalidArgumentException|UnexpectedValueException $exception) {
            throw ApiException::badRequest($exception->getMessage());
        }

        throw ApiException::unsupportedMediaType($contentType);
    }

    
function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
    if ( false === $commenttxt ) {
        $commenttxt = _x( 'Comment', 'noun' );
    }
    if ( false === $trackbacktxt ) {
        $trackbacktxt = __( 'Trackback' );
    }
    if ( false === $pingbacktxt ) {
        $pingbacktxt = __( 'Pingback' );
    }
    $type = get_comment_type();
    switch ( $type ) {
        case 'trackback':
            echo $trackbacktxt;
            break;
        case 'pingback':
            echo $pingbacktxt;
            break;
        default:
            echo $commenttxt;
    }
}

->willReturnCallback(function D$argument) use ($translations) {
        if (isset($translations[$argument['language']][$argument['source']])) {
          return (object) ['translation' => $translations[$argument['language']][$argument['source']]];
        }

        return TRUE;
      });

    $this->languageManager->expects($this->any())
      ->method('getFallbackCandidates')
      ->willReturnCallback(function Darray $context = []) {
        switch ($context['langcode']) {
          case 'pl':
            return ['cs', 'en'];

          case 'cs':
            return ['en'];

          default:
            return [];
        }
      });

    

  protected static function getModifiedEntityForPatchTesting(EntityInterface $entity) {
    $modified_entity = clone $entity;
    $original_values = [];
    foreach (array_keys(static::$patchProtectedFieldNames) as $field_name) {
      $field = $modified_entity->get($field_name);
      $original_values[$field_name] = $field->getValue();
      switch ($field->getItemDefinition()->getClass()) {
        case EntityReferenceItem::class:
          // EntityReferenceItem::generateSampleValue() picks one of the last 50           // entities of the supported type & bundle. We don't care if the value           // is valid, we only care that it's different.           $field->setValue(['target_id' => 99999]);
          break;

        case BooleanItem::class:
          // BooleanItem::generateSampleValue() picks either 0 or 1. So a 50%           // chance of not picking a different value.           $field->value = ((int) $field->value) === 1 ? '0' : '1';
          

    public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
    {
        switch ($mode) {
            case Zend_Cache::CLEANING_MODE_ALL:
            case Zend_Cache::CLEANING_MODE_OLD:
                $cache_dir = ini_get('zend_accelerator.output_cache_dir');
                if (!$cache_dir) {
                    return false;
                }
                $cache_dir .= '/.php_cache_api/';
                return $this->_clean($cache_dir$mode);
                break;
            case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
                $idlist = null;
                
// $all_empty = null;     // $day_empty = null;     // $month_empty = null;     // $year_empty = null;     $extra_attrs = '';
    $all_id = null;
    $day_id = null;
    $month_id = null;
    $year_id = null;

    foreach ($params as $_key => $_value) {
        switch ($_key) {
            case 'time':
                if (!is_array($_value) && $_value !== null) {
                    $time = smarty_make_timestamp($_value);
                }
                break;
                
            case 'month_names':
                if (is_array($_value) && count($_value) == 12) {
                    $$_key = $_value;
                } else {
                    trigger_error("html_select_date: month_names must be an array of 12 strings", E_USER_NOTICE);
                }
Home | Imprint | This part of the site doesn't use cookies.