Niouzes

< Mai 2018 >
Lu Ma Me Je Ve Sa Di
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Citation

Attention

The documentation is incomplete. The Vae Soli! team works hard to make it as exhaustive as possible with tons of useful examples and easy to understand explanations.

On top of that, we have decided to use our own tool to generate the documentation you read. This also takes time to fine-tune. Our goal is have better documentation, easier to read, easier to use, completely integrated with our site.

Even though NOT finalized, you can now link back to our documentation pages as we have decided once and for all about the structure of our documents and where they all reside on our server.

Thank you very much
The Vae Soli! team.

2018-05-20 à 07:15:18

Table Of Contents

  1. FOUNDATION (functions) (01/04/2015)
  2. LSAction (class) (01/04/2015)
  3. LSAddress (class) (01/04/2015)
  4. LSAdministrativeArea (class) (01/04/2015)
  5. LSApplication (class) (14/10/2013)
  6. LSArray (class) (14/10/2013)
  7. LSArticle (class) (18/02/2014)
  8. LSAssertion (class) (14/10/2013)
  9. LSAudience (class) (18/02/2014)
  10. AUTOLOAD (function) (21/04/2014)
  11. LSAutoReference (class) (14/10/2013)
  12. LSBag (class) (14/10/2013)
  13. LSBBCodes (class) (10/06/2014)
  14. LSBrowser (class) (14/10/2013)
  15. LSCache (class) (14/10/2013)
  16. LSCalculator (class) (14/10/2013)
  17. LSCalendar (class) (14/10/2013)
  18. LSCameraSnapshot (class) (14/10/2013)
  19. LSCitation (class) (14/10/2013)
  20. LSClass (class) (14/10/2013)
  21. LSCode (class) ()
  22. Colors (functions) (20/05/2018)
  23. LSContactForm (class) (14/10/2013)
  24. LSContainer (class) (14/10/2013)
  25. LSContents (class) (14/10/2013)
  26. LSContentsAccounts (class) (14/10/2013)
  27. LSContentsArticles (class) (14/10/2013)
  28. LSContentsAtomicClock (class) (14/10/2013)
  29. LSContentsBusinessCoordinates (class) (14/10/2013)
  30. LSContentsBusinessOff (class) (14/10/2013)
  31. LSContentsBusinessOpeningHours (class) (14/10/2013)
  32. LSContentsBreadcrumb (class) (14/10/2013)
  33. LSContentsCalendar (class) (14/10/2013)
  34. LSContentsCatalogue (class) (14/10/2013)
  35. LSContentsCharter (class) (18/02/2014)
  36. LSContentsCitation (class) (14/10/2013)
  37. LSContentsClock (class) (14/10/2013)
  38. LSContentsComments (class) (14/10/2013)
  39. LSContentsCookieUsage (class) (14/10/2013)
  40. LSContentsCountdown (class) (14/10/2013)
  41. LSContentsDatetime (class) (14/10/2013)
  42. LSContentsHeartbeat (class) (14/10/2013)
  43. LSContentsIFrame (class) (14/10/2013)
  44. LSContentsImageGallery (class) (14/10/2013)
  45. LSContentsLanguageSwitchers (class) (14/10/2013)
  46. LSContentsLegal (class) (18/02/2014)
  47. LSContentsMicronews (class) (14/10/2013)
  48. LSContentsMyAccount (class) (14/10/2013)
  49. LSContentsPaymentOptions (class) (14/10/2013)
  50. LSContentsPinboard (class) (14/10/2013)
  51. LSContentsRememberPassword (class) (14/10/2013)
  52. LSContentsRSS (class) (14/10/2013)
  53. LSContentsSiteManager (class) (14/10/2013)
  54. LSContentsSitemap (class) (14/10/2013)
  55. LSContentsShare (class) (14/10/2013)
  56. LSContentsStopwatch (class) (14/10/2013)
  57. LSContentsTagCloud (class) (14/10/2013)
  58. LSContentsTodosOnPage (class) (14/10/2013)
  59. LSContentsW3C (class) (14/10/2013)
  60. LSContentsWeather (class) (14/10/2013)
  61. LSControl (class) (14/10/2013)
  62. LSCreativeWork (class) (18/02/2014)
  63. LSCursor (class) (09/03/2015)
  64. LSCustomer (class) (14/10/2013)
  65. LSDataEnvironment (class) (14/10/2013)
  66. Dates (functions) (01/04/2015)
  67. LSDate (class) (14/10/2013)
  68. LSDictionary (class) (14/10/2013)
  69. LSDom, LSDomNode and LSXPath (class) (30/04/2014)
  70. LSErrors and LSError (classes) (14/10/2013)
  71. LSException (class) (16/10/2013)
  72. LSExplorer (class) (14/10/2013)
  73. LSFieldset (class) (14/10/2013)
  74. LSFile (class) (14/10/2013)
  75. LSFileProperties (class) (14/10/2013)
  76. Files (functions) (01/04/2015)
  77. Finance (functions) (01/04/2015)
  78. LSFootnotes (class) (22/02/2014)
  79. LSForm (class) (09/06/2014)
  80. LSFunction (class) (14/10/2013)
  81. LSGeorama (class) (24/10/2013)
  82. LSGeoramaVar (class) (24/10/2013)
  83. LSGlossary (class) (09/03/2015)
  84. LSGroup (class) (14/10/2013)
  85. HTML (functions) (01/04/2015)
  86. LSHttp (class) (14/10/2013)
  87. HTTP (functions) (01/04/2015)
  88. LSImageGallery (class) (14/10/2013)
  89. Images (functions) (01/04/2015)
  90. LSInput (class) (26/04/2014)
  91. IP (functions) (01/04/2015)
  92. LSIslandAbstract (14/10/2013)
  93. LSIslandFormAbstract (class) (14/10/2013)
  94. LSLabel (class) (14/10/2013)
  95. LSLanguageSwitchers (class) (14/10/2013)
  96. LSLatin (class) (14/10/2013)
  97. LSLegalPerson (class) (14/10/2013)
  98. LSLinkedList (class) (14/10/2013)
  99. LSList (class) (14/10/2013)
  100. Mails (functions) (01/04/2015)
  101. LSMap (class) (14/10/2013)
  102. Math (functions) (01/04/2015)
  103. LSMicronews (class) (18/02/2014)
  104. Miscellaneous (functions) (01/04/2015)
  105. LSModuleAbstract (class) (14/10/2013)
  106. LSNaturalPerson (class) (14/10/2013)
  107. LSNewsArticle (class) (18/02/2014)
  108. LSNote (class) (14/10/2013)
  109. LSMotherNature (class) (16/10/2013)
  110. LSPage (class) (18/02/2014)
  111. LSParameter (class) (14/10/2013)
  112. LSPaymentOptions (class) (14/10/2013)
  113. LSPeopleAudience (class) (18/02/2014)
  114. LSPerson (class) (14/10/2013)
  115. LSPlace (class) (18/02/2014)
  116. LSProperty (class) (14/10/2013)
  117. LSPublication (class) (14/10/2013)
  118. LSRequirement (class) (14/10/2013)
  119. LSReturn (class) (24/10/2013)
  120. LSRisk (class) (14/10/2013)
  121. LSSentanaiAbstract (14/10/2013)
  122. LSServiceMessage (class) (14/10/2013)
  123. LSSession (class) (14/10/2013)
  124. LSSiteManager (class) (14/10/2013)
  125. LSSitemap (class) (14/10/2013)
  126. LSSockets (class) (14/10/2013)
  127. LSSoftwareApplication (class) (18/02/2014)
  128. LSSource (class) (14/10/2013)
  129. Strings (functions) (31/07/2016)
  130. LSSupplier (class) (14/10/2013)
  131. System (functions) (01/04/2015)
  132. LSTag (class) (21/04/2014)
  133. LSTagCloud (class) (14/10/2013)
  134. LSTechArticle (class) (18/02/2014)
  135. LSThing (class) (18/02/2014)
  136. LSTimeline (class) (14/10/2013)
  137. LSTimer (class) (16/10/2013)
  138. LSTracer (class) (09/03/2015)
  139. LSUnitTesting (class) (14/10/2013)
  140. URL (functions) (01/04/2015)
  141. LSUser (class) (09/03/2015)
  142. LSUserMgr (class) (14/10/2013)
  143. LSVaesoli (class) (09/06/2014)
  144. LSVersion (class) (14/10/2013)
  145. LSWebSite (class) (14/10/2013)
  146. LSWidget (class) (14/10/2013)
  147. LSWireTransferForm (class) (14/10/2013)
  148. LSXMLSitemap (class) (14/10/2013)
  149. XML (functions) (01/04/2015)

