Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PicaRecord
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dmj
PicaRecord
Commits
32bb0cfe
Commit
32bb0cfe
authored
13 years ago
by
David Maus
Browse files
Options
Downloads
Patches
Plain Diff
Record: New function getFirstMatchingField
Returns the first of all fields that are matched by a field selector.
parent
bb84e9e4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/php/HAB/Pica/Record/Record.php
+18
-0
18 additions, 0 deletions
src/php/HAB/Pica/Record/Record.php
src/tests/unit-tests/php/HAB/Pica/Record/RecordTest.php
+7
-0
7 additions, 0 deletions
src/tests/unit-tests/php/HAB/Pica/Record/RecordTest.php
with
25 additions
and
0 deletions
src/php/HAB/Pica/Record/Record.php
+
18
−
0
View file @
32bb0cfe
...
@@ -229,6 +229,24 @@ abstract class Record {
...
@@ -229,6 +229,24 @@ abstract class Record {
}
}
}
}
/**
* Return the first field that matches a selector.
*
* @see \HAB\Pica\Record\getFields()
*
* @param string $selector Body of regular expression
* @return \HAB\Pica\Record\Field|null The first matching field or NULL if
* no match
*/
public
function
getFirstMatchingField
(
$selector
)
{
$fields
=
$this
->
getFields
(
$selector
);
if
(
empty
(
$fields
))
{
return
null
;
}
else
{
return
reset
(
$fields
);
}
}
/**
/**
* Finalize the clone() operation.
* Finalize the clone() operation.
*
*
...
...
This diff is collapsed.
Click to expand it.
src/tests/unit-tests/php/HAB/Pica/Record/RecordTest.php
+
7
−
0
View file @
32bb0cfe
...
@@ -38,6 +38,13 @@ class RecordTest extends \PHPUnit_FrameWork_TestCase {
...
@@ -38,6 +38,13 @@ class RecordTest extends \PHPUnit_FrameWork_TestCase {
$this
->
assertInstanceOf
(
'HAB\Pica\Record\AuthorityRecord'
,
$record
);
$this
->
assertInstanceOf
(
'HAB\Pica\Record\AuthorityRecord'
,
$record
);
}
}
public
function
testGetFirstMatchingField
()
{
$record
=
new
AuthorityRecord
(
array
(
new
Field
(
'001@'
,
0
),
new
Field
(
'001@'
,
1
)));
$this
->
assertNull
(
$record
->
getFirstMatchingField
(
'002@/00'
));
$this
->
assertInstanceOf
(
'HAB\Pica\Record\Field'
,
$record
->
getFirstMatchingField
(
'001@'
));
}
///
///
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment