/** * @param string $name command name (case-insensitive) * * @return \CConsoleCommand The command object. Null if the name is invalid. */ public function createCommand($name) { $name = StringHelper::toLowerCase($name); $command = null; if (isset($this->commands[$name])) { $command = $this->commands[$name]; } else { $commands = array_change_key_case($this->commands); if (isset($commands[$name])) { $command = $commands[$name]; } } if ($command !== null) { if (is_string($command)) { $className = 'NerdsAndCompany\\Schematic\\ConsoleCommands\\' . IOHelper::getFileName($command, false); return new $className($name, $this); } else { // an array configuration return Craft::createComponent($command, $name, $this); } } elseif ($name === 'help') { return new \CHelpCommand('help', $this); } else { return; } }
public function getNameReplacement() { $sourceType = $this->craft()->assetSources->getSourceTypeById($this->source->id); $fileList = IOHelper::getFolderContents($this->getSourceFileSystemPath($sourceType) . $this->folder->path, false); $existingFiles = array(); foreach ($fileList as $file) { $existingFiles[mb_strtolower(IOHelper::getFileName($file))] = true; } // Double-check if (!isset($existingFiles[mb_strtolower($this->filename)])) { return $this->filename; } $fileParts = explode(".", $this->filename); $extension = array_pop($fileParts); $fileName = join(".", $fileParts); for ($i = 1; $i <= 50; $i++) { if (!isset($existingFiles[mb_strtolower($fileName . '_' . $i . '.' . $extension)])) { return $fileName . '_' . $i . '.' . $extension; } } return false; }
public function getProviderSources() { $providerSources = array(); $providersPath = CRAFT_PLUGINS_PATH . 'oauth/providers/'; $providersFolderContents = IOHelper::getFolderContents($providersPath, false); if ($providersFolderContents) { foreach ($providersFolderContents as $path) { $path = IOHelper::normalizePathSeparators($path); $fileName = IOHelper::getFileName($path, false); if ($fileName == 'BaseOAuthProviderSource') { continue; } // Chop off the "OAuthProviderSource" suffix $handle = substr($fileName, 0, strlen($fileName) - 19); $providerSources[] = $this->getProviderSource($handle); } } return $providerSources; }
/** * Loads the configured providers. */ private function _loadProviders() { Craft::log(__METHOD__, LogLevel::Info, true); if ($this->_providersLoaded) { return; } // providerSources $providerSources = array(); $providersPath = CRAFT_PLUGINS_PATH . 'oauth/providers/'; $providersFolderContents = IOHelper::getFolderContents($providersPath, false); if ($providersFolderContents) { foreach ($providersFolderContents as $path) { $path = IOHelper::normalizePathSeparators($path); $fileName = IOHelper::getFileName($path, false); if ($fileName == 'BaseOAuthProviderSource') { continue; } // Chop off the "OAuthProviderSource" suffix $handle = substr($fileName, 0, strlen($fileName) - 19); $providerSource = $this->getProviderSource($handle); array_push($providerSources, $providerSource); } } // providers foreach ($providerSources as $providerSource) { $lcHandle = strtolower($providerSource->getHandle()); $record = $this->_getProviderRecordByHandle($providerSource->getHandle()); $provider = Oauth_ProviderModel::populateModel($record); $provider->class = $providerSource->getHandle(); if ($record && !empty($provider->clientId)) { $providerSource->setClient($provider->clientId, $provider->clientSecret); $provider->providerSource = $providerSource; $this->_configuredProviders[$lcHandle] = $provider; } else { $provider->providerSource = $providerSource; } $this->_allProviders[$lcHandle] = $provider; } $this->_providersLoaded = true; }