LSArray.class.php

Generated by The Vae Soli! Documentor: Guide v. 1.3.0015 on 14-10-2013 12:48:49 (DD-MM-YYYY HH:mm:SS). This documentation is built with Vae Soli! functions and classes!

File Properties

C:\websites\vaesoli.org\www\httpdocs/vaesoli/include/LSArray.class.phpC:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSArray.class.phpapplication/force-downloadC:\websites\vaesoli.org\www\httpdocs\vaesoli\include40085 bytes26/09/2013 16:45:3003/10/2013 10:01:2103/10/2013 10:01:21

Compliance

Assertions count: 39

Assertions successful: 39

Assertion failures: 0

Early Warning

LSArray.class.php contains 1105 lines of code, which exceeds the suggested limit of 1024 lines. We suggest this file got broken down in smaller chunks!

Manifest Constants

LS_ARRAY_CLASS_PWH: Define "LS" Array (Pat Was Here)

VAESOLI_PATH: Define the path where Vae Soli! is installed

VAESOLI_PLUGINS: Define the path where plugins are located

Sources required

LSUnitTesting.class.php: Vae Soli! Unit Testing

Classes

LSArrayThis class completely abstracts the array type of PHP, but it does it in such a way that only the most useful array operations are available via direct method calls. Therefore, this class is no substitute for the PHP array type but rather a sound simplification of the concept of array. The class itself is superclassed to many derived types such as LSList, LSLinkedList, LSStack, ...

