/** * Download the ZIP file to the Resources directory. */ static function processZipFile($sURL) { # Prepare the variables $sZipResource = ROOT . "/Resources/AutoUpdater.zip"; $sZipFolder = ROOT . "/Resources/AutoUpdaterFolder"; $sSystemFolder = ROOT . "/System/"; # Download the file $sZip = file_get_contents($sURL); file_put_contents($sZipResource, $sZip); $pZip = new ZipArchive(); $pZip->open($sZipResource); $pZip->extractTo($sZipFolder); unlink($sZipResource); # What is the folder name? $aZipFolder = glob(ROOT . "/Resources/AutoUpdaterFolder/*"); # Move all the system files self::rmdir($sSystemFolder); rename("{$aZipFolder[0]}/System/", $sSystemFolder); println(" * {$aZipFolder[0]}/System/ -> {$sSystemFolder}"); # Move the Start.php unlink(ROOT . '/Start.php'); rename("{$aZipFolder[0]}/Start.php", ROOT . '/Start.php'); println(" * {$aZipFolder[0]}/Start.php -> " . ROOT . '/Start.php'); # And now, clean up our mess. self::rmdir($sZipResource); unlink($aZipFolder[0]); println(" > Successfully updated the System files."); }
public static function main(array $args = array()) { $remoteControl = new RemoteControlWithUndo(); $livingRoomLight = new Light("Living Room"); $livingRoomLightOn = new LightOnCommand($livingRoomLight); $livingRoomLightOff = new LightOffCommand($livingRoomLight); $remoteControl->setCommand(0, $livingRoomLightOn, $livingRoomLightOff); $remoteControl->onButtonWasPushed(0); $remoteControl->offButtonWasPushed(0); println($remoteControl); $remoteControl->undoButtonWasPushed(); $remoteControl->offButtonWasPushed(0); $remoteControl->onButtonWasPushed(0); println($remoteControl); $remoteControl->undoButtonWasPushed(); $ceilingFan = new CeilingFan("Living Room"); $ceilingFanMedium = new CeilingFanMediumCommand($ceilingFan); $ceilingFanHigh = new CeilingFanHighCommand($ceilingFan); $ceilingFanOff = new CeilingFanOffCommand($ceilingFan); $remoteControl->setCommand(0, $ceilingFanMedium, $ceilingFanOff); $remoteControl->setCommand(1, $ceilingFanHigh, $ceilingFanOff); $remoteControl->onButtonWasPushed(0); $remoteControl->offButtonWasPushed(0); println($remoteControl); $remoteControl->undoButtonWasPushed(); $remoteControl->onButtonWasPushed(1); println($remoteControl); $remoteControl->undoButtonWasPushed(); }
/** * Loads a configuration file from a specific location. */ static function ParseLocation($sLocation) { $sConfigName = substr(basename($sLocation), 0, -4); if ($sConfigName[0] == "~") { return false; } $aConfiguration = parse_ini_file($sLocation, true); if (!is_array($aConfiguration) || count($aConfiguration) <= 1) { println(" * Sorry, looks like the network {$sConfigName} failed to load!"); return false; } $pConfig = new stdClass(); $bSlave = false; foreach ($aConfiguration as $sConfigKey => $aConfigObject) { if ($sConfigKey[0] == "~") { $sConfigKey = substr($sConfigKey, 1); $pConfig->{$sConfigKey} = (object) $aConfigObject; continue; } $aConfigObject = array_merge(array("nickname" => $sConfigKey), $aConfigObject, array("slave" => $bSlave)); $pConfig->Bots[$sConfigKey] = (object) $aConfigObject; $bSlave = true; } $sInstance = $sConfigName . ' (#' . uniqid() . ')'; self::verifyConfiguration($pConfig, $sInstance); Core::addInstance($sInstance, new CoreMaster($pConfig)); }
protected function assertAccountCreated() { $lead = Accounts::model()->findByAttributes(array('name' => 'testAccount')); $this->assertTrue($lead !== null); X2_TEST_DEBUG_LEVEL > 1 && println('account created'); return $lead; }
public function releaseBall() { println("A gumball comes rolling out the slot..."); if ($this->count != 0) { $this->count = $this->count - 1; } }
public static function main(array $args = array()) { $remoteControl = new RemoteControl(); $light = new Light("Living Room"); $tv = new TV("Living Room"); $stereo = new Stereo("Living Room"); $hottub = new Hottub(); $lightOn = new LightOnCommand($light); $stereoOn = new StereoOnCommand($stereo); $tvOn = new TVOnCommand($tv); $hottubOn = new HottubOnCommand($hottub); $lightOff = new LightOffCommand($light); $stereoOff = new StereoOffCommand($stereo); $tvOff = new TVOffCommand($tv); $hottubOff = new HottubOffCommand($hottub); $partyOn = array($lightOn, $stereoOn, $tvOn, $hottubOn); $partyOff = array($lightOff, $stereoOff, $tvOff, $hottubOff); $partyOnMacro = new MacroCommand($partyOn); $partyOffMacro = new MacroCommand($partyOff); $remoteControl->setCommand(0, $partyOnMacro, $partyOffMacro); println($remoteControl); println("--- Pushing Macro On---"); $remoteControl->onButtonWasPushed(0); println("--- Pushing Macro Off---"); $remoteControl->offButtonWasPushed(0); }
function generateDocs($folder = 'creamture') { if (!file_exists('docs/' . $folder)) { println('Docs folder doesn\'t exists'); return; } $daux_global = array('docs_directory' => '../../../docs/' . $folder, 'valid_markdown_extensions' => array('md', 'markdown')); if (file_put_contents('docs/global.json', json_encode($daux_global)) === FALSE) { println('Error writing global conf in docs folder'); exit; } require_once 'vendor/justinwalsh/daux.io/libs/daux.php'; foreach (glob('docs/assets/templates/*') as $directory) { if (strpos('.', $directory) < 0) { @rmdir('vendor/justinwalsh/daux.io/templates/' . $directory); } } //Copy alternative imgs, js and templates directory_copy('docs/assets/templates', 'vendor/justinwalsh/daux.io/templates'); if (file_exists('docs/assets/' . $folder . '_img')) { directory_copy('docs/assets/' . $folder . '_img', 'vendor/justinwalsh/daux.io/img'); } $Daux = new \Todaymade\Daux\Daux(realpath('docs/global.json')); $Daux->initialize(); if (!file_exists(PUBLICPATH . 'docs/' . $folder)) { mkdir(PUBLICPATH . 'docs/' . $folder, 0777, TRUE); } $Daux->generate_static(PUBLICPATH . 'docs/' . $folder); println('Docs generated in public folder'); }
public static function log($str) { if (X2_TEST_DEBUG_LEVEL > 0) { /**/ println("\n[" . date('H:i:s', time()) . "] " . $str); } }
public static function tearDownAfterClass() { if (X2_TEST_DEBUG_LEVEL > 0) { println(""); } parent::tearDownAfterClass(); }
public static function main(array $args = array()) { $gumballMachine = new GumballMachine(10); println($gumballMachine); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); println($gumballMachine); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); println($gumballMachine); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); println($gumballMachine); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); println($gumballMachine); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); $gumballMachine->insertQuarter(); $gumballMachine->turnCrank(); println($gumballMachine); }
public static function main(array $args = array()) { $remoteControl = new RemoteControl(); $livingRoomLight = new Light("Living Room"); $kitchenLight = new Light("Kitchen"); $ceilingFan = new CeilingFan("Living Room"); $garageDoor = new GarageDoor(""); $stereo = new Stereo("Living Room"); $livingRoomLightOn = new LightOnCommand($livingRoomLight); $livingRoomLightOff = new LightOffCommand($livingRoomLight); $kitchenLightOn = new LightOnCommand($kitchenLight); $kitchenLightOff = new LightOffCommand($kitchenLight); $ceilingFanOn = new CeilingFanOnCommand($ceilingFan); $ceilingFanOff = new CeilingFanOffCommand($ceilingFan); $garageDoorUp = new GarageDoorUpCommand($garageDoor); $garageDoorDown = new GarageDoorDownCommand($garageDoor); $stereoOnWithCD = new StereoOnWithCDCommand($stereo); $stereoOff = new StereoOffCommand($stereo); $remoteControl->setCommand(0, $livingRoomLightOn, $livingRoomLightOff); $remoteControl->setCommand(1, $kitchenLightOn, $kitchenLightOff); $remoteControl->setCommand(2, $ceilingFanOn, $ceilingFanOff); $remoteControl->setCommand(3, $stereoOnWithCD, $stereoOff); println($remoteControl); $remoteControl->onButtonWasPushed(0); $remoteControl->offButtonWasPushed(0); $remoteControl->onButtonWasPushed(1); $remoteControl->offButtonWasPushed(1); $remoteControl->onButtonWasPushed(2); $remoteControl->offButtonWasPushed(2); $remoteControl->onButtonWasPushed(3); $remoteControl->offButtonWasPushed(3); }
public static function main(array $args = array()) { $foo = CoolerSingleton::getInstance(); $bar = HotterSingleton::getInstance(); println($foo); println($bar); }
public function prepare() { println("Preparing " . $this->name); $this->dough = $this->ingredientFactory->createDough(); $this->sauce = $this->ingredientFactory->createSauce(); $this->cheese = $this->ingredientFactory->createCheese(); }
function convert_dir($dir, $echo = false) { $converted_files = array(); if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != '.' && $entry != '..') { $full = $dir . '/' . $entry; if (is_dir($full)) { $converted_files = array_merge($converted_files, convert_dir($full, $echo)); } else { if (end(explode('.', $full)) == 'php') { if (convert_file($full)) { $converted_files[] = $full; if ($echo) { println("Converted: " . $full); } } } } } } closedir($handle); } return $converted_files; }
public function run($command = FALSE, $params = array()) { $this->_loadCommands(); //read the params //$params = func_get_args(); if ($command) { $command_info = $this->_getInfoFunc($command); if ($command_info) { if (!isset($command_info['num_parameters']) || $command_info['num_parameters'] > count($params)) { //shows helps $this->help($command); } else { //Run the command println('Running command: ' . $command); println(''); call_user_func_array($command, $params); println(''); } } else { println('Sorry the command ' . $command . ' doesn\'t exists'); println(''); } } else { println('I need the name of the command!!!'); println(''); } }
function select_account() { $accounts = get_auth_keys(); //Show Account List if (count($accounts) < 1) { println("Please authenticate account."); println("eg) php auth_request.php"); exit(1); } println("Please select the account."); foreach ($accounts as $screen_name => $token) { println(sprintf("@%s", $screen_name)); } //input screen_name echo ">@"; while (true) { //input $screen_name = strtolower(trim(read())); //authenticate user check if (!array_key_exists($screen_name, $accounts)) { println("Please select the authenticated account"); echo ">@"; continue; } break; } return ["screen_name" => $screen_name, "access_token" => $accounts[$screen_name]["access_token_key"], "access_token_secret" => $accounts[$screen_name]["access_token_secret"]]; }
protected function simulate($duckFactoryOrQuackable) { if ($duckFactoryOrQuackable instanceof AbstractDuckFactory) { $redheadDuck = $duckFactoryOrQuackable->createRedheadDuck(); $duckCall = $duckFactoryOrQuackable->createDuckCall(); $rubberDuck = $duckFactoryOrQuackable->createRubberDuck(); $gooseDuck = new GooseAdapter(new Goose()); println("\nDuck Simulator: With Composite - Flocks"); $flockOfDucks = new Flock(); $flockOfDucks->add($redheadDuck); $flockOfDucks->add($duckCall); $flockOfDucks->add($rubberDuck); $flockOfDucks->add($gooseDuck); $flockOfMallards = new Flock(); $mallardOne = $duckFactoryOrQuackable->createMallardDuck(); $mallardTwo = $duckFactoryOrQuackable->createMallardDuck(); $mallardThree = $duckFactoryOrQuackable->createMallardDuck(); $mallardFour = $duckFactoryOrQuackable->createMallardDuck(); $flockOfMallards->add($mallardOne); $flockOfMallards->add($mallardTwo); $flockOfMallards->add($mallardThree); $flockOfMallards->add($mallardFour); $flockOfDucks->add($flockOfMallards); println("\nDuck Simulator: Whole Flock Simulation"); $this->simulate($flockOfDucks); println("\nDuck Simulator: Mallard Flock Simulation"); $this->simulate($flockOfMallards); println("\nThe ducks quacked " . QuackCounter::getQuacks() . " times"); } else { if ($duckFactoryOrQuackable instanceof Quackable) { $duckFactoryOrQuackable->quack(); } } }
/** * Output a variable in a readable format * * @param mixed the variable to print * @param string a CSS class name */ function printR($str, $class = '') { print '<pre class="' . $class . '" style="text-align: left; background-color: #ffffff !important; color: #000000 !important;">'; ob_start(); print_r($str); print html(ob_get_clean()); println('</pre>'); }
public static function main($args) { $enumeration = new MyArrayEnumeration($args); $iterator = new EnumerationIterator($enumeration); while ($iterator->hasNext()) { println($iterator->next()); } }
public static function main($args) { $iterator = new MyArrayIterator($args); $enumeration = new IteratorEnumeration($iterator); while ($enumeration->hasMoreElements()) { println($enumeration->nextElement()); } }
function assert_url($is) { if (!preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $is)) { exit(1); } else { println('Passed!'); } }
function test($str, $fn) { println($str, 1); if (0 === ($res = $fn(0))) { echo '> OK' . PHP_EOL; } echo PHP_EOL; return $res; }
public static function main(array $args = array()) { $factory = new SimplePizzaFactory(); $store = new PizzaStore($factory); $pizza = $store->orderPizza("cheese"); println("We ordered a " . $pizza->getName() . "\n"); $pizza = $store->orderPizza("veggie"); println("We ordered a " . $pizza->getName() . "\n"); }
public function prepare() { println("Preparing " . $this->name); $this->dough = $this->ingredientFactory->createDough(); $this->sauce = $this->ingredientFactory->createSauce(); $this->cheese = $this->ingredientFactory->createCheese(); $this->veggies = $this->ingredientFactory->createVeggies(); $this->pepperoni = $this->ingredientFactory->createPepperoni(); }
public function dim($level) { $this->level = $level; if ($level == 0) { off(); } else { println("Light is dimmed to " . $level . "%"); } }
public function myPrint() { print " " . $this->getName(); if ($this->isVegetarian()) { print "(v)"; } println(", " . $this->getPrice()); println(" -- " . $this->getDescription()); }
function DrawContentSettingsForm($title, $field) { if ($title != '') { println("<b>{$title}:</b><br>"); } $this->DrawImageLimits($field . '_image'); $this->DrawFileLimits($field . '_file'); return true; }
public static function main(array $args = array()) { $tea = new Tea(); $coffee = new Coffee(); println("Making tea..."); $tea->prepareRecipe(); println("Making coffee..."); $coffee->prepareRecipe(); }
public function setTemperature($temperature) { if ($temperature > $this->temperature) { println("Hottub is heating to a steaming " . $temperature . " degrees"); } else { println("Hottub is cooling to " . $temperature . " degrees"); } $this->temperature = $temperature; }
public static function getInstance() { if (self::$uniqueInstance == NULL) { println("Creating unique instance of Chocolate Boiler"); self::$uniqueInstance = new ChocolateBoiler(); } println("Returning instance of Chocolate Boiler"); return self::$uniqueInstance; }