├── tests ├── bootstrap.php ├── Reader │ ├── source-examples │ │ ├── extended-dialplan.txt │ │ ├── simple-dialplan.txt │ │ ├── number-variant.txt │ │ └── advanced-dialplan.txt │ ├── ReaderFactoryTest.php │ ├── Application │ │ ├── NoOpReaderTest.php │ │ └── HasApplicationTraitTest.php │ └── ReaderTest.php ├── Application │ ├── WaitTest.php │ ├── RingingTest.php │ ├── HangupTest.php │ ├── EndWhileApplicationTest.php │ ├── GosubReturnTest.php │ ├── AnswerTest.php │ ├── RealtimeTest.php │ ├── ReadTest.php │ ├── SIPAddHeaderTest.php │ ├── SetTest.php │ ├── GoTest.php │ ├── MacroTest.php │ ├── StasisTest.php │ ├── AGITest.php │ ├── WaitExtenTest.php │ ├── WhileApplicationTest.php │ ├── UserEventTest.php │ ├── MinivmGreetTest.php │ ├── MinivmRecordTest.php │ ├── ExtenSpyTest.php │ ├── GosubTest.php │ ├── CELGenUserEventTest.php │ ├── RemoveQueueMemberTest.php │ ├── MinivmMWITest.php │ ├── AuthenticateTest.php │ ├── GotoIfTest.php │ ├── VoicemailTest.php │ ├── ChanSpyTest.php │ ├── BackGroundTest.php │ ├── PageTest.php │ ├── GosubIfTest.php │ ├── GotoIfTimeTest.php │ ├── DialTest.php │ ├── RecordTest.php │ ├── ExecIfTest.php │ ├── PickupTest.php │ ├── PlaybackTest.php │ ├── PickupChanTest.php │ └── AddQueueMemberTest.php ├── Line │ ├── CommentLineTest.php │ ├── IncludeLineTest.php │ └── HintLineTest.php └── Functions │ └── MinivmAccountTest.php ├── .gitignore ├── src └── Clearvox │ └── Asterisk │ └── Dialplan │ ├── Exception │ └── LineNotFoundAtPriorityException.php │ ├── Functions │ ├── StandardFunctionTrait.php │ ├── FunctionInterface.php │ ├── ExtenLineTest.php │ └── MinivmAccount.php │ ├── Application │ ├── StandardApplicationTrait.php │ ├── ApplicationInterface.php │ ├── Ringing.php │ ├── EndWhileApplication.php │ ├── Wait.php │ ├── GosubReturn.php │ ├── Hangup.php │ ├── SIPRemoveHeader.php │ ├── UndeterminedApplication.php │ ├── NoOp.php │ ├── WhileApplication.php │ ├── MinivmGreet.php │ ├── MinivmRecord.php │ ├── Macro.php │ ├── Answer.php │ ├── SIPAddHeader.php │ ├── AGI.php │ ├── Stasis.php │ ├── MinivmMWI.php │ ├── Realtime.php │ ├── GosubIf.php │ ├── PickupChan.php │ ├── Go.php │ ├── GotoIf.php │ ├── CELGenUserEvent.php │ ├── Set.php │ ├── RemoveQueueMember.php │ ├── WaitExten.php │ ├── Pickup.php │ ├── ExecIf.php │ ├── UserEvent.php │ ├── Gosub.php │ ├── Page.php │ ├── Voicemail.php │ ├── Playback.php │ ├── GotoIfTime.php │ ├── Authenticate.php │ ├── Dial.php │ ├── Record.php │ └── AddQueueMember.php │ ├── Reader │ ├── Line │ │ ├── LineReaderInterface.php │ │ └── ExtenLineReader.php │ ├── Application │ │ ├── ApplicationReaderInterface.php │ │ ├── NoOpReader.php │ │ └── HasApplicationTrait.php │ ├── ReaderFactory.php │ └── Reader.php │ └── Line │ ├── LineInterface.php │ ├── CommentLine.php │ ├── IncludeLine.php │ ├── HintLine.php │ └── ExtenLine.php ├── phpunit.xml ├── .github ├── dependabot.yml └── workflows │ └── run_tests.yml ├── composer.json └── README.md /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | s,1,NoOp(Hello) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .gitignore support plugin (hsz.mobi) 2 | composer.lock 3 | composer.phar 4 | vendor 5 | .idea 6 | php5 -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Exception/LineNotFoundAtPriorityException.php: -------------------------------------------------------------------------------- 1 | s,1,NoOp(No Action taken here) 3 | exten => s,2,NoOp(Second line no action) 4 | exten => s,3,NoOp(3rd numbered line no action) 5 | -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Functions/StandardFunctionTrait.php: -------------------------------------------------------------------------------- 1 | toString(); 9 | } 10 | } -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tests/ 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/StandardApplicationTrait.php: -------------------------------------------------------------------------------- 1 | getName() . '(' . $this->getData() . ')'; 9 | } 10 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Functions/FunctionInterface.php: -------------------------------------------------------------------------------- 1 | assertEquals('Wait(30)', $wait->toString()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/Application/RingingTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('Ringing()', $ringing->toString()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/Line/CommentLineTest.php: -------------------------------------------------------------------------------- 1 | assertEquals("; Example Comment", $comment->toString()); 15 | } 16 | } -------------------------------------------------------------------------------- /tests/Reader/source-examples/number-variant.txt: -------------------------------------------------------------------------------- 1 | [number_incoming] 2 | exten => 012345678,1,Gosub(language_tts,s,${ACCOUNT_LANGUAGE}-tts-number-not-attached) 3 | exten => 3112345678,1,Gosub(language_tts,s,${ACCOUNT_LANGUAGE}-tts-number-not-attached) 4 | exten => +3112345678,1,Gosub(language_tts,s,${ACCOUNT_LANGUAGE}-tts-number-not-attached) 5 | exten => 003112345678,1,Gosub(language_tts,s,${ACCOUNT_LANGUAGE}-tts-number-not-attached) -------------------------------------------------------------------------------- /tests/Line/IncludeLineTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('include => testing_context', $includeLine->toString()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/Reader/ReaderFactoryTest.php: -------------------------------------------------------------------------------- 1 | create(); 15 | 16 | $this->assertInstanceOf(Reader::class, $reader); 17 | } 18 | } -------------------------------------------------------------------------------- /tests/Application/HangupTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('Hangup()', $hangup->toString()); 14 | } 15 | 16 | public function testWithCauseToString() 17 | { 18 | $hangup = new Hangup(300); 19 | $this->assertEquals('Hangup(300)', $hangup->toString()); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/Application/EndWhileApplicationTest.php: -------------------------------------------------------------------------------- 1 | endWhile = new EndWhileApplication(); 16 | } 17 | 18 | public function testGetName() 19 | { 20 | $this->assertEquals('EndWhile', $this->endWhile->getName()); 21 | } 22 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "composer" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Reader/Line/LineReaderInterface.php: -------------------------------------------------------------------------------- 1 | assertEquals('Return', $return->getName()); 14 | } 15 | 16 | public function testGetDataEmpty() 17 | { 18 | $return = new GosubReturn(); 19 | $this->assertEquals('', $return->getData()); 20 | } 21 | 22 | public function testGetData() 23 | { 24 | $return = new GosubReturn('PASSED'); 25 | $this->assertEquals('PASSED', $return->getData()); 26 | } 27 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "clearvox/asterisk-dialplan", 3 | "description": "A PHP Asterisk DialPlan Library", 4 | "version": "3.0.0", 5 | "minimum-stability": "dev", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Leon Rowland", 10 | "email": "leon@rowland.nl" 11 | }, 12 | { 13 | "name": "Yme-Jan Iedema", 14 | "email": "yme-jan@clearvox.nl" 15 | } 16 | ], 17 | "autoload": { 18 | "psr-0": { 19 | "Clearvox\\Asterisk\\Dialplan": "src" 20 | } 21 | }, 22 | "require": { 23 | "php": "^8.0" 24 | }, 25 | "require-dev": { 26 | "phpunit/phpunit": "^8.0" 27 | }, 28 | "scripts": { 29 | "test": "phpunit" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Application/AnswerTest.php: -------------------------------------------------------------------------------- 1 | answer = new Answer(100); 18 | } 19 | 20 | public function testGetNameIsCorrect() 21 | { 22 | $this->assertEquals('Answer', $this->answer->getName()); 23 | } 24 | 25 | public function testGetDelayIsCorrect() 26 | { 27 | $this->assertEquals(100, $this->answer->getDelay()); 28 | } 29 | 30 | public function testGetDataIsCorrect() 31 | { 32 | $this->assertEquals(100, $this->answer->getData()); 33 | } 34 | } -------------------------------------------------------------------------------- /.github/workflows/run_tests.yml: -------------------------------------------------------------------------------- 1 | name: Run PHP Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - master # Run tests when code is pushed to master (e.g., after merging a PR) 7 | pull_request: # Run tests on new PRs to catch issues before merging 8 | 9 | jobs: 10 | tests: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v4 16 | 17 | - name: Setup PHP 18 | uses: shivammathur/setup-php@v2 19 | with: 20 | php-version: '8.0' 21 | coverage: none # Disable Xdebug for faster execution 22 | tools: composer 23 | 24 | - name: Install dependencies 25 | run: composer install --no-progress --no-suggest --prefer-dist 26 | 27 | - name: Run tests 28 | run: composer test 29 | -------------------------------------------------------------------------------- /tests/Application/RealtimeTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('Realtime', $realtime->getName()); 15 | } 16 | 17 | public function testJustContext() 18 | { 19 | $realtime = new Realtime('my_context'); 20 | 21 | $this->assertEquals('Realtime/my_context@', $realtime->toString()); 22 | } 23 | 24 | public function testContextAndFamily() 25 | { 26 | $realtime = new Realtime('my_context', 'extens'); 27 | 28 | $this->assertEquals('Realtime/my_context@extens', $realtime->toString()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Line/LineInterface.php: -------------------------------------------------------------------------------- 1 | read = new Read('TESTING'); 18 | } 19 | 20 | public function testGetNameIsCorrect() 21 | { 22 | $this->assertEquals('Read', $this->read->getName()); 23 | } 24 | 25 | public function testGetDataIsCorrect() 26 | { 27 | // No extra data 28 | $this->assertEquals('TESTING', $this->read->getData()); 29 | 30 | $this->read->addFilename('vm-password'); 31 | $this->assertEquals('TESTING,vm-password', $this->read->getData()); 32 | 33 | $this->read->setTimeout(5); 34 | $this->assertEquals('TESTING,vm-password,,,,5', $this->read->getData()); 35 | } 36 | } -------------------------------------------------------------------------------- /tests/Application/SIPAddHeaderTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('SIPAddHeader', $sipAddHeader->getName()); 16 | } 17 | 18 | public function testArguments() 19 | { 20 | $sipAddHeader = new SIPAddHeader('Alert-Info', '\;info=alert-autoanswer'); 21 | 22 | $this->assertEquals('Alert-Info: \;info=alert-autoanswer', $sipAddHeader->getData()); 23 | } 24 | 25 | public function testToString() 26 | { 27 | $sipAddHeader = new SIPAddHeader('Alert-Info', '\;info=alert-autoanswer'); 28 | 29 | $this->assertEquals('SIPAddHeader(Alert-Info: \;info=alert-autoanswer)', $sipAddHeader->toString()); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/ApplicationInterface.php: -------------------------------------------------------------------------------- 1 | assertEquals('Set', $set->getName()); 14 | } 15 | 16 | public function testSimpleVariableSet() 17 | { 18 | $set = new Set('VARIABLENAME', '12345'); 19 | $this->assertEquals('VARIABLENAME=12345', $set->getData()); 20 | } 21 | 22 | public function testInheritVariable() 23 | { 24 | $set = new Set('VARIABLENAME', '123456'); 25 | $set->inherit(); 26 | 27 | $this->assertEquals('_VARIABLENAME=123456', $set->getData()); 28 | } 29 | 30 | public function testInheritChildVariable() 31 | { 32 | $set = new Set('VARIABLENAME', '54321'); 33 | $set->inheritChildren(); 34 | 35 | $this->assertEquals('__VARIABLENAME=54321', $set->getData()); 36 | } 37 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Reader/ReaderFactory.php: -------------------------------------------------------------------------------- 1 | applications[] = new NoOpReader(); 24 | $this->lines[] = new ExtenLineReader($this->applications); 25 | } 26 | 27 | /** 28 | * Create an instance of reader with all the known line readers and 29 | * application readers. 30 | * 31 | * @return Reader 32 | */ 33 | public function create() 34 | { 35 | return new Reader($this->lines); 36 | } 37 | } -------------------------------------------------------------------------------- /tests/Application/GoTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('Goto', $goto->getName()); 14 | } 15 | 16 | public function testJustPriorityData() 17 | { 18 | $goto = new Go(1); 19 | $this->assertEquals('1', $goto->getData()); 20 | } 21 | 22 | public function testPriorityAndExtensionsData() 23 | { 24 | $goto = new Go(1,100); 25 | $this->assertEquals('100,1', $goto->getData()); 26 | } 27 | 28 | public function testPriorityExtensionAndContextData() 29 | { 30 | $goto = new Go(1,100,'telephones'); 31 | $this->assertEquals('telephones,100,1', $goto->getData()); 32 | } 33 | 34 | public function testString() 35 | { 36 | $goto = new Go(1,'${EXTEN}', 'telephones'); 37 | $this->assertEquals('Goto(telephones,${EXTEN},1)', $goto->toString()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Asterisk Dialplan PHP 2 | [![Build Status](https://travis-ci.org/clearvox/asterisk-dialplan-php.svg?branch=master)](https://travis-ci.org/clearvox/asterisk-dialplan-php) 3 | 4 | Simplify your Dialplan building in a clean OOP, tested way. 5 | 6 | # Installation 7 | 8 | Install the latest version with: 9 | 10 | ```bash 11 | composer require clearvox/asterisk-dialplan 12 | ``` 13 | 14 | # Requirements 15 | 16 | * PHP 5.4 is required but using the latest version of PHP is highly recommended. 17 | 18 | # Documentation 19 | 20 | Read the full documentation on the wiki found [https://github.com/clearvox/asterisk-dialplan-php/wiki](https://github.com/clearvox/asterisk-dialplan-php/wiki) 21 | 22 | # Contributing 23 | 24 | Wish to contribute? Check the small guide on the Wiki. 25 | [https://github.com/clearvox/asterisk-dialplan-php/wiki/Contributing](https://github.com/clearvox/asterisk-dialplan-php/wiki/Contributing) 26 | 27 | # License 28 | 29 | This package is licensed under LGPL. You are free to use it in personal and commercial projects. The code can be forked and modified, but the original copyright author should always be included! 30 | -------------------------------------------------------------------------------- /tests/Application/MacroTest.php: -------------------------------------------------------------------------------- 1 | macro = new Macro('Testing'); 18 | } 19 | 20 | public function testGetNameIsCorrect() 21 | { 22 | $this->assertEquals('Macro', $this->macro->getName()); 23 | } 24 | 25 | public function testGetMacroNameIsCorrect() 26 | { 27 | $this->assertEquals('Testing', $this->macro->getMacroName()); 28 | } 29 | 30 | public function testGetDataWithNoArguments() 31 | { 32 | $this->assertEquals('Testing', $this->macro->getData()); 33 | } 34 | 35 | public function testGetDataWithArguments() 36 | { 37 | $this->macro 38 | ->addArgument('1234') 39 | ->addArgument('5678') 40 | ->addArgument('90AB'); 41 | 42 | $this->assertEquals('Testing,1234,5678,90AB', $this->macro->getData()); 43 | } 44 | } -------------------------------------------------------------------------------- /tests/Application/StasisTest.php: -------------------------------------------------------------------------------- 1 | stasis = new Stasis('authentication'); 18 | } 19 | 20 | public function testGetNameIsCorrect() 21 | { 22 | $this->assertEquals('Stasis', $this->stasis->getName()); 23 | } 24 | 25 | public function testGetCommandIsCorrect() 26 | { 27 | $this->assertEquals('authentication', $this->stasis->getCommand()); 28 | } 29 | 30 | public function testGetDataWithNoArguments() 31 | { 32 | $this->assertEquals('authentication', $this->stasis->getData()); 33 | } 34 | 35 | public function testGetDataWithArguments() 36 | { 37 | $this->stasis 38 | ->addArgument('12345') 39 | ->addArgument('abcde'); 40 | 41 | $this->assertEquals('authentication,12345,abcde', $this->stasis->getData()); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Ringing.php: -------------------------------------------------------------------------------- 1 | toArray(), $options); 48 | } 49 | } -------------------------------------------------------------------------------- /tests/Application/AGITest.php: -------------------------------------------------------------------------------- 1 | agi = new AGI('agi://127.0.0.7:6565/exampleScript'); 18 | } 19 | 20 | public function testGetNameIsCorrect() 21 | { 22 | $this->assertEquals('AGI', $this->agi->getName()); 23 | } 24 | 25 | public function testGetCommandIsCorrect() 26 | { 27 | $this->assertEquals('agi://127.0.0.7:6565/exampleScript', $this->agi->getCommand()); 28 | } 29 | 30 | public function testGetDataWithNoArguments() 31 | { 32 | $this->assertEquals('agi://127.0.0.7:6565/exampleScript', $this->agi->getData()); 33 | } 34 | 35 | public function testGetDataWithArguments() 36 | { 37 | $this->agi 38 | ->addArgument('12345') 39 | ->addArgument('abcde'); 40 | 41 | $this->assertEquals('agi://127.0.0.7:6565/exampleScript,12345,abcde', $this->agi->getData()); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/EndWhileApplication.php: -------------------------------------------------------------------------------- 1 | toArray(), $options); 48 | } 49 | 50 | 51 | } -------------------------------------------------------------------------------- /tests/Application/WaitExtenTest.php: -------------------------------------------------------------------------------- 1 | waitExten = new WaitExten(); 18 | } 19 | 20 | public function testName() 21 | { 22 | $this->assertEquals('WaitExten', $this->waitExten->getName()); 23 | } 24 | 25 | public function testWithWaitTime() 26 | { 27 | $this->waitExten->setSeconds(45); 28 | 29 | $this->assertEquals('WaitExten(45)', $this->waitExten->toString()); 30 | } 31 | 32 | public function testWithOptions() 33 | { 34 | $this->waitExten->setOptions(['m(default)']); 35 | $this->assertEquals('WaitExten(,m(default))', $this->waitExten->toString()); 36 | } 37 | 38 | public function testWithWaitTimeAndOptions() 39 | { 40 | $this->waitExten->setSeconds(45); 41 | $this->waitExten->setOptions(['m(default)']); 42 | $this->assertEquals('WaitExten(45,m(default))', $this->waitExten->toString()); 43 | } 44 | } -------------------------------------------------------------------------------- /tests/Application/WhileApplicationTest.php: -------------------------------------------------------------------------------- 1 | while = new WhileApplication('$[1=1]'); 18 | } 19 | 20 | public function testGetName() 21 | { 22 | $this->assertEquals('While', $this->while->getName()); 23 | } 24 | 25 | public function testGetExpression() 26 | { 27 | $this->assertEquals('$[1=1]', $this->while->getExpression()); 28 | } 29 | 30 | public function testGetData() 31 | { 32 | $this->assertEquals('$[1=1]', $this->while->getData()); 33 | } 34 | 35 | public function testToArray() 36 | { 37 | $expected = ['expression' => '$[1=1]']; 38 | 39 | $this->assertEquals($expected, $this->while->toArray()); 40 | } 41 | 42 | public function testToJson() 43 | { 44 | $expected = json_encode(['expression' => '$[1=1]']); 45 | $this->assertEquals($expected, $this->while->toJson()); 46 | } 47 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Reader/Application/HasApplicationTrait.php: -------------------------------------------------------------------------------- 1 | getMatchFormat(), $applicationRaw, $matches)) { 20 | return $application->getInstance($matches); 21 | } 22 | } 23 | 24 | // Standard expectation 25 | $format = "/([A-Za-z]+)\((.+)\)/"; 26 | $matches = []; 27 | 28 | preg_match($format, $applicationRaw, $matches); 29 | 30 | $name = (isset($matches[1]) ? $matches[1] : $matches); 31 | $data = (isset($matches[2]) ? $matches[2] : $applicationRaw); 32 | 33 | return new UndeterminedApplication($name, $data); 34 | } 35 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Line/CommentLine.php: -------------------------------------------------------------------------------- 1 | comment = $comment; 13 | } 14 | 15 | /** 16 | * Get the pattern for this line. There is no guarantee that 17 | * the response string wouldn't be empty. 18 | */ 19 | public function getPattern(): string 20 | { 21 | return ''; 22 | } 23 | 24 | /** 25 | * Get the priority for this line. There is no guarantee that 26 | * the response string wouldn't be empty. 27 | */ 28 | public function getPriority(): ?string 29 | { 30 | return null; 31 | } 32 | 33 | /** 34 | * Get the application associated with this line. 35 | */ 36 | public function getApplication(): ?ApplicationInterface 37 | { 38 | return null; 39 | } 40 | 41 | /** 42 | * Turn this implemented Line into a string representation. 43 | */ 44 | public function toString(): string 45 | { 46 | return "; $this->comment"; 47 | } 48 | } -------------------------------------------------------------------------------- /tests/Application/UserEventTest.php: -------------------------------------------------------------------------------- 1 | userEvent = new UserEvent('TestingEvent'); 18 | } 19 | 20 | public function testGetNameIsCorrect() 21 | { 22 | $this->assertEquals('UserEvent', $this->userEvent->getName()); 23 | } 24 | 25 | public function testGetDataWithoutBody() 26 | { 27 | $this->assertEquals('TestingEvent', $this->userEvent->getData()); 28 | } 29 | 30 | public function testGetDataWith1Body() 31 | { 32 | $this->userEvent->addBodyPart('Body', 'Value'); 33 | 34 | $this->assertEquals('TestingEvent,Body: Value', $this->userEvent->getData()); 35 | } 36 | 37 | public function testGetDataWithMultipleBody() 38 | { 39 | $this->userEvent 40 | ->addBodyPart('Part1', 'Part1Value') 41 | ->addBodyPart('Part2', 'Part2Value') 42 | ->addBodyPart('Part3', 'Part3Value'); 43 | 44 | $this->assertEquals('TestingEvent,Part1: Part1Value,Part2: Part2Value,Part3: Part3Value', $this->userEvent->getData()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Line/IncludeLine.php: -------------------------------------------------------------------------------- 1 | context = $context; 16 | } 17 | 18 | /** 19 | * Get the pattern for this line. There is no guarantee that 20 | * the response string wouldn't be empty. 21 | */ 22 | public function getPattern(): ?string 23 | { 24 | return ''; 25 | } 26 | 27 | /** 28 | * Get the priority for this line. There is no guarantee that 29 | * the response string wouldn't be empty. 30 | */ 31 | public function getPriority(): ?string 32 | { 33 | return ''; 34 | } 35 | 36 | /** 37 | * Get the application associated with this line. 38 | * 39 | * @return ApplicationInterface 40 | */ 41 | public function getApplication(): ?ApplicationInterface 42 | { 43 | return null; 44 | } 45 | 46 | /** 47 | * Turn this implemented Line into a string representation. 48 | */ 49 | public function toString(): string 50 | { 51 | return 'include => ' . $this->context; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /tests/Reader/Application/NoOpReaderTest.php: -------------------------------------------------------------------------------- 1 | getMatchFormat(); 19 | 20 | $lineOneMatches = []; 21 | $lineOneResponse = preg_match($pattern, $lineOne, $lineOneMatches); 22 | 23 | $lineOneApplication = $noOpReader->getInstance($lineOneMatches); 24 | 25 | $this->assertEquals(1, $lineOneResponse); 26 | $this->assertInstanceOf(NoOp::class, $lineOneApplication); 27 | $this->assertEquals('Testing hello world', $lineOneApplication->getText()); 28 | 29 | 30 | $lineTwoMatches = []; 31 | $lineTwoResponse = preg_match($pattern, $lineTwo, $lineTwoMatches); 32 | 33 | $lineTwoApplication = $noOpReader->getInstance($lineTwoMatches); 34 | 35 | $this->assertEquals(1, $lineTwoResponse); 36 | $this->assertInstanceOf(NoOp::class, $lineTwoApplication); 37 | $this->assertEquals('SingleWord', $lineTwoApplication->getText()); 38 | } 39 | } -------------------------------------------------------------------------------- /tests/Application/MinivmGreetTest.php: -------------------------------------------------------------------------------- 1 | minivmGreet = new MinivmGreet('example@test.com', ['s']); 18 | } 19 | 20 | public function testGetName() 21 | { 22 | $this->assertEquals('MinivmGreet', $this->minivmGreet->getName()); 23 | } 24 | 25 | public function testGetOptions() 26 | { 27 | $expected = ['s']; 28 | $this->assertEquals($expected, $this->minivmGreet->getOptions()); 29 | } 30 | 31 | public function testGetData() 32 | { 33 | $expected = 'example@test.com,s'; 34 | $this->assertEquals($expected, $this->minivmGreet->getData()); 35 | } 36 | 37 | public function testToArray() 38 | { 39 | $expected = ['account' => 'example@test.com', 'options' => ['s']]; 40 | $this->assertEquals($expected, $this->minivmGreet->toArray()); 41 | } 42 | 43 | public function testToJson() 44 | { 45 | $expected = json_encode(['account' => 'example@test.com', 'options' => ['s']]); 46 | $this->assertEquals($expected, $this->minivmGreet->toJson()); 47 | } 48 | } -------------------------------------------------------------------------------- /tests/Application/MinivmRecordTest.php: -------------------------------------------------------------------------------- 1 | minivmRecord = new MinivmRecord('example@host.com', ['0']); 18 | } 19 | 20 | public function testGetName() 21 | { 22 | $this->assertEquals('MinivmRecord', $this->minivmRecord->getName()); 23 | } 24 | 25 | public function testGetOptions() 26 | { 27 | $expected = ['0']; 28 | $this->assertEquals($expected, $this->minivmRecord->getOptions()); 29 | } 30 | 31 | public function testGetData() 32 | { 33 | $expected = 'example@host.com,0'; 34 | $this->assertEquals($expected, $this->minivmRecord->getData()); 35 | } 36 | 37 | public function testToArray() 38 | { 39 | $expected = ['account' => 'example@host.com', 'options' => ['0']]; 40 | $this->assertEquals($expected, $this->minivmRecord->toArray()); 41 | } 42 | 43 | public function testToJson() 44 | { 45 | $expected = json_encode(['account' => 'example@host.com', 'options' => ['0']]); 46 | $this->assertEquals($expected, $this->minivmRecord->toJson()); 47 | } 48 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Functions/ExtenLineTest.php: -------------------------------------------------------------------------------- 1 | createMock(ApplicationInterface::class); 14 | 15 | $application 16 | ->expects($this->once()) 17 | ->method('toString') 18 | ->willReturn('Dial(SIP/100)'); 19 | 20 | $extenLine = new ExtenLine('_XXX', 1, $application); 21 | 22 | $this->assertEquals( 23 | 'exten => _XXX,1,Dial(SIP/100)', 24 | $extenLine->toString() 25 | ); 26 | } 27 | 28 | public function testCorrectStringReturnWithLabel() 29 | { 30 | $application = $this->createMock(ApplicationInterface::class); 31 | 32 | $application 33 | ->expects($this->once()) 34 | ->method('toString') 35 | ->willReturn('Dial(SIP/100)'); 36 | 37 | $extenLine = new ExtenLine('_XXX', 1, $application); 38 | $extenLine->setLabel('starting'); 39 | 40 | $this->assertEquals( 41 | 'exten => _XXX,1(starting),Dial(SIP/100)', 42 | $extenLine->toString() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/Application/ExtenSpyTest.php: -------------------------------------------------------------------------------- 1 | extenSpy = new ExtenSpy('100'); 18 | } 19 | 20 | public function testGetNameIsCorrect() 21 | { 22 | $this->assertEquals('ExtenSpy', $this->extenSpy->getName()); 23 | } 24 | 25 | public function testSetGetOptions() 26 | { 27 | $options = ['b', 'c(5)', 'e(101:102)']; 28 | $this->extenSpy->setOptions($options); 29 | $this->assertEquals($options, $this->extenSpy->getOptions()); 30 | 31 | $extenSpy = new ExtenSpy('100', $options); 32 | $this->assertEquals($options, $extenSpy->getOptions()); 33 | } 34 | 35 | public function testGetDataOptions() 36 | { 37 | $options = ['b', 'c(5)', 'e(101:102)']; 38 | $this->extenSpy->setOptions($options); 39 | $this->assertEquals('100,bc(5)e(101:102)', $this->extenSpy->getData()); 40 | } 41 | 42 | public function testString() 43 | { 44 | $this->assertEquals('ExtenSpy(100)', $this->extenSpy->toString()); 45 | 46 | $this->extenSpy 47 | ->setOptions(['b', 'c(5)', 'x(1)']); 48 | 49 | $this->assertEquals('ExtenSpy(100,bc(5)x(1))', $this->extenSpy->toString()); 50 | } 51 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Wait.php: -------------------------------------------------------------------------------- 1 | seconds = $seconds; 16 | } 17 | 18 | /** 19 | * @return int 20 | */ 21 | public function getSeconds() 22 | { 23 | return $this->seconds; 24 | } 25 | 26 | /** 27 | * Should return the name of the application 28 | * 29 | * @return string 30 | */ 31 | public function getName() 32 | { 33 | return 'Wait'; 34 | } 35 | 36 | /** 37 | * Should return the AppData. AppData is the string contents 38 | * between the () of the App. 39 | * 40 | * @return string 41 | */ 42 | public function getData() 43 | { 44 | return $this->seconds; 45 | } 46 | 47 | /** 48 | * Turns this application into an Array 49 | * 50 | * @return array 51 | */ 52 | public function toArray() 53 | { 54 | return array( 55 | 'seconds' => $this->seconds 56 | ); 57 | } 58 | 59 | /** 60 | * Turns this Application into a json representation 61 | * 62 | * @param int $options 63 | * @return string 64 | */ 65 | public function toJson($options = 0) 66 | { 67 | return json_encode($this->toArray(), $options); 68 | } 69 | } -------------------------------------------------------------------------------- /tests/Line/HintLineTest.php: -------------------------------------------------------------------------------- 1 | hintLine = new HintLine('100'); 18 | } 19 | 20 | public function testGetPattern() 21 | { 22 | $this->assertEquals('100', $this->hintLine->getPattern()); 23 | } 24 | 25 | public function testGetPriority() 26 | { 27 | $this->assertEquals('hint', $this->hintLine->getPriority()); 28 | } 29 | 30 | public function testGetPeers() 31 | { 32 | $this->hintLine 33 | ->addPeer('SIP/100') 34 | ->addPeer('SIP/200'); 35 | 36 | $this->assertEquals(['SIP/100', 'SIP/200'], $this->hintLine->getPeers()); 37 | } 38 | 39 | public function testToStringOnePeer() 40 | { 41 | $this->hintLine 42 | ->addPeer('SIP/100'); 43 | 44 | $expected = "exten => 100,hint,SIP/100"; 45 | $this->assertEquals($expected, $this->hintLine->toString()); 46 | } 47 | 48 | public function testToStringManyPeers() 49 | { 50 | $this->hintLine 51 | ->addPeer('SIP/100') 52 | ->addPeer('SIP/200') 53 | ->addPeer('SIP/300'); 54 | 55 | $expected = "exten => 100,hint,SIP/100&SIP/200&SIP/300"; 56 | $this->assertEquals($expected, $this->hintLine->toString()); 57 | } 58 | } -------------------------------------------------------------------------------- /tests/Application/GosubTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('Gosub', $goSub->getName()); 16 | } 17 | 18 | public function testGetDataPriority() 19 | { 20 | $goSub = new Gosub(1); 21 | $this->assertEquals('1', $goSub->getData()); 22 | } 23 | 24 | public function testGetDataPriorityContext() 25 | { 26 | $goSub = new Gosub(1, 'example_context'); 27 | $this->assertEquals('example_context,1', $goSub->getData()); 28 | } 29 | 30 | public function testGetDataPriorityContextExten() 31 | { 32 | $goSub = new Gosub(1, 'example_context', 100); 33 | $this->assertEquals('example_context,100,1', $goSub->getData()); 34 | } 35 | 36 | public function testGetDataPriorityContextExtenArguments() 37 | { 38 | $goSub = new Gosub(1, 'example_context', 100, [ 39 | '${EXAMPLE_ARGUMENT}', 40 | '67890' 41 | ]); 42 | 43 | $this->assertEquals('example_context,100,1(${EXAMPLE_ARGUMENT},67890)', $goSub->getData()); 44 | } 45 | 46 | public function testGetDataArguments() 47 | { 48 | $goSub = new Gosub(1,null,null,[ 49 | '12345', 50 | '09876' 51 | ]); 52 | 53 | $this->assertEquals('1(12345,09876)', $goSub->getData()); 54 | } 55 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/GosubReturn.php: -------------------------------------------------------------------------------- 1 | value = $value; 16 | } 17 | 18 | /** 19 | * @return string|null 20 | */ 21 | public function getValue() 22 | { 23 | return $this->value; 24 | } 25 | 26 | /** 27 | * Should return the name of the application 28 | * 29 | * @return string 30 | */ 31 | public function getName() 32 | { 33 | return 'Return'; 34 | } 35 | 36 | /** 37 | * Should return the AppData. AppData is the string contents 38 | * between the () of the App. 39 | * 40 | * @return string 41 | */ 42 | public function getData() 43 | { 44 | return ( isset($this->value) ? $this->value : '' ); 45 | } 46 | 47 | /** 48 | * Turns this application into an Array 49 | * 50 | * @return array 51 | */ 52 | public function toArray() 53 | { 54 | return [ 55 | 'value' => $this->value 56 | ]; 57 | } 58 | 59 | /** 60 | * Turns this Application into a json representation 61 | * 62 | * @param int $options 63 | * @return string 64 | */ 65 | public function toJson($options = 0) 66 | { 67 | return json_encode($this->toArray(), $options); 68 | } 69 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Hangup.php: -------------------------------------------------------------------------------- 1 | causecode = $causecode; 16 | } 17 | 18 | /** 19 | * @return null|string 20 | */ 21 | public function getCausecode() 22 | { 23 | return $this->causecode; 24 | } 25 | 26 | /** 27 | * Should return the name of the application 28 | * 29 | * @return string 30 | */ 31 | public function getName() 32 | { 33 | return 'Hangup'; 34 | } 35 | 36 | /** 37 | * Should return the AppData. AppData is the string contents 38 | * between the () of the App. 39 | * 40 | * @return string 41 | */ 42 | public function getData() 43 | { 44 | return $this->causecode; 45 | } 46 | 47 | /** 48 | * Turns this application into an Array 49 | * 50 | * @return array 51 | */ 52 | public function toArray() 53 | { 54 | return array( 55 | 'causecode' => $this->causecode 56 | ); 57 | } 58 | 59 | /** 60 | * Turns this Application into a json representation 61 | * 62 | * @param int $options 63 | * @return string 64 | */ 65 | public function toJson($options = 0) 66 | { 67 | return json_encode($this->toArray(), $options); 68 | } 69 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Line/HintLine.php: -------------------------------------------------------------------------------- 1 | pattern = $pattern; 15 | $this->peers = $peers; 16 | } 17 | 18 | /** 19 | * Add peers to this hint. 20 | */ 21 | public function addPeer(string $peerString): HintLine 22 | { 23 | $this->peers[] = $peerString; 24 | return $this; 25 | } 26 | 27 | public function getPeers(): array 28 | { 29 | return $this->peers; 30 | } 31 | 32 | /** 33 | * Get the pattern for this line. There is no guarantee that 34 | * the response string wouldn't be empty. 35 | */ 36 | public function getPattern(): string 37 | { 38 | return $this->pattern; 39 | } 40 | 41 | /** 42 | * Get the priority for this line. There is no guarantee that 43 | * the response string wouldn't be empty. 44 | */ 45 | public function getPriority(): ?string 46 | { 47 | return 'hint'; 48 | } 49 | 50 | /** 51 | * Get the application associated with this line. 52 | */ 53 | public function getApplication(): ?ApplicationInterface 54 | { 55 | return null; 56 | } 57 | 58 | /** 59 | * Turn this implemented Line into a string representation. 60 | */ 61 | public function toString(): string 62 | { 63 | return "exten => " . $this->pattern . ',hint,' . implode('&', $this->peers); 64 | } 65 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Reader/Line/ExtenLineReader.php: -------------------------------------------------------------------------------- 1 | applications = $applications; 25 | } 26 | 27 | /** 28 | * Should return the regex string to match the line against this line instance. 29 | * 30 | * @return string 31 | */ 32 | public function getMatchFormat() 33 | { 34 | return "/^exten\s?=>\s?([A-Za-z0-9\-+_.!\[\]]+),([0-9]+)(\(?.+\))?,(.+)/"; 35 | } 36 | 37 | /** 38 | * Return the instance of the line interface. Will be given the matches from 39 | * the match format above. 40 | * 41 | * @param array $matches 42 | * @return LineInterface 43 | */ 44 | public function getInstance($matches) 45 | { 46 | $application = $this->findApplication($matches[4], $this->applications); 47 | $extenLine = new ExtenLine($matches[1], $matches[2], $application); 48 | 49 | if(!empty($matches[3])) { 50 | $extenLine->setLabel(str_replace(['(', ')'], '', $matches[3])); 51 | } 52 | 53 | return $extenLine; 54 | } 55 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/SIPRemoveHeader.php: -------------------------------------------------------------------------------- 1 | header = $header; 22 | } 23 | 24 | /** 25 | * Get the header name 26 | * 27 | * @return string 28 | */ 29 | public function getHeader() 30 | { 31 | return $this->header; 32 | } 33 | 34 | /** 35 | * Should return the name of the application 36 | * 37 | * @return string 38 | */ 39 | public function getName() 40 | { 41 | return 'SIPRemoveHeader'; 42 | } 43 | 44 | /** 45 | * Should return the AppData. AppData is the string contents 46 | * between the () of the App. 47 | * 48 | * @return string 49 | */ 50 | public function getData() 51 | { 52 | return $this->header; 53 | } 54 | 55 | /** 56 | * Turns this application into an Array 57 | * 58 | * @return array 59 | */ 60 | public function toArray() 61 | { 62 | return [ 63 | 'header' => $this->header, 64 | ]; 65 | } 66 | 67 | /** 68 | * Turns this Application into a json representation 69 | * 70 | * @param int $options 71 | * @return string 72 | */ 73 | public function toJson($options = 0) 74 | { 75 | return json_encode($this->toArray(), $options); 76 | } 77 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/UndeterminedApplication.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class UndeterminedApplication implements ApplicationInterface 13 | { 14 | use StandardApplicationTrait; 15 | 16 | /** 17 | * @var string 18 | */ 19 | protected $name; 20 | 21 | /** 22 | * @var string 23 | */ 24 | protected $data; 25 | 26 | public function __construct($name,$data) 27 | { 28 | $this->name = $name; 29 | $this->data = $data; 30 | } 31 | 32 | /** 33 | * Should return the name of the application 34 | * 35 | * @return string 36 | */ 37 | public function getName() 38 | { 39 | return $this->name; 40 | } 41 | 42 | /** 43 | * Should return the AppData. AppData is the string contents 44 | * between the () of the App. 45 | * 46 | * @return string 47 | */ 48 | public function getData() 49 | { 50 | return $this->data; 51 | } 52 | 53 | /** 54 | * Turns this application into an Array 55 | * 56 | * @return array 57 | */ 58 | public function toArray() 59 | { 60 | return array( 61 | 'name' => $this->name, 62 | 'data' => $this->data 63 | ); 64 | } 65 | 66 | /** 67 | * Turns this Application into a json representation 68 | * 69 | * @param int $options 70 | * @return string 71 | */ 72 | public function toJson($options = 0) 73 | { 74 | return json_encode($this->toArray(), $options); 75 | } 76 | } -------------------------------------------------------------------------------- /tests/Application/CELGenUserEventTest.php: -------------------------------------------------------------------------------- 1 | genUserEvent = new CELGenUserEvent('testing'); 18 | } 19 | 20 | public function testGetName() 21 | { 22 | $this->assertEquals('CELGenUserEvent', $this->genUserEvent->getName()); 23 | } 24 | 25 | public function testGetEventName() 26 | { 27 | $this->assertEquals('testing', $this->genUserEvent->getEventName()); 28 | } 29 | 30 | public function testGetDataWithNoExtra() 31 | { 32 | $this->assertEquals('testing', $this->genUserEvent->getData()); 33 | } 34 | 35 | public function testGetDataWithExtra() 36 | { 37 | $this->genUserEvent->setExtra('0123456789'); 38 | $this->assertEquals('testing,0123456789', $this->genUserEvent->getData()); 39 | } 40 | 41 | public function testToArray() 42 | { 43 | $this->genUserEvent->setExtra('0123456789'); 44 | 45 | $expected = [ 46 | 'event_name' => 'testing', 47 | 'extra' => '0123456789' 48 | ]; 49 | 50 | $this->assertEquals($expected, $this->genUserEvent->toArray()); 51 | } 52 | 53 | public function testToJson() 54 | { 55 | $this->genUserEvent->setExtra('0987654321'); 56 | 57 | $expected = json_encode([ 58 | 'event_name' => 'testing', 59 | 'extra' => '0987654321' 60 | ]); 61 | 62 | $this->assertEquals($expected, $this->genUserEvent->toJson()); 63 | } 64 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/NoOp.php: -------------------------------------------------------------------------------- 1 | text = $text; 24 | } 25 | 26 | /** 27 | * @return string 28 | */ 29 | public function getText() 30 | { 31 | return $this->text; 32 | } 33 | 34 | /** 35 | * Should return the name of the application 36 | * 37 | * @return string 38 | */ 39 | public function getName() 40 | { 41 | return 'NoOp'; 42 | } 43 | 44 | /** 45 | * Should return the AppData. AppData is the string contents 46 | * between the () of the App. 47 | * 48 | * @return string 49 | */ 50 | public function getData() 51 | { 52 | return $this->text; 53 | } 54 | 55 | /** 56 | * Turns this application into an Array 57 | * 58 | * @return array 59 | */ 60 | public function toArray() 61 | { 62 | return array( 63 | 'text' => $this->text 64 | ); 65 | } 66 | 67 | /** 68 | * Turns this Application into a json representation 69 | * 70 | * @param int $options 71 | * @return string 72 | */ 73 | public function toJson($options = 0) 74 | { 75 | return json_encode($this->toArray(), $options); 76 | } 77 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/WhileApplication.php: -------------------------------------------------------------------------------- 1 | expression = $expression; 17 | } 18 | 19 | /** 20 | * Should return the name of the application 21 | * 22 | * @return string 23 | */ 24 | public function getName() 25 | { 26 | return 'While'; 27 | } 28 | 29 | /** 30 | * Return the set expression that the while loop will continue 31 | * until it doesn't return 1. 32 | * 33 | * @return string 34 | */ 35 | public function getExpression() 36 | { 37 | return $this->expression; 38 | } 39 | 40 | /** 41 | * Should return the AppData. AppData is the string contents 42 | * between the () of the App. 43 | * 44 | * @return string 45 | */ 46 | public function getData() 47 | { 48 | return $this->expression; 49 | } 50 | 51 | /** 52 | * Turns this application into an Array 53 | * 54 | * @return array 55 | */ 56 | public function toArray() 57 | { 58 | return [ 59 | 'expression' => $this->expression, 60 | ]; 61 | } 62 | 63 | /** 64 | * Turns this Application into a json representation 65 | * 66 | * @param int $options 67 | * @return string 68 | */ 69 | public function toJson($options = 0) 70 | { 71 | return json_encode($this->toArray(), $options); 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /tests/Application/RemoveQueueMemberTest.php: -------------------------------------------------------------------------------- 1 | removeMember = new RemoveQueueMember('support'); 18 | } 19 | 20 | public function testGetName() 21 | { 22 | $this->assertEquals('RemoveQueueMember', $this->removeMember->getName()); 23 | } 24 | 25 | public function testGetQueueName() 26 | { 27 | $this->assertEquals('support', $this->removeMember->getQueueName()); 28 | } 29 | 30 | public function testGetDataNoArguments() 31 | { 32 | $this->assertEquals('support', $this->removeMember->getData()); 33 | } 34 | 35 | public function testGetDataWithInterface() 36 | { 37 | $this->removeMember 38 | ->setInterface('SIP/1000'); 39 | 40 | $this->assertEquals('support,SIP/1000', $this->removeMember->getData()); 41 | } 42 | 43 | public function testToArray() 44 | { 45 | $this->removeMember 46 | ->setInterface('SIP/1000'); 47 | 48 | $expected = [ 49 | 'name' => 'support', 50 | 'interface' => 'SIP/1000' 51 | ]; 52 | 53 | $this->assertEquals($expected, $this->removeMember->toArray()); 54 | } 55 | 56 | public function testToJson() 57 | { 58 | $this->removeMember 59 | ->setInterface('SIP/1000'); 60 | 61 | $expected = json_encode([ 62 | 'name' => 'support', 63 | 'interface' => 'SIP/1000' 64 | ]); 65 | 66 | $this->assertEquals($expected, $this->removeMember->toJson()); 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/MinivmGreet.php: -------------------------------------------------------------------------------- 1 | account = $account; 15 | $this->options = $options; 16 | } 17 | 18 | public function getAccount() 19 | { 20 | return $this->account; 21 | } 22 | 23 | public function getOptions() 24 | { 25 | return $this->options; 26 | } 27 | 28 | /** 29 | * Should return the name of the application 30 | * 31 | * @return string 32 | */ 33 | public function getName() 34 | { 35 | return 'MinivmGreet'; 36 | } 37 | 38 | /** 39 | * Should return the AppData. AppData is the string contents 40 | * between the () of the App. 41 | * 42 | * @return string 43 | */ 44 | public function getData() 45 | { 46 | $line = $this->account; 47 | 48 | if(!empty($this->options)) { 49 | $line .= ',' . implode('', $this->options); 50 | } 51 | 52 | return $line; 53 | } 54 | 55 | /** 56 | * Turns this application into an Array 57 | * 58 | * @return array 59 | */ 60 | public function toArray() 61 | { 62 | return [ 63 | 'account' => $this->account, 64 | 'options' => $this->options, 65 | ]; 66 | } 67 | 68 | /** 69 | * Turns this Application into a json representation 70 | * 71 | * @param int $options 72 | * @return string 73 | */ 74 | public function toJson($options = 0) 75 | { 76 | return json_encode($this->toArray(), $options); 77 | } 78 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/MinivmRecord.php: -------------------------------------------------------------------------------- 1 | account = $account; 15 | $this->options = $options; 16 | } 17 | 18 | public function getAccount() 19 | { 20 | return $this->account; 21 | } 22 | 23 | public function getOptions() 24 | { 25 | return $this->options; 26 | } 27 | 28 | /** 29 | * Should return the name of the application 30 | * 31 | * @return string 32 | */ 33 | public function getName() 34 | { 35 | return 'MinivmRecord'; 36 | } 37 | 38 | /** 39 | * Should return the AppData. AppData is the string contents 40 | * between the () of the App. 41 | * 42 | * @return string 43 | */ 44 | public function getData() 45 | { 46 | $data = $this->account; 47 | 48 | if(!empty($this->options)) { 49 | $data .= ',' . implode('', $this->options); 50 | } 51 | 52 | return $data; 53 | } 54 | 55 | /** 56 | * Turns this application into an Array 57 | * 58 | * @return array 59 | */ 60 | public function toArray() 61 | { 62 | return [ 63 | 'account' => $this->account, 64 | 'options' => $this->options, 65 | ]; 66 | } 67 | 68 | /** 69 | * Turns this Application into a json representation 70 | * 71 | * @param int $options 72 | * @return string 73 | */ 74 | public function toJson($options = 0) 75 | { 76 | return json_encode($this->toArray(), $options); 77 | } 78 | 79 | 80 | } -------------------------------------------------------------------------------- /tests/Reader/ReaderTest.php: -------------------------------------------------------------------------------- 1 | reader = new Reader([new ExtenLineReader([new NoOpReader])]); 20 | } 21 | 22 | public function testSimpleDialplan() 23 | { 24 | $dialplan = $this->reader->read(file_get_contents(__DIR__ . '/source-examples/simple-dialplan.txt')); 25 | 26 | $this->assertEquals('dialplan_context_1', $dialplan->getName()); 27 | $this->assertEquals(3, count($dialplan->getLines())); 28 | } 29 | 30 | public function testAdvancedDialplan() 31 | { 32 | $dialplan = $this->reader->read(file_get_contents(__DIR__ . '/source-examples/advanced-dialplan.txt')); 33 | 34 | $this->assertEquals('ea91e4f9-633c-4fa6-b357-438078ecf585', $dialplan->getName()); 35 | $this->assertEquals(28, count($dialplan->getLines())); 36 | } 37 | 38 | public function testExtendedDialplan() 39 | { 40 | $dialplan = $this->reader->read(file_get_contents(__DIR__ . '/source-examples/extended-dialplan.txt')); 41 | 42 | $this->assertEquals('something_unattached', $dialplan->getName()); 43 | $this->assertTrue($dialplan->isExtended()); 44 | } 45 | 46 | public function testNumberVariantDialplan() 47 | { 48 | $dialplan = $this->reader->read(file_get_contents(__DIR__ . '/source-examples/number-variant.txt')); 49 | 50 | $this->assertEquals('number_incoming', $dialplan->getName()); 51 | $this->assertEquals(4, count($dialplan->getLines())); 52 | } 53 | } -------------------------------------------------------------------------------- /tests/Application/MinivmMWITest.php: -------------------------------------------------------------------------------- 1 | minivmMWI = new MinivmMWI('example@host.com', 0, 1, 2); 18 | } 19 | 20 | public function testGetName() 21 | { 22 | $this->assertEquals('MinivmMWI', $this->minivmMWI->getName()); 23 | } 24 | 25 | public function testGetUrgent() 26 | { 27 | $expected = 0; 28 | $this->assertEquals($expected, $this->minivmMWI->getUrgent()); 29 | } 30 | 31 | public function testGetNew() 32 | { 33 | $expected = 1; 34 | $this->assertEquals($expected, $this->minivmMWI->getNew()); 35 | } 36 | 37 | public function testGetOld() 38 | { 39 | $expected = 2; 40 | $this->assertEquals($expected, $this->minivmMWI->getOld()); 41 | } 42 | 43 | public function testGetData() 44 | { 45 | $expected = 'example@host.com,0,1,2'; 46 | $this->assertEquals($expected, $this->minivmMWI->getData()); 47 | } 48 | 49 | public function testToArray() 50 | { 51 | $expected = ['account' => 'example@host.com', 'urgent' => 0, 'new' => 1, 'old' => 2]; 52 | $this->assertEquals($expected, $this->minivmMWI->toArray()); 53 | } 54 | 55 | public function testToString() 56 | { 57 | $expected = "MinivmMWI(example@host.com,0,1,2)"; 58 | $this->assertEquals($expected, $this->minivmMWI->toString()); 59 | } 60 | 61 | public function testToJson() 62 | { 63 | $expected = json_encode(['account' => 'example@host.com', 'urgent' => 0, 'new' => 1, 'old' => 2]); 64 | $this->assertEquals($expected, $this->minivmMWI->toJson()); 65 | } 66 | } -------------------------------------------------------------------------------- /tests/Application/AuthenticateTest.php: -------------------------------------------------------------------------------- 1 | authenticate = new Authenticate('1234'); 18 | } 19 | 20 | public function testNameIsCorrect() 21 | { 22 | $this->assertEquals('Authenticate', $this->authenticate->getName()); 23 | } 24 | 25 | public function testPasswordIsCorrect() 26 | { 27 | $this->assertEquals('1234', $this->authenticate->getPassword()); 28 | } 29 | 30 | public function testGetDataIsCorrect() 31 | { 32 | $this->assertEquals('1234', $this->authenticate->getData()); 33 | } 34 | 35 | public function testGetDataWithParameters() 36 | { 37 | $this->authenticate->setMaxDigits(5); 38 | $this->assertEquals('1234,,5', $this->authenticate->getData()); 39 | 40 | $this->authenticate->setOptions(['a', 'm']); 41 | $this->assertEquals('1234,am,5', $this->authenticate->getData()); 42 | 43 | $this->authenticate->setPrompt(true); 44 | $this->assertEquals('1234,am,5,1', $this->authenticate->getData()); 45 | } 46 | 47 | public function testDataWithOnlyOptions() 48 | { 49 | $this->authenticate->setOptions(['a', 'm']); 50 | $this->assertEquals('1234,am', $this->authenticate->getData()); 51 | } 52 | 53 | public function testDataWithOnlyMaxDigits() 54 | { 55 | $this->authenticate->setMaxDigits(10); 56 | $this->assertEquals('1234,,10', $this->authenticate->getData()); 57 | } 58 | 59 | public function testDataWithOnlyPrompt() 60 | { 61 | $this->authenticate->setPrompt(true); 62 | $this->assertEquals('1234,,,1', $this->authenticate->getData()); 63 | } 64 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Macro.php: -------------------------------------------------------------------------------- 1 | macroName = $macroName; 15 | } 16 | 17 | public function getMacroName() 18 | { 19 | return $this->macroName; 20 | } 21 | 22 | public function addArgument($argument) 23 | { 24 | $this->arguments[] = $argument; 25 | return $this; 26 | } 27 | 28 | public function getArguments() 29 | { 30 | return $this->arguments; 31 | } 32 | 33 | /** 34 | * Should return the name of the application 35 | * 36 | * @return string 37 | */ 38 | public function getName() 39 | { 40 | return 'Macro'; 41 | } 42 | 43 | /** 44 | * Should return the AppData. AppData is the string contents 45 | * between the () of the App. 46 | * 47 | * @return string 48 | */ 49 | public function getData() 50 | { 51 | $data = $this->macroName; 52 | 53 | if ( ! empty($this->arguments)) { 54 | $data .= ','; 55 | $data .= implode(',', $this->arguments); 56 | } 57 | 58 | return $data; 59 | } 60 | 61 | /** 62 | * Turns this application into an Array 63 | * 64 | * @return array 65 | */ 66 | public function toArray() 67 | { 68 | return array( 69 | 'name' => $this->macroName, 70 | 'arguments' => $this->arguments 71 | ); 72 | } 73 | 74 | /** 75 | * Turns this Application into a json representation 76 | * 77 | * @param int $options 78 | * @return string 79 | */ 80 | public function toJson($options = 0) 81 | { 82 | return json_encode($this->toArray(), $options); 83 | } 84 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Answer.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class Answer implements ApplicationInterface 13 | { 14 | use StandardApplicationTrait; 15 | 16 | /** 17 | * @var int 18 | */ 19 | protected $delay; 20 | 21 | /** 22 | * Asterisk will wait this number of milliseconds before returning to 23 | * the dialplan after answering the call. 24 | * 25 | * @param int $delay 26 | */ 27 | public function __construct($delay = null) 28 | { 29 | $this->delay = $delay; 30 | } 31 | 32 | /** 33 | * The number of milliseconds to way before returning to the dialplan 34 | * 35 | * @return int 36 | */ 37 | public function getDelay() 38 | { 39 | return $this->delay; 40 | } 41 | 42 | /** 43 | * Should return the name of the application 44 | * 45 | * @return string 46 | */ 47 | public function getName() 48 | { 49 | return 'Answer'; 50 | } 51 | 52 | /** 53 | * Should return the AppData. AppData is the string contents 54 | * between the () of the App. 55 | * 56 | * @return string 57 | */ 58 | public function getData() 59 | { 60 | return $this->delay; 61 | } 62 | 63 | /** 64 | * Turns this application into an Array 65 | * 66 | * @return array 67 | */ 68 | public function toArray() 69 | { 70 | return array( 71 | 'delay' => $this->delay 72 | ); 73 | } 74 | 75 | /** 76 | * Turns this Application into a json representation 77 | * 78 | * @param int $options 79 | * @return string 80 | */ 81 | public function toJson($options = 0) 82 | { 83 | return json_encode($this->toArray(), $options); 84 | } 85 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/SIPAddHeader.php: -------------------------------------------------------------------------------- 1 | header = $header; 27 | $this->content = $content; 28 | } 29 | 30 | /** 31 | * Get the header name 32 | * 33 | * @return string 34 | */ 35 | public function getHeader() 36 | { 37 | return $this->header; 38 | } 39 | 40 | /** 41 | * Get the header content 42 | * 43 | * @return string 44 | */ 45 | public function getContent() 46 | { 47 | return $this->content; 48 | } 49 | 50 | /** 51 | * Should return the name of the application 52 | * 53 | * @return string 54 | */ 55 | public function getName() 56 | { 57 | return 'SIPAddHeader'; 58 | } 59 | 60 | /** 61 | * Should return the AppData. AppData is the string contents 62 | * between the () of the App. 63 | * 64 | * @return string 65 | */ 66 | public function getData() 67 | { 68 | return $this->header . ': ' . $this->content; 69 | } 70 | 71 | /** 72 | * Turns this application into an Array 73 | * 74 | * @return array 75 | */ 76 | public function toArray() 77 | { 78 | return [ 79 | 'header' => $this->header, 80 | 'content' => $this->content, 81 | ]; 82 | } 83 | 84 | /** 85 | * Turns this Application into a json representation 86 | * 87 | * @param int $options 88 | * @return string 89 | */ 90 | public function toJson($options = 0) 91 | { 92 | return json_encode($this->toArray(), $options); 93 | } 94 | } -------------------------------------------------------------------------------- /tests/Application/GotoIfTest.php: -------------------------------------------------------------------------------- 1 | true = $this->createMock(Go::class); 26 | $this->false = $this->createMock(Go::class); 27 | } 28 | 29 | public function testName() 30 | { 31 | $gotoif = new GotoIf('1=1'); 32 | $this->assertEquals('GotoIf', $gotoif->getName()); 33 | } 34 | 35 | public function testWithTrueCondition() 36 | { 37 | $this->true 38 | ->expects($this->once()) 39 | ->method('getData') 40 | ->willReturn('telephones,100,1'); 41 | 42 | $gotoif = new GotoIf('1=1', $this->true); 43 | 44 | $this->assertEquals('GotoIf(1=1?telephones,100,1)', $gotoif->toString()); 45 | } 46 | 47 | public function testWithOnlyFalseCondition() 48 | { 49 | $this->false 50 | ->expects($this->once()) 51 | ->method('getData') 52 | ->willReturn('phones,101,1'); 53 | 54 | $gotoif = new GotoIf('1=1', null, $this->false); 55 | 56 | $this->assertEquals('GotoIf(1=1?:phones,101,1)', $gotoif->toString()); 57 | } 58 | 59 | public function testWithTrueAndFalseCondition() 60 | { 61 | $this->true 62 | ->expects($this->once()) 63 | ->method('getData') 64 | ->willReturn('telephones,100,1'); 65 | 66 | $this->false 67 | ->expects($this->once()) 68 | ->method('getData') 69 | ->willReturn('phones,101,1'); 70 | 71 | $gotoif = new GotoIf('1=1', $this->true, $this->false); 72 | 73 | $this->assertEquals('GotoIf(1=1?telephones,100,1:phones,101,1)', $gotoif->toString()); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tests/Application/VoicemailTest.php: -------------------------------------------------------------------------------- 1 | voicemail = new Voicemail('100', 'default', ['b', 'u']); 18 | } 19 | 20 | public function testName() 21 | { 22 | $this->assertEquals('Voicemail', $this->voicemail->getName()); 23 | } 24 | 25 | public function testData() 26 | { 27 | $this->assertEquals('100@default,bu', $this->voicemail->getData()); 28 | } 29 | 30 | public function testDataWithoutContextAndOneMailboxNoOptions() 31 | { 32 | $voicemail = new Voicemail('100'); 33 | $this->assertEquals('100', $voicemail->getData()); 34 | } 35 | 36 | public function testDataWithContextNoOptions() 37 | { 38 | $voicemail = new Voicemail('100', 'default'); 39 | $this->assertEquals('100@default', $voicemail->getData()); 40 | } 41 | 42 | public function testDataWithoutContextAndOptions() 43 | { 44 | $voicemail = new Voicemail('100', null, ['b', 'u']); 45 | $this->assertEquals('100,bu', $voicemail->getData()); 46 | } 47 | 48 | public function testAddMailbox() 49 | { 50 | $this->voicemail->addMailbox('200', 'another_context'); 51 | $this->assertEquals('100@default&200@another_context,bu', $this->voicemail->getData()); 52 | } 53 | 54 | public function testGetMailboxes() 55 | { 56 | $voicemail = new Voicemail('100'); 57 | $voicemail->addMailbox('200', 'example'); 58 | 59 | $expected = [['mailbox' => '100', 'context' => null], ['mailbox' => '200', 'context' => 'example']]; 60 | $this->assertEquals($expected, $voicemail->getMailboxes()); 61 | } 62 | 63 | public function testToArray() 64 | { 65 | $expected = [ 66 | 'mailboxes' => [ 67 | ['mailbox' => '100', 'context' => 'default'] 68 | ], 69 | 'options' => ['b', 'u'] 70 | ]; 71 | 72 | $this->assertEquals($expected, $this->voicemail->toArray()); 73 | } 74 | } -------------------------------------------------------------------------------- /tests/Application/ChanSpyTest.php: -------------------------------------------------------------------------------- 1 | chanSpy = new ChanSpy(); 18 | } 19 | 20 | public function testGetNameIsCorrect() 21 | { 22 | $this->assertEquals('ChanSpy', $this->chanSpy->getName()); 23 | } 24 | 25 | public function testSetGetChanPrefix() 26 | { 27 | $this->chanSpy->setChanPrefix('Agent'); 28 | $this->assertEquals('Agent', $this->chanSpy->getChanPrefix()); 29 | 30 | $chanSpy = new ChanSpy('Agent'); 31 | $this->assertEquals('Agent', $chanSpy->getChanPrefix()); 32 | } 33 | 34 | public function testSetGetOptions() 35 | { 36 | $options = ['b', 'c(5)', 'e(100:101)']; 37 | $this->chanSpy->setOptions($options); 38 | $this->assertEquals($options, $this->chanSpy->getOptions()); 39 | 40 | $chanSpy = new ChanSpy('', $options); 41 | $this->assertEquals($options, $chanSpy->getOptions()); 42 | } 43 | 44 | public function testGetDataOnlyPrefix() 45 | { 46 | $this->chanSpy->setChanPrefix('Agent'); 47 | $this->assertEquals('Agent', $this->chanSpy->getData()); 48 | } 49 | 50 | public function testGetDataOnlyOptions() 51 | { 52 | $options = ['b', 'c(5)', 'e(100:101)']; 53 | $this->chanSpy->setOptions($options); 54 | $this->assertEquals(',bc(5)e(100:101)', $this->chanSpy->getData()); 55 | } 56 | 57 | public function testGetDataBoth() 58 | { 59 | $this->chanSpy 60 | ->setChanPrefix('Agent') 61 | ->setOptions(['b', 'c(5)', 'e(100:101)']); 62 | 63 | $this->assertEquals('Agent,bc(5)e(100:101)', $this->chanSpy->getData()); 64 | } 65 | 66 | public function testString() 67 | { 68 | $this->assertEquals('ChanSpy()', $this->chanSpy->toString()); 69 | 70 | $this->chanSpy 71 | ->setChanPrefix('Agent') 72 | ->setOptions(['b', 'c(5)', 'x(1)']); 73 | 74 | $this->assertEquals('ChanSpy(Agent,bc(5)x(1))', $this->chanSpy->toString()); 75 | } 76 | } -------------------------------------------------------------------------------- /tests/Application/BackGroundTest.php: -------------------------------------------------------------------------------- 1 | background = new BackGround('beep'); 18 | } 19 | 20 | public function testGetNameIsCorrect() 21 | { 22 | $this->assertEquals('BackGround', $this->background->getName()); 23 | } 24 | 25 | public function testGetDataIsCorrect() 26 | { 27 | $this->assertEquals('beep', $this->background->getData()); 28 | 29 | $this->background->addFile('vm-password'); 30 | $this->assertEquals('beep&vm-password', $this->background->getData()); 31 | 32 | $this->background->setContext('incoming'); 33 | $this->assertEquals('beep&vm-password,,,incoming', $this->background->getData()); 34 | 35 | $this->background->setLangOverride('en'); 36 | $this->assertEquals('beep&vm-password,,en,incoming', $this->background->getData()); 37 | 38 | $this->background->setNoAnswer(true); 39 | $this->assertEquals('beep&vm-password,n,en,incoming', $this->background->getData()); 40 | 41 | $this->background 42 | ->setSkip(true) 43 | ->setOnlyMatch(true); 44 | 45 | $this->assertEquals('beep&vm-password,snm,en,incoming', $this->background->getData()); 46 | } 47 | 48 | public function testGetArrayAndJson() 49 | { 50 | $expected = [ 51 | 'filename' => 'beep', 52 | 'other_files' => [], 53 | 'skip' => false, 54 | 'no_answer' => false, 55 | 'only_match' => true, 56 | 'lang_override' => 'en', 57 | 'context' => 'incoming' 58 | ]; 59 | 60 | $this->background 61 | ->setContext('incoming') 62 | ->setLangOverride('en') 63 | ->setSkip(false) 64 | ->setNoAnswer(false) 65 | ->setOnlyMatch(true); 66 | 67 | $this->assertEquals($expected, $this->background->toArray()); 68 | $this->assertEquals(json_encode($expected), $this->background->toJson()); 69 | } 70 | } -------------------------------------------------------------------------------- /tests/Application/PageTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('Page', $dial->getName()); 15 | } 16 | 17 | public function testGetSingleTarget() 18 | { 19 | $dial = new Page('SIP', 100); 20 | 21 | $this->assertEquals('SIP/100', $dial->getData()); 22 | } 23 | 24 | public function testGetDataMultipleTargets() 25 | { 26 | $dial = new Page('SIP', 100); 27 | $dial 28 | ->addTarget('SIP', 101) 29 | ->addTarget('SIP', 102); 30 | 31 | $this->assertEquals('SIP/100&SIP/101&SIP/102', $dial->getData()); 32 | } 33 | 34 | public function testGetDataTimeout() 35 | { 36 | $dial = new Page('SIP', 100, 30); 37 | 38 | $this->assertEquals('SIP/100,,30', $dial->getData()); 39 | } 40 | 41 | public function testGetDataSingleOption() 42 | { 43 | $dial = new Page('SIP', 100); 44 | $dial->addOption('q'); 45 | 46 | $this->assertEquals('SIP/100,q', $dial->getData()); 47 | } 48 | 49 | public function testGetDataMultipleOptions() 50 | { 51 | $dial = new Page('SIP', 100, 30); 52 | $dial 53 | ->addOption('q') 54 | ->addOption('d'); 55 | 56 | $this->assertEquals('SIP/100,qd,30', $dial->getData()); 57 | } 58 | 59 | public function testGetTargets() 60 | { 61 | $dial = new Page('SIP', 100); 62 | $dial 63 | ->addTarget('SIP', 101) 64 | ->addTarget('SIP', 102); 65 | 66 | $expectedTargets = array( 67 | array('SIP', 100), 68 | array('SIP', 101), 69 | array('SIP', 102) 70 | ); 71 | 72 | $this->assertEquals($expectedTargets, $dial->getTargets()); 73 | } 74 | 75 | public function testGetOptions() 76 | { 77 | $dial = new Page('SIP', 100, 30); 78 | $dial 79 | ->addOption('q') 80 | ->addOption('d') 81 | ->addOption('b(test)'); 82 | 83 | $this->assertEquals(array('q', 'd', 'b(test)'), $dial->getOptions()); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/Application/GosubIfTest.php: -------------------------------------------------------------------------------- 1 | true = $this->createMock(Go::class); 27 | $this->false = $this->createMock(Go::class); 28 | } 29 | 30 | public function testName() 31 | { 32 | $goSubIf = new GosubIf('1=1'); 33 | $this->assertEquals('GosubIf', $goSubIf->getName()); 34 | } 35 | 36 | public function testWithTrueCondition() 37 | { 38 | $this->true 39 | ->expects($this->once()) 40 | ->method('getData') 41 | ->willReturn('telephones,100,1'); 42 | 43 | $goSubIf = new GosubIf('1=1', $this->true); 44 | 45 | $this->assertEquals('GosubIf(1=1?telephones,100,1)', $goSubIf->toString()); 46 | } 47 | 48 | public function testWithOnlyFalseCondition() 49 | { 50 | $this->false 51 | ->expects($this->once()) 52 | ->method('getData') 53 | ->willReturn('phones,101,1'); 54 | 55 | $goSubIf = new GosubIf('1=1', null, $this->false); 56 | 57 | $this->assertEquals('GosubIf(1=1?:phones,101,1)', $goSubIf->toString()); 58 | } 59 | 60 | public function testWithTrueAndFalseCondition() 61 | { 62 | $this->true 63 | ->expects($this->once()) 64 | ->method('getData') 65 | ->willReturn('telephones,100,1'); 66 | 67 | $this->false 68 | ->expects($this->once()) 69 | ->method('getData') 70 | ->willReturn('phones,101,1'); 71 | 72 | $goSubIf = new GosubIf('1=1', $this->true, $this->false); 73 | 74 | $this->assertEquals('GosubIf(1=1?telephones,100,1:phones,101,1)', $goSubIf->toString()); 75 | } 76 | 77 | public function testToArrayWithNoConditions() 78 | { 79 | $goSubIf = new GosubIf('1=1'); 80 | $this->assertEquals(['condition' => '1=1'], $goSubIf->toArray()); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/Reader/Application/HasApplicationTraitTest.php: -------------------------------------------------------------------------------- 1 | getObjectForTrait(HasApplicationTrait::class); 16 | 17 | $noOpApplication = $this->createMock(ApplicationReaderInterface::class); 18 | $noOpApplication 19 | ->expects($this->once()) 20 | ->method('getMatchFormat') 21 | ->willReturn('/(NoOp)\((.+)\)/'); 22 | 23 | $noOpMock = $this->createMock(ApplicationInterface::class); 24 | $noOpMock 25 | ->expects($this->once()) 26 | ->method('getName') 27 | ->willReturn('NoOp'); 28 | 29 | $noOpMock 30 | ->expects($this->once()) 31 | ->method('getData') 32 | ->willReturn('this is an example'); 33 | 34 | $noOpApplication 35 | ->expects($this->once()) 36 | ->method('getInstance') 37 | ->willReturn($noOpMock); 38 | 39 | $applications = []; 40 | $applications[] = $noOpApplication; 41 | 42 | $application = $hasApplication->findApplication("NoOp(this is an example)", $applications); 43 | 44 | $this->assertTrue($application instanceof ApplicationInterface); 45 | $this->assertEquals('NoOp', $application->getName()); 46 | $this->assertEquals('this is an example', $application->getData()); 47 | } 48 | 49 | public function testFindApplicationWithUnknownApplication() 50 | { 51 | /** @var HasApplicationTrait $hasApplication */ 52 | $hasApplication = $this->getObjectForTrait(HasApplicationTrait::class); 53 | 54 | $applications = []; 55 | $application = $hasApplication->findApplication('Testing(hello there)', $applications); 56 | 57 | $this->assertTrue($application instanceof UndeterminedApplication); 58 | $this->assertEquals('Testing', $application->getName()); 59 | $this->assertEquals('hello there', $application->getData()); 60 | } 61 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Line/ExtenLine.php: -------------------------------------------------------------------------------- 1 | pattern = $pattern; 31 | $this->priority = $priority; 32 | $this->application = $application; 33 | } 34 | 35 | /** 36 | * Get the pattern for this line. There is no guarantee that 37 | * the response string wouldn't be empty. 38 | */ 39 | public function getPattern(): string 40 | { 41 | return $this->pattern; 42 | } 43 | 44 | /** 45 | * Get the priority for this line. There is no guarantee that 46 | * the response string wouldn't be empty. 47 | */ 48 | public function getPriority(): ?string 49 | { 50 | return $this->priority; 51 | } 52 | 53 | public function setPriority(string $priority) { 54 | $this->priority = $priority; 55 | } 56 | 57 | /** 58 | * Get the application associated with this line. 59 | */ 60 | public function getApplication(): ApplicationInterface 61 | { 62 | return $this->application; 63 | } 64 | 65 | /** 66 | * Set the label for this line. 67 | */ 68 | public function setLabel(string $label): ExtenLine 69 | { 70 | $this->label = $label; 71 | return $this; 72 | } 73 | 74 | /** 75 | * Get the label set for this line. 76 | */ 77 | public function getLabel(): string 78 | { 79 | return $this->label; 80 | } 81 | 82 | /** 83 | * Turn this implemented Line into a string representation. 84 | */ 85 | public function toString(): string 86 | { 87 | $label = ''; 88 | 89 | if (isset($this->label)) { 90 | $label = '(' . $this->label . ')'; 91 | } 92 | 93 | return 'exten => ' . 94 | $this->getPattern() . 95 | ',' . $this->getPriority() . $label . 96 | ',' . $this->application->toString(); 97 | } 98 | } -------------------------------------------------------------------------------- /tests/Application/GotoIfTimeTest.php: -------------------------------------------------------------------------------- 1 | true = $this->createMock(Go::class); 26 | $this->false = $this->createMock(Go::class); 27 | } 28 | 29 | public function testName() 30 | { 31 | $ifTime = new GotoIfTime('*', '*', '*', '*'); 32 | $this->assertEquals('GotoIfTime', $ifTime->getName()); 33 | } 34 | 35 | public function testToString() 36 | { 37 | $ifTime = new GotoIfTime('1300-1500', 'mon-fri', '1-31', 'jan'); 38 | $this->assertEquals('GotoIfTime(1300-1500,mon-fri,1-31,jan,?)', $ifTime->toString()); 39 | } 40 | 41 | public function testToStringWithTimezone() 42 | { 43 | $ifTime = new GotoIfTime('1300-1500', 'mon-fri', '1-31', 'jan', 'Amsterdam'); 44 | $this->assertEquals('GotoIfTime(1300-1500,mon-fri,1-31,jan,Amsterdam?)', $ifTime->toString()); 45 | } 46 | 47 | public function testToStringWithTrueCondition() 48 | { 49 | $this->true 50 | ->expects($this->once()) 51 | ->method('getData') 52 | ->willReturn('telephones,101,1'); 53 | 54 | $ifTime = new GotoIfTime('1300-1500', 'mon-fri', '1-31', 'jan', 'Amsterdam', $this->true); 55 | $this->assertEquals('GotoIfTime(1300-1500,mon-fri,1-31,jan,Amsterdam?telephones,101,1:)', $ifTime->toString()); 56 | } 57 | 58 | public function testToStringWithFalseCondition() 59 | { 60 | $this->true 61 | ->expects($this->once()) 62 | ->method('getData') 63 | ->willReturn('telephones,101,1'); 64 | 65 | $this->false 66 | ->expects($this->once()) 67 | ->method('getData') 68 | ->willReturn('phones,100,1'); 69 | 70 | $ifTime = new GotoIfTime('1300-1500', 'mon-fri', '1-31', 'jan', 'Amsterdam', $this->true, $this->false); 71 | $this->assertEquals( 72 | 'GotoIfTime(1300-1500,mon-fri,1-31,jan,Amsterdam?telephones,101,1:phones,100,1)', 73 | $ifTime->toString() 74 | ); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /tests/Application/DialTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('Dial', $dial->getName()); 15 | } 16 | 17 | public function testGetSingleTarget() 18 | { 19 | $dial = new Dial('SIP', 100); 20 | 21 | $this->assertEquals('SIP/100', $dial->getData()); 22 | } 23 | 24 | public function testGetDataMultipleTargets() 25 | { 26 | $dial = new Dial('SIP', 100); 27 | $dial 28 | ->addTarget('SIP', 101) 29 | ->addTarget('SIP', 102); 30 | 31 | $this->assertEquals('SIP/100&SIP/101&SIP/102', $dial->getData()); 32 | } 33 | 34 | public function testGetDataTimeout() 35 | { 36 | $dial = new Dial('SIP', 100, 30); 37 | 38 | $this->assertEquals('SIP/100,30', $dial->getData()); 39 | } 40 | 41 | public function testGetDataSingleOption() 42 | { 43 | $dial = new Dial('SIP', 100, 30); 44 | $dial->addOption('o'); 45 | 46 | $this->assertEquals('SIP/100,30,o', $dial->getData()); 47 | } 48 | 49 | public function testGetDataMultipleOptions() 50 | { 51 | $dial = new Dial('SIP', 100, 30); 52 | $dial 53 | ->addOption('o') 54 | ->addOption('t') 55 | ->addOption('T'); 56 | 57 | $this->assertEquals('SIP/100,30,otT', $dial->getData()); 58 | } 59 | 60 | public function testGetDataURL() 61 | { 62 | $dial = new Dial('SIP', 100, 30, '/url'); 63 | 64 | $this->assertEquals('SIP/100,30,,/url', $dial->getData()); 65 | } 66 | 67 | public function testGetTargets() 68 | { 69 | $dial = new Dial('SIP', 100); 70 | $dial 71 | ->addTarget('SIP', 101) 72 | ->addTarget('SIP', 102); 73 | 74 | $expectedTargets = array( 75 | array('SIP', 100), 76 | array('SIP', 101), 77 | array('SIP', 102) 78 | ); 79 | 80 | $this->assertEquals($expectedTargets, $dial->getTargets()); 81 | } 82 | 83 | public function testGetOptions() 84 | { 85 | $dial = new Dial('SIP', 100, 30); 86 | $dial 87 | ->addOption('o') 88 | ->addOption('t') 89 | ->addOption('T'); 90 | 91 | $this->assertEquals(array('o', 't', 'T'), $dial->getOptions()); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/AGI.php: -------------------------------------------------------------------------------- 1 | command = $command; 21 | } 22 | 23 | /** 24 | * Return the given command for this AGI application 25 | * 26 | * @return string 27 | */ 28 | public function getCommand() 29 | { 30 | return $this->command; 31 | } 32 | 33 | /** 34 | * Add an argument to this AGI application. 35 | * 36 | * @param string $argument 37 | * @return $this 38 | */ 39 | public function addArgument($argument) 40 | { 41 | $this->arguments[] = $argument; 42 | return $this; 43 | } 44 | 45 | /** 46 | * Get all arguments for this AGI application. 47 | * 48 | * @return array 49 | */ 50 | public function getArguments() 51 | { 52 | return $this->arguments; 53 | } 54 | 55 | /** 56 | * Should return the name of the application 57 | * 58 | * @return string 59 | */ 60 | public function getName() 61 | { 62 | return 'AGI'; 63 | } 64 | 65 | /** 66 | * Should return the AppData. AppData is the string contents 67 | * between the () of the App. 68 | * 69 | * @return string 70 | */ 71 | public function getData() 72 | { 73 | $data = $this->command; 74 | 75 | if ( ! empty($this->arguments)) { 76 | $data .= ','; 77 | $data .= implode(',', $this->arguments); 78 | } 79 | 80 | return $data; 81 | } 82 | 83 | /** 84 | * Turns this application into an Array 85 | * 86 | * @return array 87 | */ 88 | public function toArray() 89 | { 90 | return array( 91 | 'command' => $this->command, 92 | 'arguments' => $this->arguments 93 | ); 94 | } 95 | 96 | /** 97 | * Turns this Application into a json representation 98 | * 99 | * @param int $options 100 | * @return string 101 | */ 102 | public function toJson($options = 0) 103 | { 104 | return json_encode($this->toArray(), $options); 105 | } 106 | } -------------------------------------------------------------------------------- /tests/Application/RecordTest.php: -------------------------------------------------------------------------------- 1 | record = new Record("/tmp/hello-world.wav"); 18 | } 19 | 20 | public function testNameIsCorrect() 21 | { 22 | $this->assertEquals("Record", $this->record->getName()); 23 | } 24 | 25 | public function testWithOnlyRequiredParameters() 26 | { 27 | $this->assertEquals("Record(/tmp/hello-world.wav)", $this->record->toString()); 28 | } 29 | 30 | public function testWithSilenceOnly() 31 | { 32 | $this->record->setSilence(5); 33 | 34 | $this->assertEquals("Record(/tmp/hello-world.wav,5)", $this->record->toString()); 35 | } 36 | 37 | public function testWithMaxDurationOnly() 38 | { 39 | $this->record->setMaxDuration(10); 40 | 41 | $this->assertEquals("Record(/tmp/hello-world.wav,,10)", $this->record->toString()); 42 | } 43 | 44 | public function testWithOptionsOnly() 45 | { 46 | $this->record->setOptions(['a', 'q', 's']); 47 | 48 | $this->assertEquals("Record(/tmp/hello-world.wav,,,aqs)", $this->record->toString()); 49 | } 50 | 51 | public function testWithSilenceAndMaxDuration() 52 | { 53 | $this->record->setSilence(5); 54 | $this->record->setMaxDuration(10); 55 | 56 | $this->assertEquals("Record(/tmp/hello-world.wav,5,10)", $this->record->toString()); 57 | } 58 | 59 | public function testWithSilenceAndOptions() 60 | { 61 | $this->record->setSilence(5); 62 | $this->record->setOptions(['a', 'q', 's']); 63 | 64 | $this->assertEquals("Record(/tmp/hello-world.wav,5,,aqs)", $this->record->toString()); 65 | } 66 | 67 | public function testWithMaxDurationAndOptions() 68 | { 69 | $this->record->setMaxDuration(10); 70 | $this->record->setOptions(['a', 'q', 's']); 71 | 72 | $this->assertEquals("Record(/tmp/hello-world.wav,,10,aqs)", $this->record->toString()); 73 | } 74 | 75 | public function testWithSilenceAndMaxDurationAndOptions() 76 | { 77 | $this->record->setSilence(5); 78 | $this->record->setMaxDuration(10); 79 | $this->record->setOptions(['a', 'q', 's']); 80 | 81 | $this->assertEquals("Record(/tmp/hello-world.wav,5,10,aqs)", $this->record->toString()); 82 | } 83 | } -------------------------------------------------------------------------------- /tests/Application/ExecIfTest.php: -------------------------------------------------------------------------------- 1 | getMock(); 21 | 22 | $applicationMock 23 | ->expects($this->any()) 24 | ->method('toString') 25 | ->willReturn('Answer'); 26 | 27 | $this->execIf = new ExecIf($this->expression, $applicationMock); 28 | } 29 | 30 | public function testGetName() 31 | { 32 | $this->assertEquals('ExecIf', $this->execIf->getName()); 33 | } 34 | 35 | public function testGetData() 36 | { 37 | $expected = $this->expression . '?Answer'; 38 | $this->assertEquals($expected, $this->execIf->getData()); 39 | } 40 | 41 | public function testOnlyTrueToString() 42 | { 43 | $expected = "ExecIf({$this->expression}?Answer)"; 44 | $this->assertEquals($expected, $this->execIf->toString()); 45 | } 46 | 47 | public function testWithFalseData() 48 | { 49 | $noOpApplication = $this->getMock('Clearvox\Asterisk\Dialplan\Application\ApplicationInterface'); 50 | $noOpApplication 51 | ->expects($this->once()) 52 | ->method('toString') 53 | ->willReturn('NoOp(Answered)'); 54 | 55 | $this->execIf->setFalse($noOpApplication); 56 | 57 | $expected = $this->expression . '?Answer:NoOp(Answered)'; 58 | $this->assertEquals($expected, $this->execIf->getData()); 59 | } 60 | 61 | public function testWithFalseString() 62 | { 63 | $noOpApplication = $this->getMock('Clearvox\Asterisk\Dialplan\Application\ApplicationInterface'); 64 | $noOpApplication 65 | ->expects($this->once()) 66 | ->method('toString') 67 | ->willReturn('NoOp(Answered)'); 68 | 69 | $this->execIf->setFalse($noOpApplication); 70 | 71 | $expected = "ExecIf({$this->expression}?Answer:NoOp(Answered))"; 72 | $this->assertEquals($expected, $this->execIf->toString()); 73 | } 74 | 75 | private function getMock() 76 | { 77 | return $this->getMockBuilder(ApplicationInterface::class) 78 | ->disableOriginalConstructor() 79 | ->getMock(); 80 | } 81 | } -------------------------------------------------------------------------------- /tests/Reader/source-examples/advanced-dialplan.txt: -------------------------------------------------------------------------------- 1 | [ea91e4f9-633c-4fa6-b357-438078ecf585] 2 | exten => s,1,CELGenUserEvent(INTO_ACCOUNT_INCOMING_ROUTER_SECTION,begin) 3 | exten => s,2,Gosub(28ccbc96-9290-4610-9601-d64e6f9bb31a,s,1) 4 | exten => s,3,GotoIf($["${PASSES}"="true"]?s-f13acc23bb3b4bcf815ec197e2ff39fe:e-f13acc23bb3b4bcf815ec197e2ff39fe) 5 | exten => s,4(s-f13acc23bb3b4bcf815ec197e2ff39fe),NoOp(Starting Passing commands) 6 | exten => s,5,ExecIf($["${IS_ANSWERED}" == ""]?Answer(400)) 7 | exten => s,6,Set(IS_ANSWERED=true) 8 | exten => s,7,Playback(8005ec1d-c641-4fe4-bc7b-4fa20f81b517/queuewelkomsuppSoraya) 9 | exten => s,8,Set(_QUEUE_ID=7192f255-d799-4400-b1e9-6c2b7f3af5a9) 10 | exten => s,9,Gosub(7192f255-d799-4400-b1e9-6c2b7f3af5a9-variables,s,1) 11 | exten => s,10,ExecIf($["${IS_ANSWERED}" == ""]?Answer(400)) 12 | exten => s,11,Set(IS_ANSWERED=true) 13 | exten => s,12,ExecIf($[${QUEUE_MEMBER(7192f255-d799-4400-b1e9-6c2b7f3af5a9,logged)}]?Queue(7192f255-d799-4400-b1e9-6c2b7f3af5a9,${QUEUE_FORCE_RING}${QUEUE_RING_IF_AVAILABLE},,,3600,,,on_answer)) 14 | exten => s,13(e-f13acc23bb3b4bcf815ec197e2ff39fe),NoOp(Ending If) 15 | exten => s,14,GosubIf($[${DIALPLAN_EXISTS(ea91e4f9-633c-4fa6-b357-438078ecf585,after,a-f13acc23bb3b4bcf815ec197e2ff39fe)}=1]?ea91e4f9-633c-4fa6-b357-438078ecf585,after,a-f13acc23bb3b4bcf815ec197e2ff39fe) 16 | exten => s,15,Gosub(d417d990-5098-4c8c-b72e-65c06ae463a8,s,1) 17 | exten => s,16,GotoIf($["${PASSES}"="true"]?s-1bedaaf78690474b9251b8f1a5a6dfb9:e-1bedaaf78690474b9251b8f1a5a6dfb9) 18 | exten => s,17(s-1bedaaf78690474b9251b8f1a5a6dfb9),NoOp(Starting Passing commands) 19 | exten => s,18,Goto(6e14741a-50d7-44b6-a891-99883141d2d2,s,1) 20 | exten => s,19,NoOp(Return Point) 21 | exten => s,20(e-1bedaaf78690474b9251b8f1a5a6dfb9),NoOp(Ending If) 22 | exten => s,21,GosubIf($[${DIALPLAN_EXISTS(ea91e4f9-633c-4fa6-b357-438078ecf585,after,a-1bedaaf78690474b9251b8f1a5a6dfb9)}=1]?ea91e4f9-633c-4fa6-b357-438078ecf585,after,a-1bedaaf78690474b9251b8f1a5a6dfb9) 23 | exten => s,22,Gosub(ccd6594c-b970-4fef-a293-e11dd864c93b,s,1) 24 | exten => s,23,GotoIf($["${PASSES}"="true"]?s-8e50bf1cc8324d8b802e2b287554d039:e-8e50bf1cc8324d8b802e2b287554d039) 25 | exten => s,24(s-8e50bf1cc8324d8b802e2b287554d039),NoOp(Starting Passing commands) 26 | exten => s,25,Goto(7891c073-83d2-4118-86c4-6e664725b63b,s,1) 27 | exten => s,26,NoOp(Return Point) 28 | exten => s,27(e-8e50bf1cc8324d8b802e2b287554d039),NoOp(Ending If) 29 | exten => s,28,GosubIf($[${DIALPLAN_EXISTS(ea91e4f9-633c-4fa6-b357-438078ecf585,after,a-8e50bf1cc8324d8b802e2b287554d039)}=1]?ea91e4f9-633c-4fa6-b357-438078ecf585,after,a-8e50bf1cc8324d8b802e2b287554d039) -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Stasis.php: -------------------------------------------------------------------------------- 1 | application = $application; 21 | } 22 | 23 | /** 24 | * Return the given applicatoin for this Stasis application 25 | * 26 | * @return string 27 | */ 28 | public function getCommand() 29 | { 30 | return $this->application; 31 | } 32 | 33 | /** 34 | * Add an argument to this Stasis application. 35 | * 36 | * @param string $argument 37 | * @return $this 38 | */ 39 | public function addArgument($argument) 40 | { 41 | $this->arguments[] = $argument; 42 | return $this; 43 | } 44 | 45 | /** 46 | * Get all arguments for this Stasis application. 47 | * 48 | * @return array 49 | */ 50 | public function getArguments() 51 | { 52 | return $this->arguments; 53 | } 54 | 55 | /** 56 | * Should return the name of the application 57 | * 58 | * @return string 59 | */ 60 | public function getName() 61 | { 62 | return 'Stasis'; 63 | } 64 | 65 | /** 66 | * Should return the AppData. AppData is the string contents 67 | * between the () of the App. 68 | * 69 | * @return string 70 | */ 71 | public function getData() 72 | { 73 | $data = $this->application; 74 | 75 | if ( ! empty($this->arguments)) { 76 | $data .= ','; 77 | $data .= implode(',', $this->arguments); 78 | } 79 | 80 | return $data; 81 | } 82 | 83 | /** 84 | * Turns this application into an Array 85 | * 86 | * @return array 87 | */ 88 | public function toArray() 89 | { 90 | return array( 91 | 'application' => $this->application, 92 | 'arguments' => $this->arguments 93 | ); 94 | } 95 | 96 | /** 97 | * Turns this Application into a json representation 98 | * 99 | * @param int $options 100 | * @return string 101 | */ 102 | public function toJson($options = 0) 103 | { 104 | return json_encode($this->toArray(), $options); 105 | } 106 | } -------------------------------------------------------------------------------- /tests/Application/PickupTest.php: -------------------------------------------------------------------------------- 1 | pickup = new Pickup(); 18 | } 19 | 20 | public function testGetName() 21 | { 22 | $this->assertEquals('Pickup', $this->pickup->getName()); 23 | } 24 | 25 | public function testConstructorWithExtension() 26 | { 27 | $pickup = new Pickup('100@PICKUPMARK'); 28 | $this->assertEquals(['100@PICKUPMARK'], $pickup->getExtensions()); 29 | } 30 | 31 | public function testAddExtension() 32 | { 33 | $this->assertEquals([], $this->pickup->getExtensions()); 34 | 35 | $this->pickup->addExtension('101@PICKUPMARK'); 36 | 37 | $this->assertEquals(['101@PICKUPMARK'], $this->pickup->getExtensions()); 38 | 39 | $this->pickup->addExtension('102@PICKUPMARK'); 40 | 41 | $this->assertEquals(['101@PICKUPMARK', '102@PICKUPMARK'], $this->pickup->getExtensions()); 42 | } 43 | 44 | public function testGetData() 45 | { 46 | $this->pickup 47 | ->addExtension('201@PICKUPMARK') 48 | ->addExtension('202@PICKUPMARK') 49 | ->addExtension('203@PICKUPMARK'); 50 | 51 | $expected = "201@PICKUPMARK&202@PICKUPMARK&203@PICKUPMARK"; 52 | 53 | $this->assertEquals($expected, $this->pickup->getData()); 54 | } 55 | 56 | public function testToArray() 57 | { 58 | $this->pickup 59 | ->addExtension('301@PICKUPMARK') 60 | ->addExtension('302@PICKUPMARK'); 61 | 62 | $expected = [ 63 | 'extensions' => ['301@PICKUPMARK', '302@PICKUPMARK'] 64 | ]; 65 | 66 | $this->assertEquals($expected, $this->pickup->toArray()); 67 | } 68 | 69 | public function testToJson() 70 | { 71 | $this->pickup 72 | ->addExtension('301@PICKUPMARK') 73 | ->addExtension('302@PICKUPMARK'); 74 | 75 | $expected = [ 76 | 'extensions' => ['301@PICKUPMARK', '302@PICKUPMARK'] 77 | ]; 78 | 79 | $this->assertEquals(json_encode($expected), $this->pickup->toJson()); 80 | } 81 | 82 | public function testToString() 83 | { 84 | $this->pickup 85 | ->addExtension('500@internal') 86 | ->addExtension('500@external'); 87 | 88 | $expected = 'Pickup(500@internal&500@external)'; 89 | 90 | $this->assertEquals($expected, $this->pickup->toString()); 91 | } 92 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Reader/Reader.php: -------------------------------------------------------------------------------- 1 | lines = $lines; 27 | 28 | // Register the default closures 29 | $this->onStartContextClosure = function($line) { 30 | $contextName = str_replace(['[', ']'], '', $line); 31 | $extended = false; 32 | 33 | if(strpos($contextName, '(+)') !== false) { 34 | $contextName = str_replace('(+)', '', $contextName); 35 | $extended = true; 36 | } 37 | 38 | $dialplan = new Dialplan($contextName); 39 | $dialplan->setExtended($extended); 40 | 41 | return $dialplan; 42 | }; 43 | } 44 | 45 | /** 46 | * Read the contents of the string, and return an instance of 47 | * @param string $contents 48 | * @return Dialplan 49 | */ 50 | public function read($contents) 51 | { 52 | $onStartContext = $this->onStartContextClosure; 53 | 54 | $lines = explode(PHP_EOL, $contents); 55 | 56 | $dialplan = null; 57 | 58 | foreach ($lines as $line) { 59 | // Starting 60 | if(strpos($line, '[') === 0) { 61 | $dialplan = $onStartContext($line); 62 | } 63 | 64 | // Match the lines 65 | foreach($this->lines as $lineReader) { 66 | $matches = []; 67 | 68 | if(preg_match($lineReader->getMatchFormat(), $line, $matches)) { 69 | $dialplan->addLine($lineReader->getInstance($matches)); 70 | } 71 | } 72 | } 73 | 74 | if(is_null($dialplan)) { 75 | // throw exception 76 | } 77 | 78 | return $dialplan; 79 | } 80 | 81 | /** 82 | * Override what should happen when a context is found from 83 | * the read function. It should return an instance of the 84 | * Dialplan class to work correctly. 85 | * 86 | * @param Closure $closure 87 | * @return $this 88 | */ 89 | public function onStartContext(Closure $closure) 90 | { 91 | $this->onStartContextClosure = $closure; 92 | return $this; 93 | } 94 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/MinivmMWI.php: -------------------------------------------------------------------------------- 1 | account = $account; 31 | $this->urgent = $urgent; 32 | $this->new = $new; 33 | $this->old = $old; 34 | } 35 | 36 | /** 37 | * @return mixed 38 | */ 39 | public function getAccount() 40 | { 41 | return $this->account; 42 | } 43 | 44 | /** 45 | * @return mixed 46 | */ 47 | public function getUrgent() 48 | { 49 | return $this->urgent; 50 | } 51 | 52 | /** 53 | * @return mixed 54 | */ 55 | public function getNew() 56 | { 57 | return $this->new; 58 | } 59 | 60 | /** 61 | * @return mixed 62 | */ 63 | public function getOld() 64 | { 65 | return $this->old; 66 | } 67 | 68 | /** 69 | * Should return the name of the application 70 | * 71 | * @return string 72 | */ 73 | public function getName() 74 | { 75 | return 'MinivmMWI'; 76 | } 77 | 78 | /** 79 | * Should return the AppData. AppData is the string contents 80 | * between the () of the App. 81 | * 82 | * @return string 83 | */ 84 | public function getData() 85 | { 86 | $data = $this->account; 87 | 88 | $data .= ',' . $this->urgent; 89 | $data .= ',' . $this->new; 90 | $data .= ',' . $this->old; 91 | 92 | return $data; 93 | } 94 | 95 | /** 96 | * Turns this application into an Array 97 | * 98 | * @return array 99 | */ 100 | public function toArray() 101 | { 102 | return [ 103 | 'account' => $this->account, 104 | 'urgent' => $this->urgent, 105 | 'new' => $this->new, 106 | 'old' => $this->old 107 | ]; 108 | } 109 | 110 | /** 111 | * Turns this Application into a json representation 112 | * 113 | * @param int $options 114 | * @return string 115 | */ 116 | public function toJson($options = 0) 117 | { 118 | return json_encode($this->toArray(), $options); 119 | } 120 | 121 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Realtime.php: -------------------------------------------------------------------------------- 1 | context = $context; 24 | $this->family = $family; 25 | $this->options = $options; 26 | } 27 | 28 | /** 29 | * @return null|string 30 | */ 31 | public function getContext() 32 | { 33 | return $this->context; 34 | } 35 | 36 | /** 37 | * @return null|string 38 | */ 39 | public function getFamily() 40 | { 41 | return $this->family; 42 | } 43 | 44 | /** 45 | * @return array 46 | */ 47 | public function getOptions() 48 | { 49 | return $this->options; 50 | } 51 | 52 | /** 53 | * Should return the name of the application 54 | * 55 | * @return string 56 | */ 57 | public function getName() 58 | { 59 | return 'Realtime'; 60 | } 61 | 62 | /** 63 | * Should return the AppData. AppData is the string contents 64 | * between the () of the App. 65 | * 66 | * @return string 67 | */ 68 | public function getData() 69 | { 70 | $data = $this->context . '@' . $this->family; 71 | 72 | if (!empty($this->options)) { 73 | $data .= '/' . implode('', $this->options); 74 | } 75 | 76 | return $data; 77 | } 78 | 79 | /** 80 | * The string representation of the Application. 81 | * 82 | * @return string 83 | */ 84 | public function toString() 85 | { 86 | return $this->getName() . '/' . $this->getData(); 87 | } 88 | 89 | /** 90 | * Turns this application into an Array 91 | * 92 | * @return array 93 | */ 94 | public function toArray() 95 | { 96 | return array( 97 | 'context' => $this->context, 98 | 'family' => $this->family, 99 | 'options' => $this->options 100 | ); 101 | } 102 | 103 | /** 104 | * Turns this Application into a json representation 105 | * 106 | * @param int $options 107 | * @return string 108 | */ 109 | public function toJson($options = 0) 110 | { 111 | return json_encode($this->toArray(), $options); 112 | } 113 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/GosubIf.php: -------------------------------------------------------------------------------- 1 | condition = $condition; 26 | $this->true = $true; 27 | $this->false = $false; 28 | } 29 | 30 | /** 31 | * @return string 32 | */ 33 | public function getCondition() 34 | { 35 | return $this->condition; 36 | } 37 | 38 | /** 39 | * @return Go|null 40 | */ 41 | public function getFalse() 42 | { 43 | return $this->false; 44 | } 45 | 46 | /** 47 | * @return Go|null 48 | */ 49 | public function getTrue() 50 | { 51 | return $this->true; 52 | } 53 | 54 | /** 55 | * Should return the name of the application 56 | * 57 | * @return string 58 | */ 59 | public function getName() 60 | { 61 | return 'GosubIf'; 62 | } 63 | 64 | /** 65 | * Should return the AppData. AppData is the string contents 66 | * between the () of the App. 67 | * 68 | * @return string 69 | */ 70 | public function getData() 71 | { 72 | $data = ''; 73 | 74 | $data .= $this->condition . '?'; 75 | 76 | if (isset($this->true)) { 77 | $data .= $this->true->getData(); 78 | } 79 | 80 | if (isset($this->false)) { 81 | $data .= ':' . $this->false->getData(); 82 | } 83 | 84 | return $data; 85 | } 86 | 87 | /** 88 | * Turns this application into an Array 89 | * 90 | * @return array 91 | */ 92 | public function toArray() 93 | { 94 | $array = array( 95 | 'condition' => $this->condition 96 | ); 97 | 98 | if(isset($this->true)) { 99 | $array['true'] = $this->true; 100 | } 101 | 102 | if(isset($this->false)) { 103 | $array['false'] = $this->false; 104 | } 105 | 106 | return $array; 107 | } 108 | 109 | /** 110 | * Turns this Application into a json representation 111 | * 112 | * @param int $options 113 | * @return string 114 | */ 115 | public function toJson($options = 0) 116 | { 117 | return json_encode($this->toArray(), $options); 118 | } 119 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/PickupChan.php: -------------------------------------------------------------------------------- 1 | if ringing. 6 | * 7 | * @author Leon Rowland 8 | */ 9 | class PickupChan implements ApplicationInterface 10 | { 11 | use StandardApplicationTrait; 12 | 13 | /** 14 | * @var array 15 | */ 16 | protected $channels = []; 17 | 18 | /** 19 | * @var array 20 | */ 21 | protected $options = []; 22 | 23 | /** 24 | * PickupChan constructor. 25 | * @param $channel 26 | * @param array $otherChannels 27 | */ 28 | public function __construct($channel, $otherChannels = []) 29 | { 30 | $this->channels = array_unique( 31 | array_merge((array)$channel, (array)$otherChannels) 32 | ); 33 | } 34 | 35 | /** 36 | * Get all channels. 37 | * 38 | * @return array 39 | */ 40 | public function getChannels() 41 | { 42 | return $this->channels; 43 | } 44 | 45 | /** 46 | * Set options on this command. 47 | * 48 | * @param string|array $options 49 | * @return $this 50 | */ 51 | public function setOptions($options) 52 | { 53 | $this->options = (array)$options; 54 | return $this; 55 | } 56 | 57 | public function getOptions() 58 | { 59 | return $this->options; 60 | } 61 | 62 | /** 63 | * Should return the name of the application 64 | * 65 | * @return string 66 | */ 67 | public function getName() 68 | { 69 | return 'PickupChan'; 70 | } 71 | 72 | /** 73 | * Should return the AppData. AppData is the string contents 74 | * between the () of the App. 75 | * 76 | * @return string 77 | */ 78 | public function getData() 79 | { 80 | $data = ''; 81 | 82 | $data .= implode('&', $this->channels); 83 | 84 | if (!empty($this->options)) { 85 | $data .= ',' . implode('', $this->options); 86 | } 87 | 88 | return $data; 89 | } 90 | 91 | /** 92 | * Turns this application into an Array 93 | * 94 | * @return array 95 | */ 96 | public function toArray() 97 | { 98 | return [ 99 | 'channels' => $this->channels, 100 | 'options' => $this->options, 101 | ]; 102 | } 103 | 104 | /** 105 | * Turns this Application into a json representation 106 | * 107 | * @param int $options 108 | * @return string 109 | */ 110 | public function toJson($options = 0) 111 | { 112 | return json_encode($this->toArray(), $options); 113 | } 114 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Go.php: -------------------------------------------------------------------------------- 1 | priority = $priority; 33 | $this->extensions = $extensions; 34 | $this->context = $context; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public function getContext() 41 | { 42 | return $this->context; 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | public function getExtensions() 49 | { 50 | return $this->extensions; 51 | } 52 | 53 | /** 54 | * @return int 55 | */ 56 | public function getPriority() 57 | { 58 | return $this->priority; 59 | } 60 | 61 | /** 62 | * Should return the name of the application 63 | * 64 | * @return string 65 | */ 66 | public function getName() 67 | { 68 | return 'Goto'; 69 | } 70 | 71 | /** 72 | * Should return the AppData. AppData is the string contents 73 | * between the () of the App. 74 | * 75 | * @return string 76 | */ 77 | public function getData() 78 | { 79 | $data = $this->priority; 80 | 81 | if (isset($this->extensions)) { 82 | $data = $this->extensions . ',' . $data; 83 | } 84 | 85 | if (isset($this->context)) { 86 | $data = $this->context . ',' . $data; 87 | } 88 | 89 | return $data; 90 | } 91 | 92 | /** 93 | * Turns this application into an Array 94 | * 95 | * @return array 96 | */ 97 | public function toArray() 98 | { 99 | return array( 100 | 'priority' => $this->priority, 101 | 'extensions' => $this->extensions, 102 | 'context' => $this->context 103 | ); 104 | } 105 | 106 | /** 107 | * Turns this Application into a json representation 108 | * 109 | * @param int $options 110 | * @return string 111 | */ 112 | public function toJson($options = 0) 113 | { 114 | return json_encode($this->toArray(), $options); 115 | } 116 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/GotoIf.php: -------------------------------------------------------------------------------- 1 | condition = $condition; 26 | $this->true = $true; 27 | $this->false = $false; 28 | } 29 | 30 | /** 31 | * @return string 32 | */ 33 | public function getCondition() 34 | { 35 | return $this->condition; 36 | } 37 | 38 | /** 39 | * @return \Clearvox\Asterisk\Dialplan\Application\Go 40 | */ 41 | public function getFalse() 42 | { 43 | return $this->false; 44 | } 45 | 46 | /** 47 | * @return \Clearvox\Asterisk\Dialplan\Application\Go 48 | */ 49 | public function getTrue() 50 | { 51 | return $this->true; 52 | } 53 | 54 | /** 55 | * Should return the name of the application 56 | * 57 | * @return string 58 | */ 59 | public function getName() 60 | { 61 | return 'GotoIf'; 62 | } 63 | 64 | /** 65 | * Should return the AppData. AppData is the string contents 66 | * between the () of the App. 67 | * 68 | * @return string 69 | */ 70 | public function getData() 71 | { 72 | $data = ''; 73 | 74 | $data .= $this->condition . '?'; 75 | 76 | if (isset($this->true)) { 77 | $data .= $this->true->getData(); 78 | } 79 | 80 | if (isset($this->false)) { 81 | $data .= ':' . $this->false->getData(); 82 | } 83 | 84 | return $data; 85 | } 86 | 87 | /** 88 | * Turns this application into an Array 89 | * 90 | * @return array 91 | */ 92 | public function toArray() 93 | { 94 | $array = array( 95 | 'condition' => $this->condition, 96 | ); 97 | 98 | if (isset($this->true)) { 99 | $array['true'] = $this->true->toArray(); 100 | } 101 | 102 | if (isset($this->false)) { 103 | $array['false'] = $this->false->toArray(); 104 | } 105 | 106 | return $array; 107 | } 108 | 109 | /** 110 | * Turns this Application into a json representation 111 | * 112 | * @param int $options 113 | * @return string 114 | */ 115 | public function toJson($options = 0) 116 | { 117 | return json_encode($this->toArray(), $options); 118 | } 119 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/CELGenUserEvent.php: -------------------------------------------------------------------------------- 1 | eventName = $eventName; 30 | $this->extra = $extra; 31 | } 32 | 33 | /** 34 | * Get the name of the event give for this CELGenUserEvent 35 | * 36 | * @return string 37 | */ 38 | public function getEventName() 39 | { 40 | return $this->eventName; 41 | } 42 | 43 | /** 44 | * Extra text to be included with the event. 45 | * 46 | * @param string $extra 47 | * @return $this 48 | */ 49 | public function setExtra($extra) 50 | { 51 | $this->extra = $extra; 52 | return $this; 53 | } 54 | 55 | /** 56 | * Return the extra text set to be included with this event. 57 | * 58 | * @return null|string 59 | */ 60 | public function getExtra() 61 | { 62 | return $this->extra; 63 | } 64 | 65 | /** 66 | * Should return the name of the application 67 | * 68 | * @return string 69 | */ 70 | public function getName() 71 | { 72 | return 'CELGenUserEvent'; 73 | } 74 | 75 | /** 76 | * Should return the AppData. AppData is the string contents 77 | * between the () of the App. 78 | * 79 | * @return string 80 | */ 81 | public function getData() 82 | { 83 | $data = $this->eventName; 84 | 85 | if(isset($this->extra)) { 86 | $data .= ',' . $this->extra; 87 | } 88 | 89 | return $data; 90 | } 91 | 92 | /** 93 | * Turns this application into an Array 94 | * 95 | * @return array 96 | */ 97 | public function toArray() 98 | { 99 | return [ 100 | 'event_name' => $this->eventName, 101 | 'extra' => $this->extra 102 | ]; 103 | } 104 | 105 | /** 106 | * Turns this Application into a json representation 107 | * 108 | * @param int $options 109 | * @return string 110 | */ 111 | public function toJson($options = 0) 112 | { 113 | return json_encode($this->toArray(), $options); 114 | } 115 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Set.php: -------------------------------------------------------------------------------- 1 | name = $this->preparedName = $name; 32 | $this->value = $value; 33 | } 34 | 35 | /** 36 | * Will make the variable inherit into channels created from the current channel. 37 | * 38 | * @return $this 39 | */ 40 | public function inherit() 41 | { 42 | $this->preparedName = '_' . $this->name; 43 | return $this; 44 | } 45 | 46 | /** 47 | * Will make the variable inherit into channels created from the current channel 48 | * and all children channels. 49 | * 50 | * @return $this 51 | */ 52 | public function inheritChildren() 53 | { 54 | $this->preparedName = '__' . $this->name; 55 | return $this; 56 | } 57 | 58 | /** 59 | * @return string 60 | */ 61 | public function getPreparedName() 62 | { 63 | return $this->preparedName; 64 | } 65 | 66 | /** 67 | * @return string 68 | */ 69 | public function getValue() 70 | { 71 | return $this->value; 72 | } 73 | 74 | /** 75 | * Should return the name of the application 76 | * 77 | * @return string 78 | */ 79 | public function getName() 80 | { 81 | return 'Set'; 82 | } 83 | 84 | /** 85 | * Should return the AppData. AppData is the string contents 86 | * between the () of the App. 87 | * 88 | * @return string 89 | */ 90 | public function getData() 91 | { 92 | return $this->preparedName . '=' . $this->value; 93 | } 94 | 95 | /** 96 | * Turns this application into an Array 97 | * 98 | * @return array 99 | */ 100 | public function toArray() 101 | { 102 | return array( 103 | 'name' => $this->preparedName, 104 | 'value' => $this->value 105 | ); 106 | } 107 | 108 | /** 109 | * Turns this Application into a json representation 110 | * 111 | * @param int $options 112 | * @return string 113 | */ 114 | public function toJson($options = 0) 115 | { 116 | return json_encode($this->toArray(), $options); 117 | } 118 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/RemoveQueueMember.php: -------------------------------------------------------------------------------- 1 | queueName = $queueName; 32 | } 33 | 34 | /** 35 | * @return string 36 | */ 37 | public function getQueueName() 38 | { 39 | return $this->queueName; 40 | } 41 | 42 | /** 43 | * @return string 44 | */ 45 | public function getInterface() 46 | { 47 | return $this->interface; 48 | } 49 | 50 | /** 51 | * Set the interface to remove from the queue, if not set, will remove 52 | * the current interface. 53 | * 54 | * @param string $interface 55 | * @return RemoveQueueMember 56 | */ 57 | public function setInterface($interface) 58 | { 59 | $this->interface = $interface; 60 | return $this; 61 | } 62 | 63 | /** 64 | * Should return the name of the application 65 | * 66 | * @return string 67 | */ 68 | public function getName() 69 | { 70 | return 'RemoveQueueMember'; 71 | } 72 | 73 | /** 74 | * Should return the AppData. AppData is the string contents 75 | * between the () of the App. 76 | * 77 | * @return string 78 | */ 79 | public function getData() 80 | { 81 | $line = array(); 82 | 83 | if (isset($this->interface)) { 84 | $line[0] = $this->interface; 85 | } 86 | 87 | $line[1] = $this->queueName; 88 | 89 | return implode(',', array_reverse($line)); 90 | } 91 | 92 | /** 93 | * Turns this application into an Array 94 | * 95 | * @return array 96 | */ 97 | public function toArray() 98 | { 99 | return [ 100 | 'name' => $this->queueName, 101 | 'interface' => $this->interface, 102 | ]; 103 | } 104 | 105 | /** 106 | * Turns this Application into a json representation 107 | * 108 | * @param int $options 109 | * @return string 110 | */ 111 | public function toJson($options = 0) 112 | { 113 | return json_encode($this->toArray(), $options); 114 | } 115 | } -------------------------------------------------------------------------------- /tests/Application/PlaybackTest.php: -------------------------------------------------------------------------------- 1 | playback = new Playback("agent-login"); 18 | } 19 | 20 | public function testNameIsCorrect() 21 | { 22 | $this->assertEquals("Playback", $this->playback->getName()); 23 | } 24 | 25 | public function testWithOnlyRequiredParameters() 26 | { 27 | $this->assertEquals("Playback(agent-login)", $this->playback->toString()); 28 | } 29 | 30 | public function testWithMoreSoundFiles() 31 | { 32 | $this->playback 33 | ->addFile('agent-logout') 34 | ->addFile('sound3'); 35 | 36 | $this->assertEquals( 37 | "Playback(agent-login&agent-logout&sound3)", 38 | $this->playback->toString() 39 | ); 40 | } 41 | 42 | public function testWithOnlyRequiredAndSkip() 43 | { 44 | $this->playback->setSkip(true); 45 | $this->assertEquals("Playback(agent-login,skip)", $this->playback->toString()); 46 | } 47 | 48 | public function testWithOnlyRequiredAndNoAnswer() 49 | { 50 | $this->playback->setNoAnswer(true); 51 | $this->assertEquals("Playback(agent-login,noanswer)", $this->playback->toString()); 52 | } 53 | 54 | public function testWithOnlyRequiredAndBothOptions() 55 | { 56 | $this->playback 57 | ->setSkip(true) 58 | ->setNoAnswer(true); 59 | 60 | $this->assertEquals("Playback(agent-login,skip,noanswer)", $this->playback->toString()); 61 | } 62 | 63 | public function testWithMultipleAndSkip() 64 | { 65 | $this->playback 66 | ->addFile('agent-logout') 67 | ->addFile('sound3') 68 | ->setSkip(true); 69 | 70 | $this->assertEquals( 71 | "Playback(agent-login&agent-logout&sound3,skip)", 72 | $this->playback->toString() 73 | ); 74 | } 75 | 76 | public function testWithMultipleAndNoAnswer() 77 | { 78 | $this->playback 79 | ->addFile('agent-logout') 80 | ->addFile('sound3') 81 | ->setNoAnswer(true); 82 | 83 | $this->assertEquals( 84 | "Playback(agent-login&agent-logout&sound3,noanswer)", 85 | $this->playback->toString() 86 | ); 87 | } 88 | 89 | public function testWithMultipleAndBothOptions() 90 | { 91 | $this->playback 92 | ->addFile('agent-logout') 93 | ->addFile('sound3') 94 | ->setNoAnswer(true) 95 | ->setSkip(true); 96 | 97 | $this->assertEquals( 98 | "Playback(agent-login&agent-logout&sound3,skip,noanswer)", 99 | $this->playback->toString() 100 | ); 101 | } 102 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/WaitExten.php: -------------------------------------------------------------------------------- 1 | . 8 | * WARNING!!!: Use of the application 'WaitExten' within a macro will not 9 | * function as expected. Please use the 'Read' application in 10 | * order to read DTMF from a channel currently executing a macro. 11 | * 12 | * Class WaitExten 13 | * @package Clearvox\Asterisk\Dialplan\Application 14 | */ 15 | class WaitExten implements ApplicationInterface 16 | { 17 | 18 | use StandardApplicationTrait; 19 | 20 | /** 21 | * @var int 22 | */ 23 | protected $seconds; 24 | 25 | /** 26 | * @var array 27 | */ 28 | protected $options; 29 | 30 | /** 31 | * @return int 32 | */ 33 | public function getSeconds() 34 | { 35 | return $this->seconds; 36 | } 37 | 38 | /** 39 | * @param int $seconds 40 | * @return $this 41 | */ 42 | public function setSeconds($seconds) 43 | { 44 | $this->seconds = $seconds; 45 | return $this; 46 | } 47 | 48 | /** 49 | * @return array 50 | */ 51 | public function getOptions() 52 | { 53 | return $this->options; 54 | } 55 | 56 | /** 57 | * m([x]): Provide music on hold to the caller while waiting for an 58 | * extension. 59 | * x - Specify the class for music on hold. 60 | * *CHANNEL(musicclass) will be used instead if set* 61 | * 62 | * @param array $options 63 | * @return $this 64 | */ 65 | public function setOptions($options) 66 | { 67 | $this->options = $options; 68 | return $this; 69 | } 70 | 71 | /** 72 | * Should return the name of the application 73 | * 74 | * @return string 75 | */ 76 | public function getName() 77 | { 78 | return 'WaitExten'; 79 | } 80 | 81 | /** 82 | * Should return the AppData. AppData is the string contents 83 | * between the () of the App. 84 | * 85 | * @return string 86 | */ 87 | public function getData() 88 | { 89 | $data = ''; 90 | 91 | if ( ! empty($this->seconds)) { 92 | $data .= $this->seconds; 93 | } 94 | 95 | if( ! empty($this->options)) { 96 | $data .= ',' . implode('', $this->options); 97 | } 98 | 99 | return $data; 100 | } 101 | 102 | /** 103 | * Turns this application into an Array 104 | * 105 | * @return array 106 | */ 107 | public function toArray() 108 | { 109 | return [ 110 | 'seconds' => $this->seconds, 111 | 'options' => $this->getOptions() 112 | ]; 113 | } 114 | 115 | /** 116 | * Turns this Application into a json representation 117 | * 118 | * @param int $options 119 | * @return string 120 | */ 121 | public function toJson($options = 0) 122 | { 123 | return json_encode($this->toArray(), $options); 124 | } 125 | 126 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Pickup.php: -------------------------------------------------------------------------------- 1 | targets are specified, the application will pickup a 9 | * channel matching the pickup group of the requesting channel. 10 | * 11 | * 2) If the is specified with a of the special string 12 | * 'PICKUPMARK' (for example 10@PICKUPMARK), the application will pickup a channel 13 | * which has defined the channel variable ${PICKUPMARK} with the same value as 14 | * (in this example, '10'). 15 | * 16 | * 3) If the is specified with or without a , the channel 17 | * with a matching and will be picked up. If no 18 | * is specified, the current context will be used. 19 | * 20 | * NOTE: The is typically set on matching channels by the dial 21 | * application that created the channel. The is set on matching 22 | * channels by the channel driver for the device. 23 | * 24 | * @author Leon Rowland 25 | */ 26 | class Pickup implements ApplicationInterface 27 | { 28 | use StandardApplicationTrait; 29 | 30 | /** 31 | * @var array 32 | */ 33 | protected $extensions = []; 34 | 35 | public function __construct($extension = []) 36 | { 37 | $this->extensions = (array)$extension; 38 | } 39 | 40 | /** 41 | * Add another extension to this pick in the format of 42 | * 43 | * extension[@context] 44 | * 45 | * @param string $extension 46 | * @return $this 47 | */ 48 | public function addExtension($extension) 49 | { 50 | $this->extensions = array_merge($this->extensions, (array)$extension); 51 | return $this; 52 | } 53 | 54 | /** 55 | * Get all extensions set for this application. 56 | * 57 | * @return array 58 | */ 59 | public function getExtensions() 60 | { 61 | return $this->extensions; 62 | } 63 | 64 | /** 65 | * Should return the name of the application 66 | * 67 | * @return string 68 | */ 69 | public function getName() 70 | { 71 | return 'Pickup'; 72 | } 73 | 74 | /** 75 | * Should return the AppData. AppData is the string contents 76 | * between the () of the App. 77 | * 78 | * @return string 79 | */ 80 | public function getData() 81 | { 82 | return implode('&', $this->extensions); 83 | } 84 | 85 | /** 86 | * Turns this application into an Array 87 | * 88 | * @return array 89 | */ 90 | public function toArray() 91 | { 92 | return [ 93 | 'extensions' => (array)$this->extensions, 94 | ]; 95 | } 96 | 97 | /** 98 | * Turns this Application into a json representation 99 | * 100 | * @param int $options 101 | * @return string 102 | */ 103 | public function toJson($options = 0) 104 | { 105 | return json_encode($this->toArray(), $options); 106 | } 107 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/ExecIf.php: -------------------------------------------------------------------------------- 1 | expression = $expression; 29 | $this->true = $true; 30 | $this->false = $false; 31 | } 32 | 33 | public function getExpression() 34 | { 35 | return $this->expression; 36 | } 37 | 38 | /** 39 | * Get the application that should run when this expression is evaluated 40 | * to true. 41 | * 42 | * @return ApplicationInterface 43 | */ 44 | public function getTrue() 45 | { 46 | return $this->true; 47 | } 48 | 49 | /** 50 | * Set the false application for the expression. 51 | * 52 | * @param ApplicationInterface $false 53 | */ 54 | public function setFalse(ApplicationInterface $false) 55 | { 56 | $this->false = $false; 57 | } 58 | 59 | /** 60 | * Get the false application for this ExecIf. There is a chance that this is null 61 | * from not being set. 62 | * 63 | * @return ApplicationInterface|null 64 | */ 65 | public function getFalse() 66 | { 67 | return $this->false; 68 | } 69 | 70 | /** 71 | * Should return the name of the application 72 | * 73 | * @return string 74 | */ 75 | public function getName() 76 | { 77 | return 'ExecIf'; 78 | } 79 | 80 | /** 81 | * Should return the AppData. AppData is the string contents 82 | * between the () of the App. 83 | * 84 | * @return string 85 | */ 86 | public function getData() 87 | { 88 | // Variables 89 | $expression = $this->expression; 90 | $trueString = $this->true->toString(); 91 | 92 | // Prepare the data 93 | $data = "$expression?$trueString"; 94 | 95 | // Add false if its set 96 | if (!is_null($this->false)) { 97 | $falseString = $this->false->toString(); 98 | $data .= ":$falseString"; 99 | } 100 | 101 | return $data; 102 | } 103 | 104 | /** 105 | * Turns this application into an Array 106 | * 107 | * @return array 108 | */ 109 | public function toArray() 110 | { 111 | $data = [ 112 | 'expression' => $this->expression, 113 | 'true' => $this->true->toArray(), 114 | ]; 115 | 116 | if (!is_null($this->false)) { 117 | $data['false'] = $this->false->toArray(); 118 | } 119 | 120 | return $data; 121 | } 122 | 123 | /** 124 | * Turns this Application into a json representation 125 | * 126 | * @param int $options 127 | * @return string 128 | */ 129 | public function toJson($options = 0) 130 | { 131 | return json_encode($this->toArray(), $options); 132 | } 133 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/UserEvent.php: -------------------------------------------------------------------------------- 1 | 6 | * representing additional arguments. The may be specified as a ',' 7 | * delimited list of key:value pairs. 8 | * 9 | * For AMI, each additional argument will be placed on a new line in the event 10 | * and the format of the event will be: 11 | * Event: UserEvent 12 | * UserEvent: 13 | * [body] 14 | * 15 | * If no is specified, only Event and UserEvent headers will be present. 16 | * For res_stasis applications, the event will be provided as a JSON blob with 17 | * additional arguments appearing as keys in the object and the under 18 | * the 'eventname' key. 19 | * 20 | * @author Leon Rowland 21 | */ 22 | class UserEvent implements ApplicationInterface 23 | { 24 | use StandardApplicationTrait; 25 | 26 | /** 27 | * @var string 28 | */ 29 | protected $eventName; 30 | 31 | /** 32 | * @var array 33 | */ 34 | protected $body = array(); 35 | 36 | /** 37 | * Send an arbitrary user-defined event to parties interested in a channel (AMI 38 | * users and relevant res_stasis applications). 39 | * 40 | * @param string $eventName 41 | */ 42 | public function __construct($eventName) 43 | { 44 | $this->eventName = $eventName; 45 | } 46 | 47 | /** 48 | * @return string 49 | */ 50 | public function getEventName() 51 | { 52 | return $this->eventName; 53 | } 54 | 55 | /** 56 | * Add a new Key:Value pair to the Event body. 57 | * 58 | * @param string $key 59 | * @param string $value 60 | * @return $this 61 | */ 62 | public function addBodyPart($key, $value) 63 | { 64 | $this->body[$key] = $value; 65 | return $this; 66 | } 67 | 68 | /** 69 | * @return array 70 | */ 71 | public function getBody() 72 | { 73 | return $this->body; 74 | } 75 | 76 | /** 77 | * Should return the name of the application 78 | * 79 | * @return string 80 | */ 81 | public function getName() 82 | { 83 | return 'UserEvent'; 84 | } 85 | 86 | /** 87 | * Should return the AppData. AppData is the string contents 88 | * between the () of the App. 89 | * 90 | * @return string 91 | */ 92 | public function getData() 93 | { 94 | $data = $this->eventName; 95 | 96 | if( ! empty($this->body)) { 97 | foreach ($this->body as $key => $value) { 98 | $data .= ',' . $key . ': ' . $value; 99 | } 100 | } 101 | 102 | return $data; 103 | } 104 | 105 | /** 106 | * Turns this application into an Array 107 | * 108 | * @return array 109 | */ 110 | public function toArray() 111 | { 112 | return array( 113 | 'event' => $this->eventName, 114 | 'body' => $this->body 115 | ); 116 | } 117 | 118 | /** 119 | * Turns this Application into a json representation 120 | * 121 | * @param int $options 122 | * @return string 123 | */ 124 | public function toJson($options = 0) 125 | { 126 | return json_encode($this->toArray(), $options); 127 | } 128 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Gosub.php: -------------------------------------------------------------------------------- 1 | priority = $priority; 35 | $this->context = $context; 36 | $this->exten = $exten; 37 | $this->arguments = $arguments; 38 | } 39 | 40 | /** 41 | * Return the priority set to go to. 42 | * 43 | * @return string 44 | */ 45 | public function getPriority() 46 | { 47 | return $this->priority; 48 | } 49 | 50 | /** 51 | * Return the context set to go to. 52 | * 53 | * @return string 54 | */ 55 | public function getContext() 56 | { 57 | return $this->context; 58 | } 59 | 60 | /** 61 | * Return the extension/pattern set to go to. 62 | * 63 | * @return string 64 | */ 65 | public function getExten() 66 | { 67 | return $this->exten; 68 | } 69 | 70 | /** 71 | * Return all arguments attached to this GoSub. 72 | * 73 | * @return array 74 | */ 75 | public function getArguments() 76 | { 77 | return $this->arguments; 78 | } 79 | 80 | /** 81 | * Should return the name of the application 82 | * 83 | * @return string 84 | */ 85 | public function getName() 86 | { 87 | return 'Gosub'; 88 | } 89 | 90 | /** 91 | * Should return the AppData. AppData is the string contents 92 | * between the () of the App. 93 | * 94 | * @return string 95 | */ 96 | public function getData() 97 | { 98 | $data = ''; 99 | 100 | // Always add the priority 101 | $data .= $this->priority; 102 | 103 | if (isset($this->context)) { 104 | if(isset($this->exten)) { 105 | $data = $this->context . ',' . $this->exten . ',' . $data; 106 | } else { 107 | $data = $this->context . ',' . $data; 108 | } 109 | } 110 | 111 | if (!empty($this->arguments)) { 112 | $data .= '(' . implode(',', $this->arguments) . ')'; 113 | } 114 | 115 | return $data; 116 | } 117 | 118 | /** 119 | * Turns this application into an Array 120 | * 121 | * @return array 122 | */ 123 | public function toArray() 124 | { 125 | return [ 126 | 'priority' => $this->priority, 127 | 'context' => $this->context, 128 | 'exten' => $this->exten, 129 | 'arguments' => $this->arguments 130 | ]; 131 | } 132 | 133 | /** 134 | * Turns this Application into a json representation 135 | * 136 | * @param int $options 137 | * @return string 138 | */ 139 | public function toJson($options = 0) 140 | { 141 | return json_encode($this->toArray(), $options); 142 | } 143 | } -------------------------------------------------------------------------------- /tests/Application/PickupChanTest.php: -------------------------------------------------------------------------------- 1 | pickupChan = new PickupChan('SIP/phone1'); 18 | } 19 | 20 | public function testNameIsCorrect() 21 | { 22 | $this->assertEquals('PickupChan', $this->pickupChan->getName()); 23 | } 24 | 25 | public function testGetChannelsIsCorrect() 26 | { 27 | $this->assertEquals(['SIP/phone1'], $this->pickupChan->getChannels()); 28 | } 29 | 30 | public function testMultipleChannelsWithStringSecondParameter() 31 | { 32 | $pickupChan = new PickupChan('SIP/phone1', 'SIP/phone2'); 33 | $this->assertEquals([ 34 | 'SIP/phone1', 35 | 'SIP/phone2', 36 | ], $pickupChan->getChannels()); 37 | } 38 | 39 | public function testMultipleChannelsWithArray() 40 | { 41 | $pickupChan = new PickupChan(['SIP/phone1', 'SIP/phone2', 'SIP/phone3']); 42 | $this->assertEquals(['SIP/phone1', 'SIP/phone2', 'SIP/phone3'], $pickupChan->getChannels()); 43 | } 44 | 45 | public function testMultipleChannelsWithArraySecondParameter() 46 | { 47 | $pickupChan = new PickupChan( 48 | ['SIP/phone1', 'SIP/phone2', 'SIP/phone3'], 49 | ['SIP/phone4', 'SIP/phone5', 'SIP/phone1'] 50 | ); 51 | $this->assertEquals( 52 | ['SIP/phone1', 'SIP/phone2', 'SIP/phone3', 'SIP/phone4', 'SIP/phone5'], 53 | $pickupChan->getChannels() 54 | ); 55 | } 56 | 57 | public function testOptions() 58 | { 59 | $this->pickupChan->setOptions('p'); 60 | $this->assertEquals(['p'], $this->pickupChan->getOptions()); 61 | } 62 | 63 | public function testOptionsWithArray() 64 | { 65 | $this->pickupChan->setOptions(['p', 'another', 'option(beep)']); 66 | $this->assertEquals(['p', 'another', 'option(beep)'], $this->pickupChan->getOptions()); 67 | } 68 | 69 | public function testToArray() 70 | { 71 | $pickupChan = new PickupChan('SIP/phone1'); 72 | $pickupChan->setOptions('p'); 73 | 74 | $expected = [ 75 | 'channels' => ['SIP/phone1'], 76 | 'options' => ['p'] 77 | ]; 78 | 79 | $this->assertEquals($expected, $pickupChan->toArray()); 80 | } 81 | 82 | public function testToJson() 83 | { 84 | $pickupChan = new PickupChan('SIP/phone1'); 85 | $pickupChan->setOptions('p'); 86 | 87 | $expected = [ 88 | 'channels' => ['SIP/phone1'], 89 | 'options' => ['p'] 90 | ]; 91 | 92 | $this->assertEquals(json_encode($expected), $pickupChan->toJson()); 93 | } 94 | 95 | public function testSimpleToString() 96 | { 97 | $expected = 'PickupChan(SIP/phone1)'; 98 | $this->assertEquals($expected, $this->pickupChan->toString()); 99 | } 100 | 101 | public function testToString() 102 | { 103 | $pickupChan = new PickupChan('SIP/phone1', ['SIP/phone2', 'SIP/phone3']); 104 | $pickupChan->setOptions('p'); 105 | 106 | $expected = 'PickupChan(SIP/phone1&SIP/phone2&SIP/phone3,p)'; 107 | $this->assertEquals($expected, $pickupChan->toString()); 108 | } 109 | } -------------------------------------------------------------------------------- /tests/Functions/MinivmAccountTest.php: -------------------------------------------------------------------------------- 1 | minivmAccount = new MinivmAccount('test@example.com'); 18 | } 19 | 20 | public function testToString() 21 | { 22 | $this->assertEquals( 23 | 'MINIVMACCOUNT(test@example.com:hasaccount)', 24 | $this->minivmAccount->toString() 25 | ); 26 | } 27 | 28 | public function testMagicMethodString() 29 | { 30 | $this->assertEquals( 31 | 'MINIVMACCOUNT(test@example.com:hasaccount)', 32 | (string)$this->minivmAccount 33 | ); 34 | } 35 | 36 | public function testRequestHasAccount() 37 | { 38 | $this->assertEquals( 39 | 'MINIVMACCOUNT(test@example.com:hasaccount)', 40 | $this->minivmAccount->requestHasAccount() 41 | ); 42 | } 43 | 44 | public function testRequestFullName() 45 | { 46 | $this->assertEquals( 47 | 'MINIVMACCOUNT(test@example.com:fullname)', 48 | $this->minivmAccount->requestFullName() 49 | ); 50 | } 51 | 52 | public function testRequestEmail() 53 | { 54 | $this->assertEquals( 55 | 'MINIVMACCOUNT(test@example.com:email)', 56 | $this->minivmAccount->requestEmail() 57 | ); 58 | } 59 | 60 | public function testRequestETemplate() 61 | { 62 | $this->assertEquals( 63 | 'MINIVMACCOUNT(test@example.com:etemplate)', 64 | $this->minivmAccount->requestETemplate() 65 | ); 66 | } 67 | 68 | public function testRequestPTemplate() 69 | { 70 | $this->assertEquals( 71 | 'MINIVMACCOUNT(test@example.com:ptemplate)', 72 | $this->minivmAccount->requestPTemplate() 73 | ); 74 | } 75 | 76 | public function testRequestAccountCode() 77 | { 78 | $this->assertEquals( 79 | 'MINIVMACCOUNT(test@example.com:accountcode)', 80 | $this->minivmAccount->requestAccountCode() 81 | ); 82 | } 83 | 84 | public function testRequestPath() 85 | { 86 | $this->assertEquals( 87 | 'MINIVMACCOUNT(test@example.com:path)', 88 | $this->minivmAccount->requestPath() 89 | ); 90 | } 91 | 92 | public function testRequestPincode() 93 | { 94 | $this->assertEquals( 95 | 'MINIVMACCOUNT(test@example.com:pincode)', 96 | $this->minivmAccount->requestPinCode() 97 | ); 98 | } 99 | 100 | public function testRequestTimeZone() 101 | { 102 | $this->assertEquals( 103 | 'MINIVMACCOUNT(test@example.com:timezone)', 104 | $this->minivmAccount->requestTimeZone() 105 | ); 106 | } 107 | 108 | public function testRequestLanguage() 109 | { 110 | $this->assertEquals( 111 | 'MINIVMACCOUNT(test@example.com:language)', 112 | $this->minivmAccount->requestLanguage() 113 | ); 114 | } 115 | 116 | public function testRequestCustom() 117 | { 118 | $this->assertEquals( 119 | 'MINIVMACCOUNT(test@example.com:customerclass)', 120 | $this->minivmAccount->requestCustom('customerclass') 121 | ); 122 | } 123 | 124 | 125 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Page.php: -------------------------------------------------------------------------------- 1 | addTarget($technology, $resource); 26 | 27 | $this->timeout = $timeout; 28 | } 29 | 30 | /** 31 | * Should return the name of the application 32 | * 33 | * @return string 34 | */ 35 | public function getName() 36 | { 37 | return 'Page'; 38 | } 39 | 40 | /** 41 | * Add a new target to the Dials. 42 | * 43 | * @param string $technology 44 | * @param string $resource 45 | * @return $this 46 | */ 47 | public function addTarget($technology, $resource) 48 | { 49 | $this->targets[] = [$technology, $resource]; 50 | return $this; 51 | } 52 | 53 | /** 54 | * Get all targets for this Dial. 55 | * 56 | * @return array 57 | */ 58 | public function getTargets() 59 | { 60 | return $this->targets; 61 | } 62 | 63 | /** 64 | * Specify an option flag for this Dial. Requires the timeout 65 | * to be set. 66 | * 67 | * @param string $option 68 | * @return $this 69 | * @throws \InvalidArgumentException 70 | */ 71 | public function addOption($option) 72 | { 73 | $this->options[] = $option; 74 | return $this; 75 | } 76 | 77 | /** 78 | * Get all dial options. 79 | * 80 | * @return array 81 | */ 82 | public function getOptions() 83 | { 84 | return $this->options; 85 | } 86 | 87 | /** 88 | * Should return the AppData. AppData is the string contents 89 | * between the () of the App. 90 | * 91 | * @return string 92 | */ 93 | public function getData() 94 | { 95 | $data = ''; 96 | 97 | if (!empty($this->targets)) { 98 | foreach ($this->targets as $target) { 99 | $data .= '&' . $target[0] . '/' . $target[1]; 100 | } 101 | } 102 | 103 | if (empty($this->options) && !empty($this->timeout)) { 104 | $data .= ','; 105 | }elseif (!empty($this->options)) { 106 | $data .= ','; 107 | foreach ($this->options as $dialOption) { 108 | $data .= $dialOption; 109 | } 110 | } 111 | 112 | if (isset($this->timeout)) { 113 | $data .= ',' . $this->timeout; 114 | } 115 | 116 | return substr($data, 1); 117 | } 118 | 119 | /** 120 | * Turns this application into an Array 121 | * 122 | * @return array 123 | */ 124 | public function toArray() 125 | { 126 | return [ 127 | 'targets' => $this->getTargets(), 128 | 'options' => $this->options, 129 | 'timeout' => $this->timeout, 130 | ]; 131 | } 132 | 133 | /** 134 | * Turns this Application into a json representation 135 | * 136 | * @param int $options 137 | * @return string 138 | */ 139 | public function toJson($options = 0) 140 | { 141 | return json_encode($this->toArray(), $options); 142 | } 143 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Voicemail.php: -------------------------------------------------------------------------------- 1 | addMailbox($mailbox, $context) 22 | ->setOptions($options); 23 | } 24 | 25 | /** 26 | * Adds another mailbox to this voicemail. 27 | * 28 | * @param string $mailbox 29 | * @param string|null $context 30 | * @return $this 31 | */ 32 | public function addMailbox($mailbox, $context = null) 33 | { 34 | $this->mailboxes[] = ['mailbox' => $mailbox, 'context' => $context]; 35 | return $this; 36 | } 37 | 38 | /** 39 | * Return all mailboxes for this voicemail application. 40 | * 41 | * @return array 42 | */ 43 | public function getMailboxes() 44 | { 45 | return $this->mailboxes; 46 | } 47 | 48 | /** 49 | * b: Play the 'busy' greeting to the calling party. 50 | * 51 | * d([c]): Accept digits for a new extension in context , if played 52 | * during the greeting. Context defaults to the current context. 53 | * 54 | * g(#): Use the specified amount of gain when recording the voicemail 55 | * message. The units are whole-number decibels (dB). Only works on supported 56 | * technologies, which is DAHDI only. 57 | * 58 | * s: Skip the playback of instructions for leaving a message to the calling party. 59 | * 60 | * u: Play the 'unavailable' greeting. 61 | * 62 | * U: Mark message as 'URGENT'. 63 | * 64 | * P: Mark message as 'PRIORITY'. 65 | * 66 | * @param array $options 67 | * @return $this 68 | */ 69 | public function setOptions(array $options) 70 | { 71 | $this->options = $options; 72 | return $this; 73 | } 74 | 75 | /** 76 | * Should return the name of the application 77 | * 78 | * @return string 79 | */ 80 | public function getName() 81 | { 82 | return 'Voicemail'; 83 | } 84 | 85 | /** 86 | * Should return the AppData. AppData is the string contents 87 | * between the () of the App. 88 | * 89 | * @return string 90 | */ 91 | public function getData() 92 | { 93 | $data = ''; 94 | 95 | $mailboxes = []; 96 | foreach ($this->mailboxes as $mailbox) { 97 | if(is_null($mailbox['context'])) { 98 | $mailboxes[] = $mailbox['mailbox']; 99 | } else { 100 | $mailboxes[] = $mailbox['mailbox'] . '@' . $mailbox['context']; 101 | } 102 | } 103 | 104 | $data .= implode('&', $mailboxes); 105 | 106 | if(!empty($this->options)) { 107 | $data .= ',' . implode('', $this->options); 108 | } 109 | 110 | return $data; 111 | } 112 | 113 | /** 114 | * Turns this application into an Array 115 | * 116 | * @return array 117 | */ 118 | public function toArray() 119 | { 120 | return [ 121 | 'mailboxes' => $this->mailboxes, 122 | 'options' => $this->options, 123 | ]; 124 | } 125 | 126 | /** 127 | * Turns this Application into a json representation 128 | * 129 | * @param int $options 130 | * @return string 131 | */ 132 | public function toJson($options = 0) 133 | { 134 | return json_encode($this->toArray(), $options); 135 | } 136 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Functions/MinivmAccount.php: -------------------------------------------------------------------------------- 1 | account = $account; 13 | } 14 | 15 | /** 16 | * Return the boolean value if the account is a valid 17 | * voicemail box or not. 18 | * 19 | * @return string 20 | */ 21 | public function requestHasAccount() 22 | { 23 | return $this->getRaw('hasaccount'); 24 | } 25 | 26 | /** 27 | * Return the set fullname on the voicemail box. 28 | * 29 | * @return string 30 | */ 31 | public function requestFullName() 32 | { 33 | return $this->getRaw('fullname'); 34 | } 35 | 36 | /** 37 | * Return the set email on the voicemail box. 38 | * 39 | * @return string 40 | */ 41 | public function requestEmail() 42 | { 43 | return $this->getRaw('email'); 44 | } 45 | 46 | /** 47 | * Return the set pager on the voicemail box. 48 | * 49 | * @return string 50 | */ 51 | public function requestPager() 52 | { 53 | return $this->getRaw('pager'); 54 | } 55 | 56 | /** 57 | * Return the set emplate for this voicemail box. 58 | * 59 | * @return string 60 | */ 61 | public function requestETemplate() 62 | { 63 | return $this->getRaw('etemplate'); 64 | } 65 | 66 | /** 67 | * Return the set ptemplate for this voicemail box. 68 | * 69 | * @return string 70 | */ 71 | public function requestPTemplate() 72 | { 73 | return $this->getRaw('ptemplate'); 74 | } 75 | 76 | /** 77 | * Return the set account code for this voicemail 78 | * account box. 79 | * 80 | * @return string 81 | */ 82 | public function requestAccountCode() 83 | { 84 | return $this->getRaw('accountcode'); 85 | } 86 | 87 | /** 88 | * Return the set path on the voicemail box. 89 | * 90 | * @return string 91 | */ 92 | public function requestPath() 93 | { 94 | return $this->getRaw('path'); 95 | } 96 | 97 | /** 98 | * Return the set pin code on the voicemail box. 99 | * 100 | * @return string 101 | */ 102 | public function requestPinCode() 103 | { 104 | return $this->getRaw('pincode'); 105 | } 106 | 107 | /** 108 | * Return the set timezone on the voicemail box. 109 | * 110 | * @return string 111 | */ 112 | public function requestTimeZone() 113 | { 114 | return $this->getRaw('timezone'); 115 | } 116 | 117 | /** 118 | * Return the set language on the voicemail box. 119 | * 120 | * @return string 121 | */ 122 | public function requestLanguage() 123 | { 124 | return $this->getRaw('language'); 125 | } 126 | 127 | /** 128 | * Request a custom value in the setvar of the 129 | * defined voicemail box. 130 | * 131 | * @param string $custom 132 | * @return string 133 | */ 134 | public function requestCustom($custom) 135 | { 136 | return $this->getRaw($custom); 137 | } 138 | 139 | /** 140 | * Returns the function in its full string representation. 141 | * 142 | * @return string 143 | */ 144 | public function toString() 145 | { 146 | return $this->requestHasAccount(); 147 | } 148 | 149 | /** 150 | * Return the full function definition with the type of data you want 151 | * from the MINIVMACCOUNT function. 152 | * 153 | * @param string $type 154 | * @return string 155 | */ 156 | protected function getRaw($type) 157 | { 158 | return 'MINIVMACCOUNT(' . $this->account . ':' . $type . ')'; 159 | } 160 | } -------------------------------------------------------------------------------- /tests/Application/AddQueueMemberTest.php: -------------------------------------------------------------------------------- 1 | queueMember = new AddQueueMember('support'); 18 | } 19 | 20 | public function testGetName() 21 | { 22 | $this->assertEquals('AddQueueMember', $this->queueMember->getName()); 23 | } 24 | 25 | public function testGetQueueName() 26 | { 27 | $this->assertEquals('support', $this->queueMember->getQueueName()); 28 | } 29 | 30 | public function testGetDataWithNoArguments() 31 | { 32 | $this->assertEquals('support', $this->queueMember->getData()); 33 | } 34 | 35 | public function testGetDataWithInterface() 36 | { 37 | $this->queueMember 38 | ->setInterface('SIP/3000'); 39 | 40 | $this->assertEquals('support,SIP/3000', $this->queueMember->getData()); 41 | } 42 | 43 | public function testGetDataWithInterfacePenalty() 44 | { 45 | $this->queueMember 46 | ->setInterface('SIP/3000') 47 | ->setPenalty(10); 48 | 49 | $this->assertEquals('support,SIP/3000,10', $this->queueMember->getData()); 50 | } 51 | 52 | public function testGetDataWithInterfacePenaltyOptions() 53 | { 54 | $this->queueMember 55 | ->setInterface('SIP/3000') 56 | ->setPenalty(10) 57 | ->setOptions(['j']); 58 | 59 | $this->assertEquals('support,SIP/3000,10,j', $this->queueMember->getData()); 60 | } 61 | 62 | public function testGetDataWithInterfacePenaltyMemberName() 63 | { 64 | $this->queueMember 65 | ->setInterface('SIP/3000') 66 | ->setPenalty(10) 67 | ->setMemberName('john'); 68 | 69 | $this->assertEquals('support,SIP/3000,10,,john', $this->queueMember->getData()); 70 | } 71 | 72 | public function testGetDataWithInterfacePenaltyMemberNameStateInterface() 73 | { 74 | $this->queueMember 75 | ->setInterface('SIP/3000') 76 | ->setPenalty(10) 77 | ->setMemberName('james') 78 | ->setStateInterface('SIP/1000'); 79 | 80 | $this->assertEquals('support,SIP/3000,10,,james,SIP/1000', $this->queueMember->getData()); 81 | } 82 | 83 | public function testGetDataOnlyStateInterface() 84 | { 85 | $this->queueMember 86 | ->setStateInterface('SIP/1000'); 87 | 88 | $this->assertEquals('support,,,,,SIP/1000', $this->queueMember->getData()); 89 | } 90 | 91 | public function testToArray() 92 | { 93 | $this->queueMember 94 | ->setInterface('SIP/3000') 95 | ->setPenalty(10) 96 | ->setOptions(['j']) 97 | ->setMemberName('james') 98 | ->setStateInterface('SIP/1000'); 99 | 100 | $expected = [ 101 | 'name' => 'support', 102 | 'interface' => 'SIP/3000', 103 | 'penalty' => 10, 104 | 'options' => ['j'], 105 | 'member_name' => 'james', 106 | 'state_interface' => 'SIP/1000' 107 | ]; 108 | 109 | $this->assertEquals($expected, $this->queueMember->toArray()); 110 | } 111 | 112 | public function testToJson() 113 | { 114 | $this->queueMember 115 | ->setInterface('SIP/3000') 116 | ->setPenalty(10) 117 | ->setOptions(['j']) 118 | ->setMemberName('james') 119 | ->setStateInterface('SIP/1000'); 120 | 121 | $expected = json_encode([ 122 | 'name' => 'support', 123 | 'interface' => 'SIP/3000', 124 | 'penalty' => 10, 125 | 'options' => ['j'], 126 | 'member_name' => 'james', 127 | 'state_interface' => 'SIP/1000' 128 | ]); 129 | 130 | $this->assertEquals($expected, $this->queueMember->toJson()); 131 | } 132 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Playback.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | class Playback implements ApplicationInterface 24 | { 25 | use StandardApplicationTrait; 26 | 27 | /** 28 | * @var string 29 | */ 30 | protected $filename; 31 | 32 | /** 33 | * @var array 34 | */ 35 | protected $otherFiles = array(); 36 | 37 | /** 38 | * @var bool|null 39 | */ 40 | protected $skip; 41 | 42 | /** 43 | * @var bool|null 44 | */ 45 | protected $noAnswer; 46 | 47 | public function __construct($filename, array $otherFiles = array()) 48 | { 49 | $this->filename = $filename; 50 | $this->otherFiles = $otherFiles; 51 | } 52 | 53 | /** 54 | * Add a file to this playback. 55 | * 56 | * @param string $filename 57 | * @return $this 58 | */ 59 | public function addFile($filename) 60 | { 61 | $this->otherFiles[] = $filename; 62 | return $this; 63 | } 64 | 65 | /** 66 | * If $skip is set to TRUE then "Do not play if not answered" 67 | * 68 | * @param boolean $skip 69 | * @return $this 70 | */ 71 | public function setSkip($skip) 72 | { 73 | $this->skip = (bool) $skip; 74 | return $this; 75 | } 76 | 77 | /** 78 | * If $noAnswer is set to TRUE then "Playback without answering, otherwise the channel will 79 | * be answered before the sound is played." 80 | * 81 | * NOTE: Not all channel types support playing messages while still on hook. 82 | * 83 | * @param boolean $noAnswer 84 | * @return $this 85 | */ 86 | public function setNoAnswer($noAnswer) 87 | { 88 | $this->noAnswer = (bool) $noAnswer; 89 | return $this; 90 | } 91 | 92 | /** 93 | * Should return the name of the application 94 | * 95 | * @return string 96 | */ 97 | public function getName() 98 | { 99 | return 'Playback'; 100 | } 101 | 102 | /** 103 | * Should return the AppData. AppData is the string contents 104 | * between the () of the App. 105 | * 106 | * @return string 107 | */ 108 | public function getData() 109 | { 110 | $data = ''; 111 | 112 | $data .= $this->filename; 113 | 114 | if ( ! empty($this->otherFiles)) { 115 | $data .= "&" . implode('&', $this->otherFiles); 116 | } 117 | 118 | $options = ''; 119 | 120 | if ($this->skip) { 121 | $options .= ",skip"; 122 | } 123 | 124 | if ($this->noAnswer) { 125 | $options .= ",noanswer"; 126 | } 127 | 128 | return $data . $options; 129 | } 130 | 131 | /** 132 | * Turns this application into an Array 133 | * 134 | * @return array 135 | */ 136 | public function toArray() 137 | { 138 | return [ 139 | 'filename' => $this->filename, 140 | 'other_filenames' => $this->otherFiles, 141 | 'skip' => $this->skip, 142 | 'no_answer' => $this->noAnswer 143 | ]; 144 | } 145 | 146 | /** 147 | * Turns this Application into a json representation 148 | * 149 | * @param int $options 150 | * @return string 151 | */ 152 | public function toJson($options = 0) 153 | { 154 | return json_encode($this->toArray()); 155 | } 156 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/GotoIfTime.php: -------------------------------------------------------------------------------- 1 | times = $times; 46 | $this->weekdays = $weekdays; 47 | $this->mdays = $mdays; 48 | $this->months = $months; 49 | $this->timezone = $timezone; 50 | $this->true = $true; 51 | $this->false = $false; 52 | } 53 | 54 | /** 55 | * @return \Clearvox\Asterisk\Dialplan\Application\Go 56 | */ 57 | public function getFalse() 58 | { 59 | return $this->false; 60 | } 61 | 62 | /** 63 | * @return string 64 | */ 65 | public function getMdays() 66 | { 67 | return $this->mdays; 68 | } 69 | 70 | /** 71 | * @return string 72 | */ 73 | public function getMonths() 74 | { 75 | return $this->months; 76 | } 77 | 78 | /** 79 | * @return string 80 | */ 81 | public function getTimes() 82 | { 83 | return $this->times; 84 | } 85 | 86 | /** 87 | * @return null|string 88 | */ 89 | public function getTimezone() 90 | { 91 | return $this->timezone; 92 | } 93 | 94 | /** 95 | * @return \Clearvox\Asterisk\Dialplan\Application\Go 96 | */ 97 | public function getTrue() 98 | { 99 | return $this->true; 100 | } 101 | 102 | /** 103 | * @return string 104 | */ 105 | public function getWeekdays() 106 | { 107 | return $this->weekdays; 108 | } 109 | 110 | /** 111 | * Should return the name of the application 112 | * 113 | * @return string 114 | */ 115 | public function getName() 116 | { 117 | return 'GotoIfTime'; 118 | } 119 | 120 | /** 121 | * Should return the AppData. AppData is the string contents 122 | * between the () of the App. 123 | * 124 | * @return string 125 | */ 126 | public function getData() 127 | { 128 | $data = $this->times . ',' . $this->weekdays . ',' . $this->mdays . ',' . $this->months . ','; 129 | 130 | if (isset($this->timezone)) { 131 | $data .= $this->timezone; 132 | } 133 | 134 | $data .= '?'; 135 | 136 | if (isset($this->true)) { 137 | $data .= $this->true->getData() . ':'; 138 | 139 | if (isset($this->false)) { 140 | $data .= $this->false->getData(); 141 | } 142 | } 143 | 144 | return $data; 145 | } 146 | 147 | /** 148 | * Turns this application into an Array 149 | * 150 | * @return array 151 | */ 152 | public function toArray() 153 | { 154 | return array( 155 | 'times' => $this->times, 156 | 'weekdays' => $this->weekdays, 157 | 'mdays' => $this->mdays, 158 | 'months' => $this->months, 159 | 'timezone' => $this->timezone, 160 | 'true' => $this->true->toArray(), 161 | 'false' => $this->false->toArray() 162 | ); 163 | } 164 | 165 | /** 166 | * Turns this Application into a json representation 167 | * 168 | * @param int $options 169 | * @return string 170 | */ 171 | public function toJson($options = 0) 172 | { 173 | return json_encode($this->toArray(), $options); 174 | } 175 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Authenticate.php: -------------------------------------------------------------------------------- 1 | password = $password; 37 | $this->options = $options; 38 | $this->maxDigits = $maxDigits; 39 | $this->prompt = $prompt; 40 | } 41 | 42 | /** 43 | * @return string 44 | */ 45 | public function getPassword() 46 | { 47 | return $this->password; 48 | } 49 | 50 | /** 51 | * @return array 52 | */ 53 | public function getOptions() 54 | { 55 | return $this->options; 56 | } 57 | 58 | /** 59 | * @return int 60 | */ 61 | public function getMaxDigits() 62 | { 63 | return $this->maxDigits; 64 | } 65 | 66 | /** 67 | * @return boolean 68 | */ 69 | public function isPrompt() 70 | { 71 | return $this->prompt; 72 | } 73 | 74 | /** 75 | * @param array $options 76 | * @return Authenticate 77 | */ 78 | public function setOptions(array $options) 79 | { 80 | $this->options = $options; 81 | return $this; 82 | } 83 | 84 | /** 85 | * @param int $maxDigits 86 | * @return Authenticate 87 | */ 88 | public function setMaxDigits($maxDigits) 89 | { 90 | $this->maxDigits = $maxDigits; 91 | return $this; 92 | } 93 | 94 | /** 95 | * @param boolean $prompt 96 | * @return Authenticate 97 | */ 98 | public function setPrompt($prompt) 99 | { 100 | $this->prompt = $prompt; 101 | return $this; 102 | } 103 | 104 | /** 105 | * Should return the name of the application 106 | * 107 | * @return string 108 | */ 109 | public function getName() 110 | { 111 | return 'Authenticate'; 112 | } 113 | 114 | /** 115 | * Should return the AppData. AppData is the string contents 116 | * between the () of the App. 117 | * 118 | * @return string 119 | */ 120 | public function getData() 121 | { 122 | $data = $this->password; 123 | 124 | if ( ! empty($this->options) || 0 !== $this->maxDigits || false !== $this->prompt) { 125 | $data .= ','; 126 | } 127 | 128 | if ( ! empty($this->options)) { 129 | $data .= implode('', $this->options); 130 | } 131 | 132 | if (0 !== $this->maxDigits || false !== $this->prompt) { 133 | $data .= ','; 134 | } 135 | 136 | if ( 0 !== $this->maxDigits) { 137 | $data .= $this->maxDigits; 138 | } 139 | 140 | if ( false !== $this->prompt) { 141 | $data .= ',' . ($this->prompt ? 1 : 0); 142 | } 143 | 144 | return $data; 145 | } 146 | 147 | /** 148 | * Turns this application into an Array 149 | * 150 | * @return array 151 | */ 152 | public function toArray() 153 | { 154 | return [ 155 | 'password' => $this->password, 156 | 'options' => $this->options, 157 | 'max_digits' => $this->maxDigits, 158 | 'prompt' => $this->prompt 159 | ]; 160 | } 161 | 162 | /** 163 | * Turns this Application into a json representation 164 | * 165 | * @param int $options 166 | * @return string 167 | */ 168 | public function toJson($options = 0) 169 | { 170 | return json_encode($this->toArray(), $options); 171 | } 172 | 173 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Dial.php: -------------------------------------------------------------------------------- 1 | initialTarget[0] = $technology; 36 | $this->initialTarget[1] = $resource; 37 | 38 | $this->timeout = $timeout; 39 | $this->url = $url; 40 | 41 | if (is_null($timeout) && !is_null($url)) { 42 | throw new \InvalidArgumentException("Requires a Timeout to add a URL"); 43 | } 44 | } 45 | 46 | /** 47 | * Add a new target to the Dials. 48 | * 49 | * @param string $technology 50 | * @param string $resource 51 | * @return $this 52 | */ 53 | public function addTarget($technology, $resource) 54 | { 55 | $this->targets[] = array($technology, $resource); 56 | return $this; 57 | } 58 | 59 | /** 60 | * Get all targets for this Dial. 61 | * 62 | * @return array 63 | */ 64 | public function getTargets() 65 | { 66 | return array_merge(array($this->initialTarget), $this->targets); 67 | } 68 | 69 | /** 70 | * Specify an option flag for this Dial. Requires the timeout 71 | * to be set. 72 | * 73 | * @param string $dialOption 74 | * @return $this 75 | * @throws \InvalidArgumentException 76 | */ 77 | public function addOption($dialOption) 78 | { 79 | if (is_null($this->timeout)) { 80 | throw new \InvalidArgumentException("Requires a Timeout to add Options"); 81 | } 82 | 83 | $this->dialOptions[] = $dialOption; 84 | return $this; 85 | } 86 | 87 | /** 88 | * Get all dial options. 89 | * 90 | * @return array 91 | */ 92 | public function getOptions() 93 | { 94 | return $this->dialOptions; 95 | } 96 | 97 | /** 98 | * Should return the name of the application 99 | * 100 | * @return string 101 | */ 102 | public function getName() 103 | { 104 | return 'Dial'; 105 | } 106 | 107 | /** 108 | * Should return the AppData. AppData is the string contents 109 | * between the () of the App. 110 | * 111 | * @return string 112 | */ 113 | public function getData() 114 | { 115 | $data = $this->initialTarget[0] . '/' . $this->initialTarget[1]; 116 | 117 | if (!empty($this->targets)) { 118 | foreach ($this->targets as $target) { 119 | $data .= '&' . $target[0] . '/' . $target[1]; 120 | } 121 | } 122 | 123 | if (isset($this->timeout)) { 124 | $data .= ',' . $this->timeout; 125 | } 126 | 127 | if (!empty($this->dialOptions)) { 128 | $data .= ','; 129 | 130 | foreach ($this->dialOptions as $dialOption) { 131 | $data .= $dialOption; 132 | } 133 | } elseif (isset($this->url)) { 134 | $data .= ','; 135 | } 136 | 137 | if (isset($this->url)) { 138 | $data .= ',' . $this->url; 139 | } 140 | 141 | return $data; 142 | } 143 | 144 | /** 145 | * Turns this application into an Array 146 | * 147 | * @return array 148 | */ 149 | public function toArray() 150 | { 151 | return array( 152 | 'targets' => $this->getTargets(), 153 | 'timeout' => $this->timeout, 154 | 'url' => $this->url, 155 | 'options' => $this->dialOptions 156 | ); 157 | } 158 | 159 | /** 160 | * Turns this Application into a json representation 161 | * 162 | * @param int $options 163 | * @return string 164 | */ 165 | public function toJson($options = 0) 166 | { 167 | return json_encode($this->toArray(), $options); 168 | } 169 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/Record.php: -------------------------------------------------------------------------------- 1 | filename = $filename; 66 | } 67 | 68 | /** 69 | * @return mixed 70 | */ 71 | public function getSilence() 72 | { 73 | return $this->silence; 74 | } 75 | 76 | /** 77 | * @param mixed $silence 78 | * @return $this 79 | */ 80 | public function setSilence($silence) 81 | { 82 | $this->silence = $silence; 83 | return $this; 84 | } 85 | 86 | /** 87 | * @return mixed 88 | */ 89 | public function getMaxDuration() 90 | { 91 | return $this->maxDuration; 92 | } 93 | 94 | /** 95 | * @param mixed $maxDuration 96 | * @return $this 97 | */ 98 | public function setMaxDuration($maxDuration) 99 | { 100 | $this->maxDuration = $maxDuration; 101 | return $this; 102 | } 103 | 104 | /** 105 | * a: Append to existing recording rather than replacing. 106 | * 107 | * n: Do not answer, but record anyway if line not yet answered. 108 | * 109 | * q: quiet (do not play a beep tone). 110 | * 111 | * s: skip recording if the line is not yet answered. 112 | * 113 | * t: use alternate '*' terminator key (DTMF) instead of default '#' 114 | * 115 | * x: Ignore all terminator keys (DTMF) and keep recording until hangup. 116 | * 117 | * k: Keep recorded file upon hangup. 118 | * 119 | * y: Terminate recording if *any* DTMF digit is received. 120 | * 121 | * @param array $options 122 | * @return $this 123 | */ 124 | public function setOptions(array $options) 125 | { 126 | $this->options = $options; 127 | return $this; 128 | } 129 | 130 | /** 131 | * @return array 132 | */ 133 | public function getOptions() 134 | { 135 | return $this->options; 136 | } 137 | 138 | /** 139 | * Should return the name of the application 140 | * 141 | * @return string 142 | */ 143 | public function getName() 144 | { 145 | return 'Record'; 146 | } 147 | 148 | /** 149 | * Should return the AppData. AppData is the string contents 150 | * between the () of the App. 151 | * 152 | * @return string 153 | */ 154 | public function getData() 155 | { 156 | $data = $this->filename; 157 | 158 | if( ! empty($this->silence)) { 159 | $data .= ',' . $this->silence; 160 | } elseif ( ! empty($this->maxDuration) || !empty($this->options)) { 161 | $data .= ','; 162 | } 163 | 164 | if( ! empty($this->maxDuration)) { 165 | $data .= ',' . $this->maxDuration; 166 | } elseif ( ! empty($this->options)){ 167 | $data .= ','; 168 | } 169 | 170 | if ( ! empty($this->options)) { 171 | $data .= ',' . implode('', $this->options); 172 | } 173 | 174 | return $data; 175 | } 176 | 177 | /** 178 | * Turns this application into an Array 179 | * 180 | * @return array 181 | */ 182 | public function toArray() 183 | { 184 | return [ 185 | 'filename' => $this->filename, 186 | 'silence' => $this->silence, 187 | 'max_duration' => $this->maxDuration, 188 | 'options' => $this->options, 189 | ]; 190 | } 191 | 192 | /** 193 | * Turns this Application into a json representation 194 | * 195 | * @param int $options 196 | * @return string 197 | */ 198 | public function toJson($options = 0) 199 | { 200 | return json_encode($this->toArray(), $options); 201 | } 202 | 203 | } -------------------------------------------------------------------------------- /src/Clearvox/Asterisk/Dialplan/Application/AddQueueMember.php: -------------------------------------------------------------------------------- 1 | queueName = $queueName; 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getQueueName() 47 | { 48 | return $this->queueName; 49 | } 50 | 51 | /** 52 | * The name of the queue to add a member to 53 | * 54 | * @param string $queueName 55 | * @return AddQueueMember 56 | */ 57 | public function setQueueName($queueName) 58 | { 59 | $this->queueName = $queueName; 60 | return $this; 61 | } 62 | 63 | /** 64 | * @return string 65 | */ 66 | public function getInterface() 67 | { 68 | return $this->interface; 69 | } 70 | 71 | /** 72 | * The interface to add to the queue, if not specified, uses the current interface 73 | * 74 | * @param string $interface 75 | * @return AddQueueMember 76 | */ 77 | public function setInterface($interface) 78 | { 79 | $this->interface = $interface; 80 | return $this; 81 | } 82 | 83 | /** 84 | * @return int 85 | */ 86 | public function getPenalty() 87 | { 88 | return $this->penalty; 89 | } 90 | 91 | /** 92 | * Integer greater than or equal to 0, available members with lower penalties will get calls first 93 | * 94 | * @param int $penalty 95 | * @return AddQueueMember 96 | */ 97 | public function setPenalty($penalty) 98 | { 99 | $this->penalty = $penalty; 100 | return $this; 101 | } 102 | 103 | /** 104 | * @return array 105 | */ 106 | public function getOptions() 107 | { 108 | return $this->options; 109 | } 110 | 111 | /** 112 | * In 1.6 there are no options. 113 | * 114 | * @param array $options 115 | * @return AddQueueMember 116 | */ 117 | public function setOptions(array $options) 118 | { 119 | $this->options = $options; 120 | return $this; 121 | } 122 | 123 | /** 124 | * @return string 125 | */ 126 | public function getMemberName() 127 | { 128 | return $this->memberName; 129 | } 130 | 131 | /** 132 | * A specific member name to be added. This is simply a text label to allow easy identification of a 133 | * queue member from either the queue_log file or AMI events. 134 | * 135 | * @param string $memberName 136 | * @return AddQueueMember 137 | */ 138 | public function setMemberName($memberName) 139 | { 140 | $this->memberName = $memberName; 141 | return $this; 142 | } 143 | 144 | /** 145 | * @return string 146 | */ 147 | public function getStateInterface() 148 | { 149 | return $this->stateInterface; 150 | } 151 | 152 | /** 153 | * An alternate interface to be used to determine the state of the member 154 | * 155 | * @param string $stateInterface 156 | * @return AddQueueMember 157 | */ 158 | public function setStateInterface($stateInterface) 159 | { 160 | $this->stateInterface = $stateInterface; 161 | return $this; 162 | } 163 | 164 | /** 165 | * Should return the name of the application 166 | * 167 | * @return string 168 | */ 169 | public function getName() 170 | { 171 | return 'AddQueueMember'; 172 | } 173 | 174 | /** 175 | * Should return the AppData. AppData is the string contents 176 | * between the () of the App. 177 | * 178 | * @return string 179 | */ 180 | public function getData() 181 | { 182 | $line = array(); 183 | 184 | if(!empty($this->stateInterface)) { 185 | $line[0] = $this->stateInterface; 186 | $line[1] = null; 187 | $line[2] = null; 188 | $line[3] = null; 189 | $line[4] = null; 190 | } 191 | 192 | if (!empty($this->memberName)) { 193 | $line[1] = $this->memberName; 194 | $line[2] = null; 195 | $line[3] = null; 196 | $line[4] = null; 197 | } 198 | 199 | if (!empty($this->options)) { 200 | $line[2] = implode('', $this->options); 201 | $line[3] = null; 202 | $line[4] = null; 203 | } 204 | 205 | if (!empty($this->penalty)) { 206 | $line[3] = $this->penalty; 207 | $line[4] = null; 208 | } 209 | 210 | if (!empty($this->interface)) { 211 | $line[4] = $this->interface; 212 | } 213 | 214 | $line[5] = $this->queueName; 215 | 216 | return implode(',', array_reverse($line)); 217 | } 218 | 219 | /** 220 | * Turns this application into an Array 221 | * 222 | * @return array 223 | */ 224 | public function toArray() 225 | { 226 | return [ 227 | 'name' => $this->queueName, 228 | 'interface' => $this->interface, 229 | 'penalty' => $this->penalty, 230 | 'options' => $this->options, 231 | 'member_name' => $this->memberName, 232 | 'state_interface' => $this->stateInterface, 233 | ]; 234 | } 235 | 236 | /** 237 | * Turns this Application into a json representation 238 | * 239 | * @param int $options 240 | * @return string 241 | */ 242 | public function toJson($options = 0) 243 | { 244 | return json_encode($this->toArray(), $options); 245 | } 246 | } --------------------------------------------------------------------------------