Properties
NameVisibilityTypeDescription
$iPos public int Current position in the array
$xStore public array Internal array
Methods
  1. __construct(): Class constructor
  2. Count(): Counts the elements of the array
  3. current(): Returns the current element
  4. Get(): Gets one element of the array by its index
  5. InsertAfter(): Inserts $xItem after the element that is located at $iIndex
  6. InsertBefore(): Inserts $xItem before the element that is located at $iIndex
  7. key(): Returns the key of the current element
  8. next(): Moves forward to next element
  9. Pop(): Pops the last element off the end of the array
  10. Position(): Returns the current position in the array
  11. Prepend(): Prepend one element to the beginning of the array
  12. Push(): Pushes an element onto the array
  13. PushMany(): Pushes all the elements of $aItems as separated items
  14. Remove(): Removes the first element of the array
  15. RemoveAll(): Removes all items from the array
  16. RemoveFirst(): Removes the first element of the array
  17. RemoveLast(): Removes the last element of the array
  18. rewind(): Rewinds the array to the first element
  19. ThrowUp(): Returns a parsable string representation of the array
  20. valid(): Checks if current position is valid
__construct(): Class constructor

[ back to method list ]

Syntax

__construct()

Parameters

None

Return

(void)

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );

echo ( $szStr = $oArray->ThrowUp() );

echo LSUnitTesting::assert( strstr( $szStr,'\'xStore\'' ) && strstr( $szStr,'Hello' ),
                            'ASSERTION SUCCESS: array seems OK'                      ,
                            'ASSERTION FAILURE: array does not look good'            ,
                            'GuideAssert' );
echo LSUnitTesting::assert( $oArray->Count() === 2                   ,
                            'ASSERTION SUCCESS: array length OK'     ,
                            'ASSERTION FAILURE: invalid array length',
                            'GuideAssert' );

LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
    1 => 'World',
  ),
   'iPos' => -1,
))

GuideAssert() ... ASSERTION SUCCESS: array seems OK

GuideAssert() ... ASSERTION SUCCESS: array length OK

Unit Testing

2 assertions: 2 successful; 0 failed

Count(): Counts the elements of the array

[ back to method list ]

Syntax

Count()

Parameters

None

Return

(int) The number of elements in the array

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );

echo $oArray->Count();

echo LSUnitTesting::assert( $oArray->Count() === 2                   ,
                            'ASSERTION SUCCESS: array length OK'     ,
                            'ASSERTION FAILURE: invalid array length',
                            'GuideAssert' );

2

GuideAssert() ... ASSERTION SUCCESS: array length OK

Unit Testing

1 assertions: 1 successful; 0 failed

current(): Returns the current element

[ back to method list ]

Syntax

current()

Parameters

None

Return

(mixed)

Example Executed
$oArray = new LSArray();
echo LSUnitTesting::assert( is_null( $oArray->current() )                   ,
                            'ASSERTION SUCCESS: current position correct'   ,
                            'ASSERTION FAILURE: current position incorrect' ,
                            'GuideAssert' );

$oArray->PushMany( array( 'Monday','Tuesday','Wednesday','Thursday','Friday' ) );

echo '<ol>';
foreach( $oArray as $szKey => $szValue )
{
    echo "<li>Key = {$szKey}; Value = {$szValue}</li>";
}
echo '</ol>';

echo LSUnitTesting::assert( $oArray->Position() === 5                       ,
                            'ASSERTION SUCCESS: current position correct'   ,
                            'ASSERTION FAILURE: current position incorrect' ,
                            'GuideAssert' );
echo LSUnitTesting::assertFalse( $oArray->Valid()                   ,
                            'ASSERTION SUCCESS: invalid position'   ,
                            'ASSERTION FAILURE: valid position'     ,
                            'GuideAssert' );

GuideAssert() ... ASSERTION SUCCESS: current position correct

  1. Key = 0; Value = Monday
  2. Key = 1; Value = Tuesday
  3. Key = 2; Value = Wednesday
  4. Key = 3; Value = Thursday
  5. Key = 4; Value = Friday

