/**
  * {@inheritdoc}
  */
 public function getFirstEntry() : EntryInterface
 {
     if (0 === $this->stack->count()) {
         throw new \RuntimeException('Trace empty');
     }
     return $this->stack->bottom();
 }
 public function getPredicate()
 {
     $predicate = $this->predicateStack->bottom()->pruneInstancesOf(NullPredicate::class, true)->pruneRedundantComposites(true);
     if ($predicate instanceof CompositePredicate) {
         $predicate = $predicate->pruneInstancesOf(NullPredicate::class, true);
     }
     return $predicate;
 }
 /**
  * @return ResourceInterface
  */
 public function bottom()
 {
     return $this->transform(parent::bottom());
 }
Beispiel #4
0
 /**
  * Convenient access to the first handler return value.
  *
  * @return mixed The first handler return value
  */
 public function first()
 {
     return parent::bottom();
 }
Beispiel #5
0
 /**
  * Get committed exceptions in the group.
  *
  * @return  \ArrayObject
  */
 public function getExceptions()
 {
     return $this->_group->bottom();
 }
Beispiel #6
0
 /**
  * Count the number of committed exceptions.
  *
  * @return  int
  */
 public function count()
 {
     return count($this->_group->bottom());
 }
Beispiel #7
0
 /**
  * Process start elements
  * @param $parser
  * @param $name
  * @param $attrs
  */
 protected function startElement($parser, $name, $attrs)
 {
     // Interpolate properties into the attributes
     $attrs = $this->substituteProperties($attrs);
     switch ($name) {
         case 'ROLE':
             $role = new Rs\CreateRole($attrs['NAME'], $attrs['DESCRIPTION'], []);
             $this->stack->push($role);
             break;
         case 'TASK':
             $role = $this->stack->pop();
             $role->TaskIDs[] = $attrs['ID'];
             $this->stack->push($role);
             break;
         case 'FOLDER':
             fwrite(STDOUT, sprintf('Creating folder: %s%s%s', $this->path->top(), $this->path->top() == self::ROOT ? '' : '/', $attrs['NAME']) . PHP_EOL);
             $folder = new Rs\CreateFolder($attrs['NAME'], $this->path->top(), []);
             try {
                 $this->rs->CreateFolder($folder);
             } catch (SoapFault $e) {
                 // Ignore already exists exceptions
                 if (strpos($e->getMessage(), 'Microsoft.ReportingServices.Diagnostics.Utilities.ItemAlreadyExistsException') === false) {
                     throw $e;
                 }
             } catch (Exception $e) {
                 fwrite(STDERR, 'Error: ' . $e->getMessage() . PHP_EOL);
             }
             // Push the folder onto the queue.  In SSRS root folder must be '/', but no other folders can have trailing slashes :(
             if ($this->path->top() != self::ROOT) {
                 $this->path->push($this->path->top() . '/' . $attrs['NAME']);
             } else {
                 $this->path->push($this->path->top() . $attrs['NAME']);
             }
             break;
         case 'DATASOURCE':
             fwrite(STDOUT, sprintf('Creating data source: %s%s%s', $this->path->top(), $this->path->top() == self::ROOT ? '' : '/', $attrs['NAME']) . PHP_EOL);
             // Overwrite?
             $overwrite = $this->getAttrDefault('OVERWRITE', $attrs, 'true') == 'true';
             // Build definition
             $definition = new Rs\DataSourceDefinition();
             $definition->ConnectString = $this->getAttrDefault('CONNECTSTRING', $attrs, '');
             $definition->Extension = $this->getAttrDefault('EXTENSION', $attrs, 'SQL');
             $definition->Enabled = $this->getAttrDefault('ENABLED', $attrs, 'true') == 'true';
             $definition->UseOriginalConnectString = $this->getAttrDefault('ORIGINALCONNECTSTRINGEXPRESSIONBASED', $attrs, 'false') == 'true';
             $definition->OriginalConnectStringExpressionBased = $this->getAttrDefault('ORIGINALCONNECTSTRINGEXPRESSIONBASED', $attrs, 'false') == 'true';
             $definition->WindowsCredentials = $this->getAttrDefault('WINDOWSCREDENTIALS', $attrs, 'false') == 'true';
             $definition->ImpersonateUser = $this->getAttrDefault('IMPERSONATEUSER', $attrs, 'false') == 'true';
             $credentialRetrieval = $this->getAttrDefault('CREDENTIALRETRIEVAL', $attrs, 'Prompt');
             switch (strtoupper($credentialRetrieval)) {
                 case 'PROMPT':
                     $definition->Prompt = $this->getAttrDefault('PROMPT', $attrs, '');
                     $definition->CredentialRetrieval = Rs\CredentialRetrievalEnum::Prompt;
                     break;
                 case 'STORE':
                     $definition->CredentialRetrieval = Rs\CredentialRetrievalEnum::Store;
                     $definition->UserName = $this->getAttrDefault('USERNAME', $attrs, '');
                     $definition->Password = $this->getAttrDefault('PASSWORD', $attrs, '');
                     break;
                 case 'INTEGRATED':
                     $definition->CredentialRetrieval = Rs\CredentialRetrievalEnum::Integrated;
                     break;
                 case 'NONE':
                     $definition->CredentialRetrieval = Rs\CredentialRetrievalEnum::None;
                     break;
                 default:
                     throw new Exception("Invalid credential retrieval: " . $credentialRetrieval);
             }
             $dataSource = new Rs\CreateDataSource($attrs['NAME'], $this->path->top(), $overwrite, $definition, []);
             try {
                 $this->rs->CreateDataSource($dataSource);
             } catch (Exception $e) {
                 fwrite(STDERR, 'Error: ' . $e->getMessage() . PHP_EOL);
             }
             break;
         case 'DATASET':
             fwrite(STDOUT, sprintf('Creating dataset: %s%s%s', $this->path->top(), $this->path->top() == self::ROOT ? '' : '/', $attrs['NAME']) . PHP_EOL);
             $dataset = new Rs\CreateCatalogItem();
             $dataset->ItemType = 'DataSet';
             $dataset->Name = $attrs['NAME'];
             $dataset->Parent = $this->path->top();
             $dataset->Overwrite = true;
             if (!is_readable($attrs['DEFINITION'])) {
                 throw new Exception("File not found: " . $attrs['DEFINITION']);
             }
             // Change definition to point to live data source, if necessary
             $definition = file_get_contents($attrs['DEFINITION']);
             if (array_key_exists('DATASOURCEREF', $attrs)) {
                 $dsRef = $attrs['DATASOURCEREF'];
                 $rootRef = $this->path->bottom();
                 if ($rootRef != self::ROOT) {
                     $dsRef = $rootRef . $dsRef;
                 }
                 fwrite(STDOUT, sprintf('    Linking data source: %s', $dsRef) . PHP_EOL);
                 $xml = new SimpleXMLElement($definition);
                 $xml->DataSet->Query->DataSourceReference = $dsRef;
                 $definition = $xml->asXML();
             }
             $dataset->Definition = $definition;
             $dataset->Properties = [];
             try {
                 $response = $this->rs->CreateCatalogItem($dataset);
             } catch (Exception $e) {
                 fwrite(STDERR, 'Error: ' . $e->getMessage() . PHP_EOL);
             }
             break;
         case 'REPORT':
             fwrite(STDOUT, sprintf('Creating report: %s%s%s', $this->path->top(), $this->path->top() == self::ROOT ? '' : '/', $attrs['NAME']) . PHP_EOL);
             $report = new Rs\CreateCatalogItem();
             $report->ItemType = 'Report';
             $report->Name = $attrs['NAME'];
             $report->Parent = $this->path->top();
             $report->Overwrite = true;
             if (!is_readable($attrs['DEFINITION'])) {
                 throw new Exception("File not found: " . $attrs['DEFINITION']);
             }
             $report->Definition = file_get_contents($attrs['DEFINITION']);
             $report->Properties = [];
             try {
                 $response = $this->rs->CreateCatalogItem($report);
             } catch (Exception $e) {
                 fwrite(STDERR, 'Error: ' . $e->getMessage() . PHP_EOL);
             }
             // Set data source
             if (array_key_exists('DATASOURCEREF', $attrs)) {
                 $ref = new Rs\DataSourceReference();
                 $dsRef = $attrs['DATASOURCEREF'];
                 $rootRef = $this->path->bottom();
                 if ($rootRef != self::ROOT) {
                     $dsRef = $rootRef . $dsRef;
                 }
                 $ref->Reference = $dsRef;
                 fwrite(STDOUT, sprintf('    Linking data source: %s => %s', $attrs['DATASOURCEREFNAME'], $dsRef) . PHP_EOL);
                 $source = new Rs\DataSource();
                 $source->DataSourceReference = $ref;
                 $source->Name = $attrs['DATASOURCEREFNAME'];
                 $sources = [];
                 $sources[0] = $source;
                 $set = new Rs\SetItemDataSources();
                 $set->ItemPath = $this->path->top() . '/' . $report->Name;
                 $set->DataSources = $sources;
                 try {
                     $this->rs->SetItemDataSources($set);
                 } catch (Exception $e) {
                     fwrite(STDERR, 'Error: ' . $e->getMessage() . PHP_EOL);
                 }
             }
             $this->stack->push(array($this->path->top(), $name, $attrs));
             break;
         case 'ITEMREFERENCE':
             $itemRef = $attrs['REFERENCE'];
             $rootRef = $this->path->bottom();
             if ($rootRef != self::ROOT) {
                 $itemRef = $rootRef . $itemRef;
             }
             fwrite(STDOUT, sprintf('    Linking reference: %s => %s', $attrs['NAME'], $itemRef) . PHP_EOL);
             $itemReference = new Rs\ItemReference();
             $itemReference->Name = $attrs['NAME'];
             $itemReference->Reference = $itemRef;
             // Get the report we're in
             $report = $this->stack->top();
             $itemReferences = new Rs\SetItemReferences();
             $itemReferences->ItemPath = $report[0] . '/' . $report[2]['NAME'];
             // TODO: set all references in bulk!
             $itemReferences->ItemReferences = [$itemReference];
             try {
                 $response = $this->rs->SetItemReferences($itemReferences);
             } catch (Exception $e) {
                 fwrite(STDERR, 'Error: ' . $e->getMessage() . PHP_EOL);
             }
             break;
     }
 }