GuideAssert() ... ASSERTION SUCCESS: current position correct

GuideAssert() ... ASSERTION SUCCESS: invalid position

Unit Testing

3 assertions: 3 successful; 0 failed

Get(): Gets one element of the array by its index

[ back to method list ]

Syntax

Get( $iIndex )

Parameters
NameTypeDescription
$iIndex int Index in the array
Return

(mixed) The element stored in the array at index $iIndex

Example(s)
$oArray = new LSArray();

$oArray->Push( 'Hello' );
$oArray->Push( 'World' );

echo '<p>',$oArray->Get( 1 ),'</p>';
echo '<p>',$oArray->Get( 2 ),'</p>';   // Generates a warning stating that element #2 is not defined
Example Executed
$oArray = new LSArray();

$oArray->Push( 'Hello' );
$oArray->Push( 'World' );

echo '<p>',$oArray->Get( 1 ),'</p>';
echo '<p>Elements in the array:',$oArray->Count(),'</p>';

echo LSUnitTesting::assert( $oArray->Get(0) === 'Hello'                         ,
                            'ASSERTION SUCCESS: element retrieved successfully' ,
                            'ASSERTION FAILURE: element retrieval failure'      ,
                            'GuideAssert' );
echo LSUnitTesting::assert( $oArray->Get(1) === 'World'                         ,
                            'ASSERTION SUCCESS: element retrieved successfully' ,
                            'ASSERTION FAILURE: element retrieval failure'      ,
                            'GuideAssert' );

World

Elements in the array:2

GuideAssert() ... ASSERTION SUCCESS: element retrieved successfully

GuideAssert() ... ASSERTION SUCCESS: element retrieved successfully

Unit Testing

2 assertions: 2 successful; 0 failed

InsertAfter(): Inserts $xItem after the element that is located at $iIndex

[ back to method list ]

Syntax

InsertAfter( $xItem,$iIndex )

Parameters
NameTypeDescription
$xItem mixed The element to be inserted
$iIndex int Position at which the item must be inserted
Return

(int) 0 ... $xItem prepended (start of array)
1 ... $xItem appended (end of array)
2 ... $xItem inserted in the middle of the array

Examples Executed
Example #1
$oPack1 = new LSArray();

$oPack1->PushMany( array( 'Banana','Orange','Pineapple' ) );

$oPack2 = new LSArray();

$oPack2->PushMany( array( 'Raspberry','Watermelon','Pear' ) );

echo $oPack1->ThrowUp();
echo $oPack2->ThrowUp();

$oPack1->InsertAfter( $oPack2,1 );
echo $oPack1;

echo LSUnitTesting::assert( $oPack1->Get( 2 ) === 'Raspberry'                       ,
                            'ASSERTION SUCCESS: Raspberry found at slot #3 (2)'     ,
                            'ASSERTION FAILURE: Raspberry NOT found at slot #3 (2)' ,
                            'GuideAssert' );

LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Banana',
    1 => 'Orange',
    2 => 'Pineapple',
  ),
   'iPos' => -1,
))LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Raspberry',
    1 => 'Watermelon',
    2 => 'Pear',
  ),
   'iPos' => -1,
))LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Banana',
    1 => 'Orange',
    2 => 'Raspberry',
    3 => 'Watermelon',
    4 => 'Pear',
    5 => 'Pineapple',
  ),
   'iPos' => -1,
))

GuideAssert() ... ASSERTION SUCCESS: Raspberry found at slot #3 (2)

Unit Testing

1 assertions: 1 successful; 0 failed

InsertBefore(): Inserts $xItem before the element that is located at $iIndex

[ back to method list ]

Syntax

InsertBefore( $xItem,$iIndex )

Parameters
NameTypeDescription
$xItem mixed The element to be inserted
$iIndex int Position at which the item must be inserted
Return

(int) 0 ... $xItem prepended (start of array)
1 ... $xItem appended (end of array)
2 ... $xItem inserted in the middle of the array

Examples Executed
Example #1
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );
$oArray->Push( "Bonjour" );
$oArray->Push( "Monde" );

echo $oArray->ThrowUp();

$oArray->InsertBefore( "NEW",3 );

echo $oArray->ThrowUp();

LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
    1 => 'World',
    2 => 'Bonjour',
    3 => 'Monde',
  ),
   'iPos' => -1,
))LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
    1 => 'World',
    2 => 'Bonjour',
    3 => 'NEW',
    4 => 'Monde',
  ),
   'iPos' => -1,
))
Example #2
// Let's build an array of WE days
$oWEDays = new LSArray();
$oWEDays->PushMany( array( 'Saturday','Sunday' ) );

// Let's build an array of Week days
$oWeekDays = new LSArray();
$oWeekDays->PushMany( array( 'Monday','Tuesday','Wednesday','Thursday','Friday' ) );

// Let's insert the week days BEFORE position 0 of WE days
$oWEDays->InsertBefore( $oWeekDays,0 );

// Let's see what it looks like
var_dump( $oWEDays );
//$oWEDays->ThrowUp();

echo LSUnitTesting::assert( $oWEDays->Get( 2 ) === 'Wednesday'                      ,
                            'ASSERTION SUCCESS: Wednesday found at slot #3 (2)'     ,
                            'ASSERTION FAILURE: Wednesday NOT found at slot #3 (2)' ,
                            'GuideAssert' );

echo LSUnitTesting::assert( $oWEDays instanceof LSArray         ,
                            'ASSERTION SUCCESS: proper type'    ,
                            'ASSERTION FAILURE: type is weird'  ,
                            'GuideAssert' );

object(LSArray)[1823]
  protected 'xStore' => 
    array (size=7)
      0 => string 'Monday' (length=6)
      1 => string 'Tuesday' (length=7)
      2 => string 'Wednesday' (length=9)
      3 => string 'Thursday' (length=8)
      4 => string 'Friday' (length=6)
      5 => string 'Saturday' (length=8)
      6 => string 'Sunday' (length=6)
  private 'iPos' => int -1

GuideAssert() ... ASSERTION SUCCESS: Wednesday found at slot #3 (2)

GuideAssert() ... ASSERTION SUCCESS: proper type

Unit Testing

2 assertions: 2 successful; 0 failed

key(): Returns the key of the current element

[ back to method list ]

Syntax

key()

Parameters

None

Return

(int) position of current element; null on failure.

Example Executed
$oArray = new LSArray();

$oArray->PushMany( array( 'Monday','Tuesday','Wednesday','Thursday','Friday' ) );

echo '<p>',$oArray->key(),'</p>';

$oArray->next();

echo '<p>',$oArray->key(),'</p>';
echo '<p>',$oArray->current(),'</p>';

echo LSUnitTesting::assert( $oArray->Get( $oArray->key() ) === 'Monday'                     ,
                            'ASSERTION SUCCESS: Monday found thanks to key()'               ,
                            'ASSERTION FAILURE: Monday cannot be retrieved thanks to key()' ,
                            'GuideAssert' );
echo LSUnitTesting::assert( $oArray->current() === 'Monday'                             ,
                            'ASSERTION SUCCESS: Monday found via current()'             ,
                            'ASSERTION FAILURE: Monday cannot be found via current()'   ,
                            'GuideAssert' );

-1

0

Monday

GuideAssert() ... ASSERTION SUCCESS: Monday found thanks to key()

GuideAssert() ... ASSERTION SUCCESS: Monday found via current()

Unit Testing

2 assertions: 2 successful; 0 failed

next(): Moves forward to next element

[ back to method list ]

Syntax

next()

Parameters

None

Return

(void)

Example Executed
$oArray = new LSArray();

$oArray->PushMany( array( 'Monday','Tuesday','Wednesday','Thursday','Friday' ) );

echo '<p>',$oArray->key(),'</p>';

echo LSUnitTesting::assert( is_null( $oArray->current() )                               ,
                            'ASSERTION SUCCESS: invalid position detected'              ,
                            'ASSERTION FAILURE: valid position ... which is incorrect'  ,
                            'GuideAssert' );

echo LSUnitTesting::assert( $oArray->Position() === -1                                  ,
                            'ASSERTION SUCCESS: invalid position detected'              ,
                            'ASSERTION FAILURE: valid position ... which is incorrect'  ,
                            'GuideAssert' );

$oArray->next();

echo '<p>',$oArray->key(),'</p>';
echo '<p>',$oArray->current(),'</p>';

echo LSUnitTesting::assert( $oArray->Position() === 0                           ,
                            'ASSERTION SUCCESS: position correctly detected'    ,
                            'ASSERTION FAILURE: position incorrectly detected'  ,
                            'GuideAssert' );

$oArray->next();

echo LSUnitTesting::assert( $oArray->Position() === 1                               ,
                            'ASSERTION SUCCESS: new position correctly detected'    ,
                            'ASSERTION FAILURE: new position incorrectly detected'  ,
                            'GuideAssert' );

-1

GuideAssert() ... ASSERTION SUCCESS: invalid position detected

GuideAssert() ... ASSERTION SUCCESS: invalid position detected

0

Monday

GuideAssert() ... ASSERTION SUCCESS: position correctly detected

GuideAssert() ... ASSERTION SUCCESS: new position correctly detected

Unit Testing

4 assertions: 4 successful; 0 failed

Pop(): Pops the last element off the end of the array

[ back to method list ]

Syntax

Pop()

Parameters

None

Return

(mixed) The last element of the array or null if array is empty

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );

echo '<p>Elements in the array:',$oArray->Count(),'</p>';

echo $oArray->Pop();
echo '<p>Elements in the array:',$oArray->Count(),'</p>';

echo LSUnitTesting::assert( $oArray->Count() === 1                   ,
                            'ASSERTION SUCCESS: array length OK'     ,
                            'ASSERTION FAILURE: invalid array length',
                            'GuideAssert' );

Elements in the array:2

World

Elements in the array:1

GuideAssert() ... ASSERTION SUCCESS: array length OK

Unit Testing

1 assertions: 1 successful; 0 failed

Position(): Returns the current position in the array

[ back to method list ]

Syntax

Position()

Parameters

None

Return

(int) The current position

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );

echo $oArray->ThrowUp();

$oArray->Prepend( "First" );

echo LSUnitTesting::assert( $oArray->Get(0) === 'First'             ,
                            'ASSERTION SUCCESS: expected element'   ,
                            'ASSERTION FAILURE: unexpected element' ,
                            'GuideAssert' );
echo LSUnitTesting::assert( $oArray->Get(1) === 'Hello'             ,
                            'ASSERTION SUCCESS: expected element'   ,
                            'ASSERTION FAILURE: unexpected element' ,
                            'GuideAssert' );
echo LSUnitTesting::assert( $oArray->Get(2) === 'World'             ,
                            'ASSERTION SUCCESS: expected element'   ,
                            'ASSERTION FAILURE: unexpected element' ,
                            'GuideAssert' );
echo LSUnitTesting::assert( $oArray->Position() === -1              ,
                            'ASSERTION SUCCESS: expected position'  ,
                            'ASSERTION FAILURE: unexpected position',
                            'GuideAssert' );
$oArray->next();
echo LSUnitTesting::assert( $oArray->Position() === 0              ,
                            'ASSERTION SUCCESS: expected position'  ,
                            'ASSERTION FAILURE: unexpected position',
                            'GuideAssert' );

LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
    1 => 'World',
  ),
   'iPos' => -1,
))

GuideAssert() ... ASSERTION SUCCESS: expected element

GuideAssert() ... ASSERTION SUCCESS: expected element

GuideAssert() ... ASSERTION SUCCESS: expected element

GuideAssert() ... ASSERTION SUCCESS: expected position

GuideAssert() ... ASSERTION SUCCESS: expected position

Unit Testing

5 assertions: 5 successful; 0 failed

Prepend(): Prepend one element to the beginning of the array

[ back to method list ]

Syntax

Prepend( $xItem )

Parameters
NameTypeDescription
$xItem mixed The element to be prepended
Return

(int) The count of items in the array

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );

echo $oArray->ThrowUp();

$oArray->Prepend( "First" );

echo $oArray->ThrowUp();

echo LSUnitTesting::assert( $oArray->Get(0) === 'First'                     ,
                            'ASSERTION SUCCESS: prepend correctly executed' ,
                            'ASSERTION FAILURE: prepend failure'            ,
                            'GuideAssert' );

LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
    1 => 'World',
  ),
   'iPos' => -1,
))LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'First',
    1 => 'Hello',
    2 => 'World',
  ),
   'iPos' => -1,
))

GuideAssert() ... ASSERTION SUCCESS: prepend correctly executed

Unit Testing

1 assertions: 1 successful; 0 failed

Push(): Pushes an element onto the array

[ back to method list ]

Syntax

Push( $xItem )

Alias

Append()

Parameters
NameTypeDescription
$xItem mixed The element to be put onto the array
Return

(int) The count of items pushed in the array

Example Executed
$oArray = new LSArray();

echo LSUnitTesting::assert( $oArray->Count() === 0                                  ,
                            'ASSERTION SUCCESS: elements successfully counted'      ,
                            'ASSERTION FAILURE: elements not counted successfully'  ,
                            'GuideAssert' );

$oArray->Push( "Hello" );

echo LSUnitTesting::assert( $oArray->Count() === 1                                  ,
                            'ASSERTION SUCCESS: elements successfully counted'      ,
                            'ASSERTION FAILURE: elements not counted successfully'  ,
                            'GuideAssert' );

$oArray->Push( "World" );

echo LSUnitTesting::assert( $oArray->Count() === 2                                  ,
                            'ASSERTION SUCCESS: elements successfully counted'      ,
                            'ASSERTION FAILURE: elements not counted successfully'  ,
                            'GuideAssert' );

$oArray->RemoveAll();

echo LSUnitTesting::assert( $oArray->Count() === 0                                  ,
                            'ASSERTION SUCCESS: elements successfully counted'      ,
                            'ASSERTION FAILURE: elements not counted successfully'  ,
                            'GuideAssert' );

GuideAssert() ... ASSERTION SUCCESS: elements successfully counted

GuideAssert() ... ASSERTION SUCCESS: elements successfully counted

GuideAssert() ... ASSERTION SUCCESS: elements successfully counted

GuideAssert() ... ASSERTION SUCCESS: elements successfully counted

Unit Testing

4 assertions: 4 successful; 0 failed

See Also

PushMany(), Pop()

PushMany(): Pushes all the elements of $aItems as separated items

[ back to method list ]

Syntax

PushMany( $aItems )

Parameters
NameTypeDescription
$aItems array An array whose elements must be pushed as individual elements
Return

(int) The count of items pushed in the array

Example Executed
$oArray = new LSArray();

echo '<p>Count:',$oArray->PushMany( array( 1,2,3,'Hello','World' ) ),'</p>';

echo $oArray->ThrowUp();

foreach( $oArray as $xItem )
{
    echo '<p>',$xItem,'</p>';
}

echo LSUnitTesting::assert( $oArray->Count() === 5                              ,
                            'ASSERTION SUCCESS: elements successfully counted'  ,
                            'ASSERTION FAILURE: elements wrongly counted'       ,
                            'GuideAssert' );

$oArray->PushMany( array( 1,2,3,array( 'a','b','c' ) ) );

echo LSUnitTesting::assert( $oArray->Count() === 9                              ,
                            'ASSERTION SUCCESS: elements successfully counted'  ,
                            'ASSERTION FAILURE: elements wrongly counted'       ,
                            'GuideAssert' );

Count:5

LSArray::__set_state(array( 'xStore' => array ( 0 => 1, 1 => 2, 2 => 3, 3 => 'Hello', 4 => 'World', ), 'iPos' => -1, ))

1

2

3

Hello

World

GuideAssert() ... ASSERTION SUCCESS: elements successfully counted

GuideAssert() ... ASSERTION SUCCESS: elements successfully counted

Unit Testing

2 assertions: 2 successful; 0 failed

See Also

Push(), Pop()

Remove(): Removes the first element of the array

[ back to method list ]

Syntax

Remove( $iIndex )

Parameters
NameTypeDescription
$iIndex int Index in the array
Return

(void)

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );
$oArray->Push( "Bonjour" );
$oArray->Push( "Monde" );

echo '<p>There are ',$oArray->Count(),' elements in the array</p>';
echo $oArray->ThrowUp();

echo $oArray->Remove( 2 );

echo $oArray->ThrowUp();

echo LSUnitTesting::assert( $oArray->Count() === 3                              ,
                            'ASSERTION SUCCESS: elements counted successfully'  ,
                            'ASSERTION FAILURE: elements wrongly counted'       ,
                            'GuideAssert' );

echo LSUnitTesting::assert( $oArray->Get(2) === 'Monde'                             ,
                            'ASSERTION SUCCESS: element #3 successfully retrieved'  ,
                            'ASSERTION FAILURE: element #3 is wrong'                ,
                            'GuideAssert' );

There are 4 elements in the array

LSArray::__set_state(array( 'xStore' => array ( 0 => 'Hello', 1 => 'World', 2 => 'Bonjour', 3 => 'Monde', ), 'iPos' => -1, ))LSArray::__set_state(array( 'xStore' => array ( 0 => 'Hello', 1 => 'World', 2 => 'Monde', ), 'iPos' => -1, ))

GuideAssert() ... ASSERTION SUCCESS: elements counted successfully

GuideAssert() ... ASSERTION SUCCESS: element #3 successfully retrieved

Unit Testing

2 assertions: 2 successful; 0 failed

RemoveAll(): Removes all items from the array

[ back to method list ]

Syntax

RemoveAll()

Alias

Clear()

Parameters

None

Return

(void)

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );
$oArray->Push( "Bonjour" );
$oArray->Push( "Monde" );

echo $oArray->ThrowUp();

$oArray->RemoveAll();

echo $oArray->ThrowUp();

echo LSUnitTesting::assert( $oArray->Count() === 0                   ,
                            'ASSERTION SUCCESS: array length OK'     ,
                            'ASSERTION FAILURE: invalid array length',
                            'GuideAssert' );

LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
    1 => 'World',
    2 => 'Bonjour',
    3 => 'Monde',
  ),
   'iPos' => -1,
))LSArray::__set_state(array(
   'xStore' => 
  array (
  ),
   'iPos' => -1,
))

GuideAssert() ... ASSERTION SUCCESS: array length OK

Unit Testing

1 assertions: 1 successful; 0 failed

RemoveFirst(): Removes the first element of the array

[ back to method list ]

Syntax

RemoveFirst()

Parameters

None

Return

(void)

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );

echo $oArray->ThrowUp();

echo $oArray->RemoveFirst();

echo $oArray->ThrowUp();

echo LSUnitTesting::assert( $oArray->Count() === 1                   ,
                            'ASSERTION SUCCESS: array length OK'     ,
                            'ASSERTION FAILURE: invalid array length',
                            'GuideAssert' );

LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
    1 => 'World',
  ),
   'iPos' => -1,
))LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'World',
  ),
   'iPos' => -1,
))

GuideAssert() ... ASSERTION SUCCESS: array length OK

Unit Testing

1 assertions: 1 successful; 0 failed

RemoveLast(): Removes the last element of the array

[ back to method list ]

Syntax

RemoveLast()

Parameters

None

Return

(void)

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( "World" );

echo $oArray->ThrowUp();

echo $oArray->RemoveLast();
echo $oArray->ThrowUp();

echo LSUnitTesting::assert( $oArray->Count() === 1                   ,
                            'ASSERTION SUCCESS: array length OK'     ,
                            'ASSERTION FAILURE: invalid array length',
                            'GuideAssert' );

LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
    1 => 'World',
  ),
   'iPos' => -1,
))LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
  ),
   'iPos' => -1,
))

GuideAssert() ... ASSERTION SUCCESS: array length OK

Unit Testing

1 assertions: 1 successful; 0 failed

rewind(): Rewinds the array to the first element

[ back to method list ]

Syntax

rewind()

Parameters

None

Return

(void)

Example Executed
$oArray = new LSArray();

$oArray->PushMany( array( 'Monday','Tuesday','Wednesday','Thursday','Friday' ) );

echo '<p>',$oArray->key(),'</p>';

$oArray->next();

echo '<p>',$oArray->key(),'</p>';
echo '<p>',$oArray->current(),'</p>';

$oArray->rewind();

echo '<p>',$oArray->key(),'</p>';
echo '<p>',$oArray->current(),'</p>';

echo LSUnitTesting::assert( $oArray->Position() === 0               ,
                            'ASSERTION SUCCESS: successful rewind'  ,
                            'ASSERTION FAILURE: rewind failure'     ,
                            'GuideAssert' );

-1

0

Monday

0

Monday

GuideAssert() ... ASSERTION SUCCESS: successful rewind

Unit Testing

1 assertions: 1 successful; 0 failed

ThrowUp(): Returns a parsable string representation of the array

[ back to method list ]

Syntax

ThrowUp()

Parameters

None

Return

(string) String representation of the array

Example Executed
$oArray = new LSArray();

$oArray->Push( "Hello" );
$oArray->Push( array( "Me","and","You" ) );

echo ( $szArray = $oArray->ThrowUp() );

echo LSUnitTesting::assert( strstr( $szArray,'LSArray::' ) && strstr( $szArray,'xStore' )       ,
                            'ASSERTION SUCCESS: seems to be a LSArray indeed'                   ,
                            'ASSERTION FAILURE: the thing does not seem to be what we expected' ,
                            'GuideAssert' );

LSArray::__set_state(array(
   'xStore' => 
  array (
    0 => 'Hello',
    1 => 
    array (
      0 => 'Me',
      1 => 'and',
      2 => 'You',
    ),
  ),
   'iPos' => -1,
))

GuideAssert() ... ASSERTION SUCCESS: seems to be a LSArray indeed

Unit Testing

1 assertions: 1 successful; 0 failed

valid(): Checks if current position is valid

[ back to method list ]

Syntax

valid()

Parameters

None

Return

(bool) Returns true on success or false on failure.

Example Executed
$oArray = new LSArray();

echo LSUnitTesting::assertFalse( $oArray->Valid()                                       ,
                            'ASSERTION SUCCESS: correct ... array visitor NO walk'      ,
                            'ASSERTION FAILURE: incorrect ... a visitor came already?'  ,
                            'GuideAssert' );

$oArray->PushMany( array( 'Monday','Tuesday','Wednesday','Thursday','Friday' ) );


for ( $i = 1;$i < 4;$i++ )
    $oArray->next();

echo '<p>Position: ',$oArray->key(),'</p>';

$oArray->next();

echo '<p>Position: ',$oArray->key(),'</p>';

$oArray->next();

echo '<p>Position: ',$oArray->key(),'</p>';
echo '<p>VALID? ',MISC_CastString( $oArray->valid() ),'</p>';

echo LSUnitTesting::assert( $oArray->Valid()                                                ,
                            'ASSERTION SUCCESS: correct ... visitor took a valid walk'      ,
                            'ASSERTION FAILURE: incorrect ... visitor walked off alleys'    ,
                            'GuideAssert' );

GuideAssert() ... ASSERTION SUCCESS: correct ... array visitor NO walk

Position: 2

Position: 3

Position: 4

VALID? true

GuideAssert() ... ASSERTION SUCCESS: correct ... visitor took a valid walk

Unit Testing

2 assertions: 2 successful; 0 failed

Précédent Suivant