idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
19,200
public function getResponse ( ) { $ this -> matcher = new UrlMatcher ( $ this -> routes , $ this -> context ) ; $ this -> parameters = $ this -> matcher -> matchRequest ( $ this -> request ) ; $ controller = $ this -> parameters [ '_controller' ] ; if ( $ controller === null ) { $ response = new Response ( ) ; } else { $ this -> controller = new $ controller ( $ this -> request , $ this -> parameters ) ; $ response = $ this -> controller -> handler ( ) ; } return $ response ; }
get response in controller s handler
19,201
public static function create ( ) { $ args = func_get_args ( ) ; $ class = get_called_class ( ) ; if ( $ class == 'Novusvetus\\ClassHelper\\ClassHelper' ) { $ class = array_shift ( $ args ) ; } $ class = self :: getOverwriteClass ( $ class ) ; $ r = new ReflectionClass ( $ class ) ; return $ r -> newInstanceArgs ( $ args ) ; }
The factory method allows you to create an instance of a class .
19,202
public function getCurrentTags ( ) { if ( ! isset ( $ this -> _currentTags ) ) { if ( ! $ this -> viaClass ) { return [ ] ; } $ viaClass = $ this -> viaClass ; $ params = [ $ this -> viaLocalField => $ this -> owner -> primaryKey ] ; $ rawTags = $ viaClass :: find ( ) -> disableAccessCheck ( ) -> where ( $ params ) -> select ( $ this -> viaForeignField ) -> column ( ) ; $ this -> _currentTags = [ ] ; foreach ( $ rawTags as $ tag ) { $ this -> _currentTags [ $ tag ] = $ tag ; } } return $ this -> _currentTags ; }
Get current tags .
19,203
public function run ( ) { if ( 'cli' === php_sapi_name ( ) ) { $ input = new ArgvInput ( ) ; $ env = $ input -> getParameterOption ( [ '--env' , '-e' ] , getenv ( 'SYMFONY_ENV' ) ? : 'dev' ) ; $ debug = '0' !== getenv ( 'SYMFONY_DEBUG' ) && ! $ input -> hasParameterOption ( [ '--no-debug' , '' ] ) && 'prod' !== $ env ; if ( $ debug || $ this -> debug ) { Debug :: enable ( ) ; } $ application = new Application ( $ this -> getKernel ( ) ) ; $ application -> run ( $ input ) ; } else { $ request = Request :: createFromGlobals ( ) ; $ kernel = $ this -> getKernel ( ) ; if ( ! $ this -> debug ) { $ kernel -> loadClassCache ( ) ; } if ( $ this -> cacheClass && class_exists ( $ this -> cacheClass ) ) { $ cacheClass = $ this -> cacheClass ; $ kernel = new $ cacheClass ( $ kernel ) ; } $ response = $ kernel -> handle ( $ request ) ; $ response -> send ( ) ; $ kernel -> terminate ( $ request , $ response ) ; } }
Start application .
19,204
public function firstOrCreate ( array $ attributes = [ ] ) { $ this -> applyCriteria ( ) ; $ this -> applyScope ( ) ; $ model = $ this -> model -> firstOrCreate ( $ attributes ) ; $ this -> resetModel ( ) ; return $ this -> parserResult ( $ model ) ; }
Retrieve first data of repository or create new Entity
19,205
public function dispatchRequirements ( $ dependencies , $ parameters ) { $ dispatches = [ ] ; foreach ( $ dependencies as $ dependency ) { list ( $ name , $ instance ) = $ this -> extractDependency ( $ dependency , $ parameters ) ; $ dispatches [ $ name ] = $ instance ; } return $ dispatches ; }
Dispacth require dependencies
19,206
public function generateReflector ( $ type , $ factory ) { switch ( $ type ) { case 'callback' : return $ this -> generateCallbackReflector ( $ factory ) ; case 'class' : return $ this -> generateClassReflector ( $ factory ) ; } }
Generate factory s reflector
19,207
public function generateCallbackReflector ( $ factory ) { $ reflector = new ReflectionFunction ( $ factory ) ; $ dependencies = $ reflector -> getParameters ( ) ; return [ $ factory , $ dependencies ] ; }
Generate callback reflector
19,208
public function generateClassReflector ( $ factory ) { $ reflector = new ReflectionClass ( $ factory ) ; $ constructor = $ reflector -> getConstructor ( ) ; $ dependencies = is_null ( $ constructor ) ? [ ] : $ constructor -> getParameters ( ) ; return [ $ reflector , $ dependencies ] ; }
Generate class reflector
19,209
public function get ( $ path , $ action = null ) { return $ this -> match ( $ path , HttpMethodRule :: HTTP_METHOD_GET , $ action ) ; }
get method matching
19,210
public function post ( $ path , $ action = null ) { return $ this -> match ( $ path , HttpMethodRule :: HTTP_METHOD_POST , $ action ) ; }
post method matching
19,211
public function put ( $ path , $ action = null ) { return $ this -> match ( $ path , HttpMethodRule :: HTTP_METHOD_PUT , $ action ) ; }
put method matching
19,212
public function delete ( $ path , $ action = null ) { return $ this -> match ( $ path , HttpMethodRule :: HTTP_METHOD_DELETE , $ action ) ; }
delete method matching
19,213
public function any ( $ path , $ action = null ) { return $ this -> match ( $ path , HttpMethodRule :: HTTP_METHOD_ANY , $ action ) ; }
any method matching
19,214
public function controller ( ) { if ( ! $ this -> hasController ( ) ) { throw new InvalidControllerException ( 'Could get controller of ' . get_class ( $ this ) . '. Please fill $controller property.' ) ; } return app ( ) -> make ( $ this -> controller ) ; }
Get the controller linked from
19,215
private function _mergeRecursively ( $ obj1 , $ obj2 ) { if ( empty ( $ obj1 ) ) return $ obj2 ; if ( is_object ( $ obj2 ) ) { $ keys = array_keys ( get_object_vars ( $ obj2 ) ) ; foreach ( $ keys as $ key ) { if ( isset ( $ obj1 -> { $ key } ) && is_object ( $ obj1 -> { $ key } ) && is_object ( $ obj2 -> { $ key } ) ) { $ obj1 -> { $ key } = $ this -> _mergeRecursively ( $ obj1 -> { $ key } , $ obj2 -> { $ key } ) ; } elseif ( isset ( $ obj1 -> { $ key } ) && is_array ( $ obj1 -> { $ key } ) && is_array ( $ obj2 -> { $ key } ) ) { $ obj1 -> { $ key } = $ this -> _mergeRecursively ( $ obj1 -> { $ key } , $ obj2 -> { $ key } ) ; } else if ( ! empty ( $ obj2 -> { $ key } ) ) { $ obj1 -> { $ key } = $ obj2 -> { $ key } ; } } } elseif ( is_array ( $ obj2 ) ) { if ( is_array ( $ obj1 ) && is_array ( $ obj2 ) ) { foreach ( $ obj2 as $ key => $ value ) { if ( empty ( $ obj1 [ $ key ] ) ) { $ obj1 [ $ key ] = $ obj2 [ $ key ] ; } if ( ! empty ( $ obj2 [ $ key ] ) ) { $ obj1 [ $ key ] = $ this -> mergeObjectsRecursively ( $ obj1 [ $ key ] , $ obj2 [ $ key ] ) ; } } } else { $ obj1 = $ obj2 ; } } return $ obj1 ; }
Recursively merges two objects and returns a resulting object .
19,216
public static function connect ( ) { try { if ( ! getenv ( 'APP_ENV' ) || getenv ( 'APP_ENV' ) == "local" ) { $ dotenv = new Dotenv ( $ _SERVER [ 'DOCUMENT_ROOT' ] ) ; $ dotenv -> load ( ) ; } $ host = getenv ( 'DB_HOST' ) ; $ db = getenv ( 'DB_NAME' ) ; $ username = getenv ( 'DB_USERNAME' ) ; $ password = getenv ( 'DB_PASSWORD' ) ; $ driver = getenv ( 'DB_DRIVER' ) ; return new PDO ( $ driver . ':host=' . $ host . ';dbname=' . $ db , $ username , $ password ) ; } catch ( PDOException $ e ) { return $ e -> getMessage ( ) ; } }
This method creates and returns a connection to the database
19,217
public function getApi ( ) { if ( $ this -> app [ 'debug' ] ) { $ exceptionLogStr = 'Ext.direct.Manager.on("exception", function(error){console.error(Ext.util.Format.format("Remote Call: {0}.{1}\n{2}", error.action, error.method, error.message, error.where)); return false;});' ; } else { $ exceptionLogStr = sprintf ( 'Ext.direct.Manager.on("exception", function(error){alert("%s");});' , $ this -> app [ 'direct.exception.message' ] ) ; } $ apiStr = sprintf ( "Ext.Direct.addProvider(%s);\n%s" , $ this , $ exceptionLogStr ) ; $ response = new Response ( $ apiStr ) ; $ response -> headers -> set ( 'Content-Type' , 'text/javascript' ) ; return $ response ; }
Get the ExtDirect API response .
19,218
public function getRemoting ( ) { $ apiStr = sprintf ( "Ext.app.REMOTING_API =%s;" , $ this ) ; $ response = new Response ( $ apiStr ) ; $ response -> headers -> set ( 'Content-Type' , 'text/javascript' ) ; return $ response ; }
Get the ExtDirect Api response Remoting descriptor .
19,219
private function createApi ( ) { $ routes = $ this -> app [ "routes" ] ; $ actions = $ this -> getRouteActions ( $ routes ) ; return array ( 'url' => $ this -> app [ 'request' ] -> getBaseUrl ( ) . $ this -> app [ 'direct.route.pattern' ] , 'type' => $ this -> app [ 'direct.api.type' ] , 'namespace' => $ this -> app [ 'direct.api.namespace' ] , 'id' => $ this -> app [ 'direct.api.id' ] , 'actions' => $ actions ) ; }
Create the ExtDirect API based on controllers files .
19,220
protected function getRouteActions ( $ routes ) { $ actions = array ( ) ; foreach ( $ routes -> all ( ) as $ route ) { if ( in_array ( 'POST' , $ route -> getMethods ( ) ) == true && $ route -> isDirect ( ) ) { $ apiParts = $ this -> getRouteApiParts ( $ route ) ; if ( $ apiParts [ 'exposed' ] ) { $ path = $ apiParts [ 'path' ] ; unset ( $ apiParts [ 'path' ] ) ; unset ( $ apiParts [ 'exposed' ] ) ; $ actions [ $ path ] [ ] = $ apiParts ; } } } return $ actions ; }
Get the route API definition
19,221
protected function getRouteApiParts ( $ route ) { $ name = explode ( '/' , $ route -> getPattern ( ) ) ; $ parts = array ( 'exposed' => false ) ; if ( count ( $ name ) > 2 ) { $ method = array_pop ( $ name ) ; array_walk ( $ name , function ( & $ n ) { $ n = ucfirst ( $ n ) ; } ) ; $ path = implode ( '' , $ name ) ; $ parts = array ( 'path' => $ path , 'exposed' => true , 'name' => $ method , 'len' => 1 ) ; if ( $ route -> isFormDirect ( ) ) { $ parts [ 'formHandler' ] = true ; } } return $ parts ; }
Return the route extdirect api parts .
19,222
public function getprogram ( $ id ) { if ( isset ( $ this -> programs [ $ id ] ) ) return $ this -> programs [ $ id ] ; else { try { $ programs = $ this -> getProgramsArray ( array ( $ id ) ) ; if ( isset ( $ programs [ $ id ] ) ) { return $ programs [ $ id ] ; } else { throw new ProgramNotFound ( "Couldn't get Program with id : $id . NO such program" , 0 ) ; } } catch ( \ Exception $ ex ) { throw new ProgramNotFound ( "Couldn't get Program with id : $id . ERROR" , 0 , $ ex ) ; } } }
Recovers the Program with the demanded ID
19,223
public function toClone ( ) { $ attributes = $ this -> toArray ( false ) ; unset ( $ attributes [ 'id' ] ) ; unset ( $ attributes [ '_id' ] ) ; return $ this -> create ( $ attributes , false ) ; }
Create clone this model .
19,224
public function getCollection ( ) { if ( ! isset ( $ this -> collection ) ) { return str_replace ( '\\' , '' , Str :: snake ( Str :: plural ( class_basename ( $ this ) ) ) ) ; } return $ this -> collection ; }
Get the collection associated with the model .
19,225
protected function performDelete ( QueryBuilder $ query ) { if ( ! $ this -> exists ) { return true ; } if ( $ this -> fireModelEvent ( 'deleting' ) === false ) { return false ; } $ query -> where ( '_id' , $ this -> getId ( ) ) ; $ query -> delete ( ) ; $ this -> exists = false ; $ this -> fireModelEvent ( 'deleted' , false ) ; return true ; }
Processar exclusao do documento .
19,226
public function validate ( $ subject ) : bool { if ( \ is_string ( $ this -> schema [ 'pattern' ] ) ) { if ( ! \ preg_match ( sprintf ( '/%s/i' , $ this -> schema [ 'pattern' ] ) , $ subject ) ) { return false ; } } return true ; }
Validates subject against pattern
19,227
protected function _get_key ( $ remove = false ) { list ( $ identifier , $ sections , $ index ) = $ this -> _get_index ( ) ; $ index = $ index === null ? array ( ) : $ index = $ this -> _unserialize ( $ index ) ; $ key = isset ( $ index [ $ identifier ] [ 0 ] ) ? $ index [ $ identifier ] [ 0 ] : false ; if ( $ remove === true ) { if ( $ key !== false ) { unset ( $ index [ $ identifier ] ) ; static :: $ redis -> set ( $ this -> config [ 'cache_id' ] . ':index:' . $ sections , $ this -> _serialize ( $ index ) ) ; } } else { $ key === false and $ key = $ this -> _new_key ( ) ; } return $ key ; }
get s the redis key belonging to the cache identifier
19,228
protected function _new_key ( ) { $ key = '' ; while ( strlen ( $ key ) < 32 ) { $ key .= mt_rand ( 0 , mt_getrandmax ( ) ) ; } return md5 ( $ this -> config [ 'cache_id' ] . '_' . uniqid ( $ key , TRUE ) ) ; }
generate a new unique key for the current identifier
19,229
public static function parse ( $ json ) { $ json = json_decode ( $ json ) ; if ( ! isset ( $ json -> status ) ) { throw new JSendParseException ( 'Could not parse data; required element \'status\' missing.' ) ; } $ instance = new static ( $ json -> status ) ; if ( ! isset ( $ json -> code ) ) { $ json -> code = 200 ; } $ instance -> setCode ( $ json -> code ) ; if ( $ instance -> isError ( ) ) { if ( ! isset ( $ json -> message ) ) { throw new JSendParseException ( 'Could not parse data; required element \'message\' missing.' ) ; } $ instance -> setMessage ( $ json -> message ) ; } if ( $ instance -> isSuccess ( ) || $ instance -> isFail ( ) ) { if ( ! isset ( $ json -> data ) ) { throw new JSendParseException ( 'Could not parse data; required element \'data\' missing.' ) ; } $ instance -> setData ( $ json -> data ) ; } else { if ( $ instance -> isError ( ) ) { if ( isset ( $ json -> data ) ) { $ instance -> setData ( $ json -> data ) ; } } } return $ instance ; }
Parse a JSend response json
19,230
public function getJson ( ) { $ response = [ 'status' => $ this -> status , ] ; switch ( $ this -> status ) { case self :: STATUS_SUCCESS : case self :: STATUS_FAIL : $ response = array_merge ( $ response , [ 'data' => $ this -> data , ] ) ; break ; case self :: STATUS_ERROR ; $ code = $ this -> code ? [ 'code' => $ this -> code ] : [ ] ; $ data = $ this -> data ? [ 'data' => $ this -> data ] : [ ] ; $ response = array_merge ( $ response , [ 'message' => $ this -> message , ] , $ code , $ data ) ; break ; default : $ response = [ 'status' => self :: STATUS_ERROR , 'code' => 500 , 'message' => 'JSend response was built illegally' , 'data' => [ 'original-data' => [ 'status' => $ this -> status , 'code' => $ this -> code , 'message' => $ this -> message , 'data' => $ this -> data , ] , ] , ] ; break ; } return json_encode ( $ response ) ; }
Retrieve the json response
19,231
public function setStatus ( $ status ) { if ( ! in_array ( $ status , $ this -> getStatusses ( ) ) ) { throw new Exception ( sprintf ( 'Illegal status %1$s given. Must be one of %2$s' , $ status , implode ( ', ' , $ this -> getStatusses ( ) ) ) ) ; } $ this -> status = $ status ; return $ this ; }
Set the status for this response
19,232
protected function setOptions ( ) { $ this -> resource -> setOption ( CURLOPT_URL , $ this -> createUrl ( ) ) ; $ this -> resource -> setOption ( CURLOPT_CUSTOMREQUEST , $ this -> request -> getMethod ( ) ) ; $ this -> resource -> setOption ( CURLOPT_RETURNTRANSFER , true ) ; $ this -> resource -> setOption ( CURLOPT_HEADER , true ) ; $ this -> resource -> setOption ( CURLOPT_FOLLOWLOCATION , $ this -> options -> get ( HttpClientOptions :: FOLLOW_REDIRECT , false ) ) ; if ( $ this -> options -> get ( HttpClientOptions :: VERIFY_SSL , true ) ) { $ this -> resource -> setOption ( CURLOPT_SSL_VERIFYPEER , true ) ; $ this -> resource -> setOption ( CURLOPT_SSL_VERIFYHOST , 2 ) ; } else { $ this -> resource -> setOption ( CURLOPT_SSL_VERIFYPEER , false ) ; $ this -> resource -> setOption ( CURLOPT_SSL_VERIFYHOST , false ) ; } foreach ( $ this -> options -> toArray ( ) as $ option => $ value ) { if ( str_starts_with ( $ option , 'CURLOPT_' ) && defined ( $ option ) ) { $ this -> resource -> setOption ( constant ( $ option ) , $ value ) ; } } }
Process and client settings .
19,233
protected function setHeaders ( ) { $ headers = $ this -> request -> getHeaders ( ) -> toFlatArray ( ) ; $ this -> resource -> setOption ( CURLOPT_HTTPHEADER , $ headers ) ; }
Process and apply request headers .
19,234
protected function setContent ( ) { $ body = null ; if ( $ this -> request -> hasContent ( ) ) { $ body = $ this -> request -> getContent ( ) ; } if ( $ body !== null ) { $ this -> resource -> setOption ( CURLOPT_POST , true ) ; $ this -> resource -> setOption ( CURLOPT_POSTFIELDS , $ body ) ; } }
Send request content .
19,235
public function map ( $ formType ) { $ this -> mapping = array_merge ( array ( $ formType => 'string' ) , $ this -> mapping ) ; return $ this -> mapping [ $ formType ] ; }
Returns the Elastica type linked to a form type
19,236
private function directories ( ) : \ Generator { foreach ( $ this -> directories as $ root ) { if ( is_dir ( $ root ) ) { yield $ root => new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ root ) ) ; } } }
Yield an iterator for each directory .
19,237
private function paths ( ) : \ Generator { foreach ( $ this -> directories ( ) as $ root => $ directory ) { foreach ( $ directory as $ file ) { if ( preg_match ( self :: PATTERN , $ file -> getFilename ( ) ) === 1 ) { yield $ root => $ file -> getPathname ( ) ; } } } }
Yield paths of the files declaring classes for each directory .
19,238
private function fqcn ( ) : \ Generator { foreach ( $ this -> paths ( ) as $ root => $ path ) { $ x = substr ( $ path , strlen ( $ root ) + 1 , - 4 ) ; $ fqcn = implode ( '' , [ $ this -> namespace , '\\' , str_replace ( '/' , '\\' , $ x ) ] ) ; yield $ fqcn => $ fqcn ; } }
Yield the non redundant fully qualified class name of the classes .
19,239
private function initProphecyReturnValues ( ) { $ reflection = new \ Maybe \ Util \ Reflection ( $ this -> classname ) ; $ returnTypes = $ reflection -> getReturnTypes ( ) ; foreach ( $ returnTypes as $ method => $ type ) { $ this -> initProphecyReturnValueForMethod ( $ method , $ type ) ; } }
Tries to set a coherent return value for each of the faked method using Reflection API .
19,240
public function handle ( ) { $ action = isset ( $ _GET [ "action" ] ) ? trim ( $ _GET [ "action" ] ) : "list" ; $ control = new Control ( ) ; switch ( $ action ) { case "detail" : $ control -> detailAction ( ) ; break ; default : $ control -> listAction ( ) ; } }
Web app handle
19,241
public static function toInteger ( $ error ) { if ( is_string ( $ error ) && isset ( self :: $ errors [ $ error ] ) ) { $ error = self :: $ errors [ $ error ] ; } if ( ! is_int ( $ error ) || ! in_array ( $ error , self :: $ errors ) ) { self :: toss ( "InvalidArgument" , "The value {0} is not a valid E_ERROR constant value." , $ error ) ; } return $ error ; }
Returns the value of the error as an integer
19,242
public static function toString ( $ error ) { if ( is_int ( $ error ) && in_array ( $ error , self :: $ errors ) ) { $ error = array_search ( $ error , self :: $ errors ) ; } if ( ! is_string ( $ error ) || ! isset ( self :: $ errors [ $ error ] ) ) { self :: toss ( "InvalidArgument" , "The value {0} is not a valid E_ERROR constant value." , $ error ) ; } return $ error ; }
Returns the value of the error as a string
19,243
public static function toUser ( & $ error ) { $ error_int = self :: toInteger ( $ error ) ; switch ( $ error_int ) { case E_ERROR : $ error = E_USER_ERROR ; break ; case E_WARNING : $ error = E_USER_WARNING ; break ; case E_NOTICE : $ error = E_USER_NOTICE ; break ; case E_DEPRECATED : $ error = E_USER_DEPRECATED ; break ; } return self :: isTrueUser ( $ error ) ; }
Converts an E_ERROR constant to the E_USER_ERROR equivalent
19,244
public function store ( UploadedFileSource $ file , $ folderId , $ userId , $ originalFileId , $ useWizard ) { $ tempId = uniqid ( ) ; $ tempDir = $ this -> tempDir . '/' . $ tempId . '/' ; $ tempName = $ tempDir . basename ( $ file -> getPath ( ) ) ; if ( ! file_exists ( $ tempDir ) && ! mkdir ( $ tempDir , 0777 , true ) ) { throw new StoreUploadedFileException ( 'Error occured while creating temp upload folder.' ) ; } if ( ! move_uploaded_file ( $ file -> getPath ( ) , $ tempName ) ) { throw new StoreUploadedFileException ( 'Error occured during uploaded file move.' ) ; } $ tempFile = new TempFile ( $ tempId , $ file -> getName ( ) , $ tempName , $ file -> getMimeType ( ) , $ file -> getSize ( ) , $ this -> hasher -> fromPath ( $ tempName ) , $ originalFileId , $ folderId , $ userId , $ useWizard ) ; $ tempFiles = $ this -> session -> get ( 'mediamanager.temp_files' ) ; $ tempFiles [ $ tempId ] = $ tempFile ; $ this -> session -> set ( 'mediamanager.temp_files' , $ tempFiles ) ; return $ tempFile ; }
Store upload .
19,245
private static function parseLanguage ( $ code ) { $ lang = substr ( $ code , 0 , 2 ) ; foreach ( self :: codes ( ) as $ code ) { if ( $ code [ 'code' ] == strtolower ( $ lang ) ) { return [ strtolower ( $ lang ) , $ code [ 'description' ] ] ; } } throw new UnknownLanguageCodeException ( "The language code '{$code}'' is unknown." ) ; }
Get language code
19,246
private static function parseRegion ( $ code ) { $ lang = substr ( $ code , 0 , 2 ) ; $ reg = strtoupper ( substr ( $ code , 3 , 2 ) ) ; $ needle = "{$lang}-{$reg}" ; foreach ( self :: codes ( ) as $ code ) { if ( $ code [ 'code' ] == $ needle ) { return [ $ reg , $ code [ 'description' ] ] ; } } throw new UnknownLanguageCodeException ( "The region code '{$code}'' is unknown." ) ; }
Get regina name and code
19,247
final public static function register ( Factory $ factory ) { if ( ! isset ( self :: $ factories [ $ factory -> driver ] ) ) self :: $ factories [ $ factory -> driver ] = $ factory ; }
Registers a driver based on its factory
19,248
final private static function getFactory ( $ driver ) { $ key = array_search ( strtolower ( $ driver ) , array_map ( 'strtolower' , array_keys ( self :: $ factories ) ) ) ; if ( $ key === false ) throw new DriverException ( 'Driver not found' ) ; $ factories = array_values ( self :: $ factories ) ; return $ factories [ $ key ] ; }
Get a factory for the requested driver
19,249
final public static function getConnection ( $ cnxString ) { $ factory = self :: getFactory ( parse_url ( $ cnxString , PHP_URL_SCHEME ) ) ; return $ factory -> getConnection ( $ cnxString ) ; }
Get connection from connection string
19,250
public function getFunctions ( ) { return array ( 'fuel_version' => new Twig_Function_Method ( $ this , 'fuel_version' ) , 'url' => new Twig_Function_Method ( $ this , 'url' ) , 'base_url' => new Twig_Function_Function ( 'Uri::base' ) , 'current_url' => new Twig_Function_Function ( 'Uri::current' ) , 'uri_segment' => new Twig_Function_Function ( 'Uri::segment' ) , 'uri_segments' => new Twig_Function_Function ( 'Uri::segments' ) , 'config' => new Twig_Function_Function ( 'Config::get' ) , 'lang' => new Twig_Function_Function ( 'Lang::get' ) , 'form_open' => new Twig_Function_Function ( 'Form::open' ) , 'form_close' => new Twig_Function_Function ( 'Form::close' ) , 'form_input' => new Twig_Function_Function ( 'Form::input' ) , 'form_password' => new Twig_Function_Function ( 'Form::password' ) , 'form_hidden' => new Twig_Function_Function ( 'Form::hidden' ) , 'form_radio' => new Twig_Function_Function ( 'Form::radio' ) , 'form_checkbox' => new Twig_Function_Function ( 'Form::checkbox' ) , 'form_textarea' => new Twig_Function_Function ( 'Form::textarea' ) , 'form_file' => new Twig_Function_Function ( 'Form::file' ) , 'form_button' => new Twig_Function_Function ( 'Form::button' ) , 'form_reset' => new Twig_Function_Function ( 'Form::reset' ) , 'form_submit' => new Twig_Function_Function ( 'Form::submit' ) , 'form_select' => new Twig_Function_Function ( 'Form::select' ) , 'form_label' => new Twig_Function_Function ( 'Form::label' ) , 'form_val' => new Twig_Function_Function ( 'Input::param' ) , 'input_get' => new Twig_Function_Function ( 'Input::get' ) , 'input_post' => new Twig_Function_Function ( 'Input::post' ) , 'asset_add_path' => new Twig_Function_Function ( 'Asset::add_path' ) , 'asset_css' => new Twig_Function_Function ( 'Asset::css' ) , 'asset_js' => new Twig_Function_Function ( 'Asset::js' ) , 'asset_img' => new Twig_Function_Function ( 'Asset::img' ) , 'asset_render' => new Twig_Function_Function ( 'Asset::render' ) , 'asset_find_file' => new Twig_Function_Function ( 'Asset::find_file' ) , 'html_anchor' => new Twig_Function_Function ( 'Html::anchor' ) , 'session_get' => new Twig_Function_Function ( 'Session::get' ) , 'session_get_flash' => new Twig_Function_Function ( 'Session::get_flash' ) , 'markdown_parse' => new Twig_Function_Function ( 'Markdown::parse' ) , 'auth_has_access' => new Twig_Function_Function ( 'Auth::has_access' ) , 'auth_check' => new Twig_Function_Function ( 'Auth::check' ) ) ; }
Sets up all of the functions this extension makes available .
19,251
public function onLogin ( Event $ event ) { $ adapter = $ this -> getAuthenticationAdapterFactory ( ) -> factory ( $ event -> getParams ( ) ) ; $ result = $ event -> getAuthenticationService ( ) -> authenticate ( $ adapter ) ; $ event -> setResult ( $ result ) ; return $ result ; }
Default action on login
19,252
public static function make ( $ name , $ config ) { $ required = false ; if ( $ config [ 0 ] === '+' ) { $ required = true ; $ config = substr ( $ config , 1 ) ; } list ( $ shortName , $ type ) = explodeList ( ':' , $ config , 2 ) ; return new static ( $ name , $ shortName , $ type , $ required ) ; }
Make a CLIArgument from config
19,253
private function parse ( ) { $ inputs = explode ( '&' , $ this -> input ) ; foreach ( $ inputs as $ input ) { $ exp = explode ( '=' , $ input ) ; if ( count ( $ exp ) == 2 ) $ this -> content [ urldecode ( $ exp [ 0 ] ) ] = urldecode ( $ exp [ 1 ] ) ; } }
Parsing the sent input
19,254
public function validate ( $ value , Constraint $ constraint ) { $ value = trim ( $ value ) ; parent :: validate ( $ value , $ constraint ) ; }
Trim value before passing to NotBlankValidator
19,255
protected function registerImageSizes ( ) { do_action ( "before_theme_register_image-sizes" ) ; foreach ( $ this -> getConfig ( "image-sizes" ) as $ id => $ data ) : add_image_size ( $ id , $ data [ "width" ] , $ data [ "height" ] , $ data [ "crop" ] ) ; endforeach ; do_action ( "after_theme_register_image-sizes" ) ; }
Registers image sizes from config
19,256
public function getImage ( $ attachment_id , $ size = "post-thumbnail" , $ placeholder = true ) { $ sizes = $ this -> getConfig ( "image-sizes" ) ; if ( isset ( $ sizes [ $ size ] ) && $ placeholder ) { $ image = "//placehold.it/" . $ sizes [ $ size ] [ "width" ] . "x" . $ sizes [ $ size ] [ "height" ] ; } else { $ image = false ; } $ imgData = wp_get_attachment_image_src ( $ attachment_id , $ size ) ; if ( $ imgData && is_array ( $ imgData ) && isset ( $ imgData [ 0 ] ) && $ imgData [ 0 ] ) : $ image = $ imgData [ 0 ] ; endif ; return $ image ; }
Get image url by ID and size
19,257
public function commit ( ) { $ this -> driver -> inTransaction ( function ( Driver $ driver , array $ pendingQueries ) { foreach ( $ pendingQueries as $ item ) { $ item -> execute ( ) ; } } , $ this -> pendingQueries ) ; $ this -> pendingQueries = [ ] ; }
Executes pending queries
19,258
protected function quote ( $ s , $ start , $ end ) { if ( $ start == $ end ) { return "" ; } return preg_quote ( substr ( $ s , $ start , $ end ) , '#' ) ; }
Returns a part of the string and quotes it .
19,259
public function matchStrings ( $ str , & $ uriTemplateVariables ) { $ matches = array ( ) ; if ( preg_match_all ( $ this -> pattern , $ str , $ matches , PREG_PATTERN_ORDER ) ) { if ( $ uriTemplateVariables !== null ) { array_shift ( $ matches ) ; if ( count ( $ this -> variableNames ) != count ( $ matches ) ) { throw new \ Exception ( "The number of capturing groups in the pattern segment " . $ this -> pattern . " does not match the number of URI template variables it defines, which can occur if" . " capturing groups are used in a URI template regex. Use non-capturing groups instead." ) ; } for ( $ i = 0 ; $ i < count ( $ matches ) ; $ i ++ ) { $ uriTemplateVariables [ $ this -> variableNames [ $ i ] ] = $ matches [ $ i ] [ 0 ] ; } } return true ; } else { return false ; } }
Main entry point of the AntPathStringMatcher .
19,260
public function getSysCcmpBaseCurrency ( $ date ) { if ( ! preg_match ( '#\A\d\d\d\d#' , $ date , $ match ) ) { throw new CHttpException ( 400 , 'invalid date in getSysCcmpBaseCurrency(): ' . $ date ) ; } $ year = ( int ) $ match [ 0 ] ; foreach ( $ this -> _base_currencies as $ bc ) { if ( $ bc [ 'fcbc_year_from' ] <= $ year && ( empty ( $ bc [ 'fcbc_year_to' ] ) || $ bc [ 'fcbc_year_to' ] >= $ year ) ) { return $ bc [ 'fcbc_fcrn_id' ] ; } } throw new CHttpException ( 400 , 'Please define for ' . $ date . ' base currency! SysCcmpId = ' . Yii :: app ( ) -> sysCompany -> getActiveCompany ( ) ) ; }
Look for base currency on date
19,261
public function getSourceBaseCurrency ( $ source ) { if ( $ this -> _source === FALSE ) { $ this -> _loadSources ( ) ; } return $ this -> _source [ $ source ] [ 'fcsr_base_fcrn_id' ] ; }
get source base currency
19,262
public function getCurrencyIdByCode ( $ code ) { $ this -> sError = FALSE ; if ( $ this -> _currencyCode2Id === FALSE ) { $ this -> _loadCurrencyCodes ( ) ; } if ( ! isset ( $ this -> _currencyCode2Id [ $ code ] ) ) { $ this -> sError = 'Incorect currency code: ' . $ code ; return FALSE ; } return $ this -> _currencyCode2Id [ $ code ] ; }
Get cyrrency id by currency code
19,263
public function isValidCurrencyId ( $ id ) { $ this -> sError = FALSE ; if ( ! $ this -> getCurrencyId2Code ( $ id ) ) { $ this -> sError = 'Incorect currency id: ' . $ id ; return FALSE ; } return TRUE ; }
Validate currency ID
19,264
public function isValidSourceId ( $ source ) { $ this -> sError = FALSE ; if ( $ this -> _source === FALSE ) { $ this -> _loadSources ( ) ; } if ( ! isset ( $ this -> _source [ $ source ] ) ) { $ this -> sError = 'Incorect source id: ' . $ source ; return FALSE ; } return TRUE ; }
Validate SOURCE ID
19,265
public function convertToBase ( $ amt , $ fcrn_id , $ date , $ round = 6 ) { $ source = $ this -> getSysCcmpCurrencySource ( $ date ) ; $ rate = $ this -> getCurrencyRate ( $ fcrn_id , $ date , $ source ) ; if ( $ rate === FALSE ) { return FALSE ; } if ( $ source == 2 ) { return round ( $ rate * $ amt , $ round ) ; } return round ( $ amt / $ rate , $ round ) ; }
convert to base currency
19,266
public function convertFromTo ( $ from_fcrn_id , $ to_fcrn_id , $ amt , $ date , $ round = 6 , $ source = false ) { Yii :: log ( "Converting from " . $ this -> convId2Code ( $ from_fcrn_id ) . " to " . $ this -> convId2Code ( $ to_fcrn_id ) ) ; if ( ! $ source ) { $ source = $ this -> getSysCcmpCurrencySource ( $ date ) ; } $ from_rate = $ this -> getCurrencyRate ( $ from_fcrn_id , $ date , $ source ) ; if ( $ from_rate === FALSE ) { return FALSE ; } $ to_rate = $ this -> getCurrencyRate ( $ to_fcrn_id , $ date , $ source ) ; if ( $ to_rate === FALSE ) { return FALSE ; } if ( $ source == self :: SOURCE_BANK_RU ) { return round ( $ to_rate * $ from_rate * $ amt , $ round ) ; } else { return round ( $ to_rate / $ from_rate * $ amt , $ round ) ; } }
convert from one currency to other
19,267
public function itemsFilterHash ( $ params ) { $ itemshash = parent :: itemsFilterHash ( $ params ) ; if ( isset ( $ params [ 'group' ] ) ) { $ itemshash .= ':group=' . $ params [ 'group' ] ; } if ( isset ( $ params [ 'level' ] ) ) { $ itemshash .= ':level=' . $ params [ 'level' ] ; } if ( isset ( $ params [ 'parent' ] ) ) { $ itemshash .= ':parent=' . $ params [ 'parent' ] ; } if ( isset ( $ params [ 'parentisnull' ] ) ) { $ itemshash .= ':parentisnull=' . empty ( $ params [ 'parentisnull' ] ) ? 'N' : 'Y' ; } if ( isset ( $ params [ 'parenttree' ] ) ) { $ itemid = ( int ) $ params [ 'parenttree' ] ; $ item = $ this -> itemGet ( $ itemid ) ; if ( empty ( $ item ) ) { return false ; } $ itemshash .= ':parenttree-' . $ item -> lft . '-' . $ item -> rgt ; } if ( ( isset ( $ params [ 'parenttree_lft' ] ) ) && ( isset ( $ params [ 'parenttree_rgt' ] ) ) ) { $ lft = $ params [ 'parenttree_lft' ] ; $ rgt = $ params [ 'parenttree_rgt' ] ; if ( ( $ lft < 1 ) || ( $ rgt < 1 ) || ( $ lft >= $ rgt ) ) { return false ; } $ itemshash .= ':parenttree-' . $ lft . '-' . $ rgt ; } if ( isset ( $ params [ 'parentchain' ] ) ) { $ itemid = ( int ) $ params [ 'parentchain' ] ; $ item = $ this -> itemGet ( $ itemid ) ; if ( empty ( $ item ) ) { return false ; } $ itemshash .= ':parentchain-' . $ item -> lft . '-' . $ item -> rgt ; } if ( ( isset ( $ params [ 'parentchain_lft' ] ) ) && ( isset ( $ params [ 'parentchain_rgt' ] ) ) ) { $ lft = $ params [ 'parentchain_lft' ] ; $ rgt = $ params [ 'parentchain_rgt' ] ; if ( ( $ lft < 1 ) || ( $ rgt < 1 ) || ( $ lft >= $ rgt ) ) { return false ; } $ itemshash .= ':parentchain-' . $ lft . '-' . $ rgt ; } return $ itemshash ; }
Get items hash for caching
19,268
public function cache ( $ urn ) { $ base32Sha1 = TOGoS_Fetcher_HashUtil :: extractBase32Sha1 ( $ urn ) ; $ psp = substr ( $ base32Sha1 , 0 , 2 ) . "/" . $ base32Sha1 ; $ dataDir = "{$this->cacheRepoDir}/data" ; if ( is_dir ( $ dataDir ) ) { foreach ( scandir ( $ dataDir ) as $ sector ) { if ( $ sector [ 0 ] == '.' ) continue ; $ existing = "{$dataDir}/{$sector}/{$psp}" ; if ( file_exists ( $ existing ) ) return $ existing ; } $ existing = "{$dataDir}/{$psp}" ; if ( file_exists ( $ existing ) ) return $ existing ; } $ destFile = "{$dataDir}/{$this->cacheSector}/{$psp}" ; $ tempFile = $ this -> tempFile ( $ destFile ) ; try { $ size = $ this -> download ( $ urn , $ tempFile ) ; } catch ( Exception $ e ) { unlink ( $ tempFile ) ; throw $ e ; } return $ this -> completeDownload ( $ tempFile , $ destFile , $ size ) ; }
Returns the path of the file if successfully cached
19,269
public function metaCustomColumn ( $ column_name , $ meta_field , $ id ) { if ( $ column_name === $ column_name ) { $ column_name = get_post_meta ( $ id , $ meta_field , true ) ; echo $ column_name ; } }
Displays post meta field in custom column on post admin view
19,270
public function dashboardCpts ( ) { $ args = array ( 'public' => true , '_builtin' => false ) ; $ output = 'object' ; $ operator = 'and' ; $ post_types = get_post_types ( $ args , $ output , $ operator ) ; foreach ( $ post_types as $ post_type ) { $ num_posts = wp_count_posts ( $ post_type -> name ) ; $ num = number_format_i18n ( $ num_posts -> publish ) ; $ text = _n ( $ post_type -> labels -> singular_name , $ post_type -> labels -> name , intval ( $ num_posts -> publish ) ) ; if ( current_user_can ( 'edit_posts' ) ) { $ num = "<a href='edit.php?post_type=$post_type->name'>$num" ; $ text = "$text</a>" ; } echo '<li class="post-count">' . $ num . ' ' . $ text . '</li>' ; } }
Add custom post types to right now dashboard
19,271
public function dashboardTaxonomies ( ) { $ taxonomies = get_taxonomies ( $ args , $ output , $ operator ) ; foreach ( $ taxonomies as $ taxonomy ) { $ num_terms = wp_count_terms ( $ taxonomy -> name ) ; $ num = number_format_i18n ( $ num_terms ) ; $ text = _n ( $ taxonomy -> labels -> singular_name , $ taxonomy -> labels -> name , intval ( $ num_terms ) ) ; if ( current_user_can ( 'manage_categories' ) ) { $ num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num" ; $ text = "$text</a>" ; } echo '<li class="post-count">' . $ num . ' ' . $ text . '</li>' ; } }
Adds taxonomies to the Right Now dashboard
19,272
public function setSelectionItems ( array $ items ) { $ this -> selectionItems = $ items ; $ this -> model -> selectionItems = $ this -> getCurrentlyAvailableSelectionItems ( ) ; return $ this ; }
Receives an array specifying the item sources for this control .
19,273
protected final function makeItem ( $ value , $ label , $ data = [ ] ) { $ item = new \ stdClass ( ) ; $ item -> value = $ value ; $ item -> label = $ label ; $ item -> data = $ data ; return $ item ; }
Makes a stdClass to represent an item .
19,274
public function defineProperty ( string $ property , $ constraints = [ ] , $ defaultValue = null ) { $ this -> validProperties [ $ property ] = $ constraints ; if ( ! is_null ( $ defaultValue ) ) { $ this -> defaultValues [ $ property ] = $ defaultValue ; } }
Define a property on data container
19,275
public function isValidProperty ( string $ property ) { if ( ! empty ( $ this -> validProperties ) && ! array_key_exists ( $ property , $ this -> validProperties ) ) { return false ; } return true ; }
Check if a property is valid
19,276
protected function normalizeValue ( $ value ) { $ normalizedValue = $ value ; if ( is_object ( $ value ) ) { if ( get_class ( $ value ) === "DateTime" ) { $ normalizedValue = $ value -> format ( "Y-m-d\TH:i:s.u\Z" ) ; } elseif ( $ value instanceof DataContainerInterface || method_exists ( $ value , 'normalizeData' ) ) { $ normalizedValue = $ value -> normalizeData ( ) ; } else { throw new PropertyValueNormalizationException ( "Value error: object of type [" . get_class ( $ value ) . "] does not implement DataContainerInterface nor have a [normalizeData] method" ) ; } } elseif ( is_array ( $ value ) ) { foreach ( $ value as $ arrProperty => $ arrValue ) { $ normalizedValue [ $ arrProperty ] = $ this -> normalizeValue ( $ arrValue ) ; } } return $ normalizedValue ; }
Normalize a property value
19,277
private function checkTypes ( string $ property , $ value ) { $ integrityConstraints = $ this -> getIntegritySpecification ( $ property ) ; $ actualValueType = gettype ( $ value ) ; if ( $ actualValueType == 'double' ) { $ actualValueType = is_int ( $ value ) ? 'integer' : 'number' ; } else { if ( $ actualValueType == 'NULL' ) { $ actualValueType = 'null' ; } } if ( count ( $ integrityConstraints ) ) { if ( $ actualValueType == 'object' ) { if ( ! in_array ( get_class ( $ value ) , $ integrityConstraints ) ) { throw new PropertyValueNotValidException ( "Type error: Property [$property] accepts only [" . implode ( ',' , $ integrityConstraints ) . '], but given value is instance of : [' . get_class ( $ value ) . ']' ) ; } } else { $ isValidType = false ; foreach ( $ integrityConstraints as $ type ) { if ( $ type === 'object' && is_object ( $ value ) ) { $ isValidType = true ; break ; } elseif ( $ type == 'array' && is_array ( $ value ) ) { $ isValidType = true ; break ; } elseif ( $ type == 'string' && is_string ( $ value ) ) { $ isValidType = true ; break ; } elseif ( $ type == 'number' && is_numeric ( $ value ) ) { $ isValidType = true ; break ; } elseif ( ( $ type == 'integer' || $ type == 'int' ) && is_int ( $ value ) ) { $ isValidType = true ; break ; } elseif ( ( $ type == 'boolean' || $ type == 'bool' ) && is_bool ( $ value ) ) { $ isValidType = true ; break ; } elseif ( $ type == 'null' && $ value === null ) { $ isValidType = true ; break ; } } if ( ! $ isValidType ) { throw new PropertyValueNotValidException ( "Type error: Property [$property] accepts only [" . implode ( ',' , $ integrityConstraints ) . "], but given value is: [$actualValueType]" ) ; } } } return true ; }
Check property value type
19,278
private function getIntegritySpecification ( string $ property ) { $ constraints = $ this -> validProperties [ $ property ] ; if ( ! is_array ( $ constraints ) ) { $ constraints = $ this -> parseIntegritySpecification ( $ this -> validProperties [ $ property ] ) ; } return $ constraints ; }
Get defined integrity check type|value for a property
19,279
private function parseIntegritySpecification ( string $ integritySpecification ) { $ parsedIntegritySpecification = [ ] ; if ( strpos ( $ integritySpecification , '|' ) !== false ) { $ parsedIntegritySpecification = explode ( '|' , $ integritySpecification ) ; } elseif ( ! empty ( $ integritySpecification ) ) { $ parsedIntegritySpecification = [ $ integritySpecification ] ; } return $ parsedIntegritySpecification ; }
Parse integrity specification array|null
19,280
public function log ( $ log_name , $ level , $ message , $ context ) { $ service_name = $ this -> get_service_metas ( 'service_name' ) ; return $ this -> _krl -> log ( $ service_name , $ log_name , $ level , $ message , $ context ) ; }
Ecriture de log basique ou via service du kernel
19,281
public function renderResponse ( $ view , $ params = [ ] ) { $ context = $ this instanceof Action ? $ this -> controller : $ this ; if ( Yii :: $ app -> request -> isAjax === true ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; $ content = $ context -> renderAjax ( $ view , $ params ) ; return new AjaxResponse ( $ content , false , Yii :: $ app -> session -> getAllFlashes ( true ) ) ; } else { return $ context -> render ( $ view , $ params ) ; } }
Generates response for current request based on it s type
19,282
public function transform ( $ text , $ options = null ) { if ( null !== $ options ) { $ this -> setOptions ( $ options ) ; } $ parser = $ this -> extraEnabled ? new MarkdownExtraParser : new MarkdownParser ; $ parsed = $ parser -> transformMarkdown ( $ text ) ; if ( ! empty ( $ this -> linkTarget ) ) { $ parsed = preg_replace ( '#<(a|form)((\s[^>]*)?)>(.*?)</\\1>#' , '<$1 target="' . htmlspecialchars ( $ this -> linkTarget ) . '"$2>$4</$1>' , $ parsed ) ; } if ( $ this -> stripScripts ) { $ parsed = preg_replace ( '#<script(\s[^>]*)?>.*?</script>#' , '' , $ parsed ) ; } return $ parsed ; }
Transform text from markdown to html
19,283
public function findAll ( $ page = 1 , $ max = 50 ) { $ offset = ( ( $ page - 1 ) * $ max ) ; $ productOrders = $ this -> productOrderRepository -> findBy ( array ( ) , array ( ) , $ max , $ offset ) ; return $ productOrders ; }
Find al ProductOrders with pagination options .
19,284
public function create ( ProductOrder $ productOrder ) { $ this -> getEm ( ) -> persist ( $ productOrder ) ; $ this -> getEm ( ) -> flush ( ) ; return $ productOrder ; }
Create a new productOrder .
19,285
public function clearDrafts ( ) { $ interval = new \ DateInterval ( 'P1D' ) ; $ dateTo = new \ DateTime ( ) ; $ dateTo -> sub ( $ interval ) ; $ orders = $ this -> productOrderRepository -> getDraftsBetween ( null , $ dateTo ) ; $ processedCount = 0 ; foreach ( $ orders as $ productOrder ) { $ productOrder -> setEnabled ( false ) ; $ processedCount ++ ; } $ this -> getEm ( ) -> flush ( ) ; return [ 'processed' => $ processedCount ] ; }
Disable old draft orders .
19,286
public function setDeleted ( bool $ deleted ) { if ( ! is_bool ( $ deleted ) ) { throw new InvalidParameterTypeException ( get_class ( $ this ) , __METHOD__ , 1 , 'boolean' , gettype ( $ deleted ) ) ; } $ this -> deleted = $ deleted ; return $ this ; }
Sets Instance to deleted or not deleted
19,287
public function get ( ) { if ( $ this -> argument instanceof Argument && ! $ this -> argument -> has ( 'color' ) ) { return $ this -> text ; } $ text = '' ; if ( $ this -> foregroundColor !== '' ) { $ highlight = $ this -> hasHighlightedForeground ? static :: HIGH_FOREGROUND : static :: REGULAR_FOREGROUND ; $ decoration = $ this -> isBold ? static :: DECORATION_BOLD : '' ; $ decoration .= $ this -> isUnderline ? static :: DECORATION_UNDERLINE : '' ; $ decoration = ! empty ( $ decoration ) ? $ decoration : static :: DECORATION_NONE ; $ text .= self :: BEGIN . $ decoration . $ highlight . $ this -> foregroundColor . self :: END ; } if ( $ this -> backgroundColor !== '' ) { $ highlight = $ this -> hasHighlightedBackground ? static :: HIGH_BACKGROUND : static :: REGULAR_BACKGROUND ; $ text .= self :: BEGIN . $ highlight . $ this -> backgroundColor . self :: END ; } $ text .= $ this -> text . self :: DESACTIVATE ; return $ text ; }
Get text with styles .
19,288
public function reset ( ) { $ this -> isBold = false ; $ this -> isUnderline = false ; $ this -> hasHighlightedBackground = false ; $ this -> hasHighlightedForeground = false ; $ this -> backgroundColor = Style :: COLOR_BLACK ; $ this -> foregroundColor = Style :: COLOR_WHITE ; return $ this ; }
Reset styles .
19,289
public function getObjectManager ( ) { if ( ! $ this -> objectManager instanceof ObjectManager ) { $ this -> setObjectManager ( $ this -> getServiceManager ( ) -> get ( 'doctrine.entitymanager.orm_default' ) ) ; } return $ this -> objectManager ; }
Get the object manager
19,290
public function onFinish ( $ event ) { $ objectManager = $ this -> getObjectManager ( ) ; $ unitOfWork = $ objectManager -> getUnitOfWork ( ) ; if ( $ unitOfWork -> size ( ) > 0 ) { $ objectManager -> flush ( ) ; } }
Listen to the finish event and attempt to flush changes
19,291
private function setPropertyValuesToObject ( Request $ request , $ object , array $ fields ) : void { $ objectClass = get_class ( $ object ) ; foreach ( $ fields as $ propertyName => $ attributeName ) { $ value = $ request -> attributes -> get ( $ attributeName ) ; $ propertyTypes = $ this -> propertyTypeExtractor -> getTypes ( $ objectClass , $ propertyName ) ; $ propertyType = null ; if ( $ propertyTypes ) { $ propertyType = array_pop ( $ propertyTypes ) ; } if ( ! $ value ) { if ( $ propertyType && ! $ propertyType -> isNullable ( ) ) { throw new MissingAttributeException ( sprintf ( 'Missing the attribute with name "%s" in request.' , $ attributeName ) ) ; } continue ; } if ( $ propertyType -> getBuiltinType ( ) === Type :: BUILTIN_TYPE_OBJECT ) { $ value = $ this -> denormalizer -> denormalize ( $ value , $ propertyType -> getClassName ( ) ) ; } $ refProperty = new \ ReflectionProperty ( $ object , $ propertyName ) ; $ refProperty -> setAccessible ( true ) ; $ refProperty -> setValue ( $ object , $ value ) ; } }
Set the values to object
19,292
protected function tmpFile ( ) { if ( ( $ this -> temp = tempnam ( $ this -> config -> tmp , $ this -> config -> prefix ) ) === false ) { throw new Rah_Eien_Exception ( 'Unable to create a temporary file, check the configured tmp directory.' ) ; } if ( $ this -> config -> extension ) { if ( rename ( $ this -> temp , $ this -> temp . '.' . $ this -> config -> extension ) === false ) { throw new Rah_Eien_Exception ( 'Unable to add "' . $ this -> config -> extension . '" extension to "' . $ this -> temp . '".' ) ; } $ this -> temp .= '.' . $ this -> config -> extension ; } }
Gets a path to a temporary file .
19,293
protected function tmpDirectory ( ) { $ this -> tmpFile ( ) ; unlink ( $ this -> temp ) ; $ this -> temp .= '.d' ; if ( mkdir ( $ this -> temp ) === false ) { throw new Rah_Eien_Exception ( 'Unable to create a temporary directory, check the configured tmp directory.' ) ; } }
Gets a path to a temporary directory .
19,294
protected function clean ( ) { if ( $ this -> temp ) { new Rah_Eien_Action_Stat ( $ this -> temp , 'wf' ) ; if ( unlink ( $ this -> temp ) === false ) { throw new Rah_Eien_Exception ( 'Unable to remove the temporary trash.' ) ; } } }
Clean temporary trash .
19,295
public function getNextStep ( ) { $ next = parent :: getNextStep ( ) ; if ( empty ( $ next ) ) { $ form = $ this -> getStepForm ( ) ; if ( ! empty ( $ form ) ) { $ type = $ form -> get ( 'type' ) ; if ( ! empty ( $ type ) ) { $ next = $ type -> getValue ( ) ; } } } return $ next ; }
Get next step
19,296
public function connect ( Info $ info ) : PDO { try { $ mysql = new PDO ( "{$info->getDsn()}:host={$info->getHost()};dbname={$info->getDbname()};port={$info->getPort()};charset={$info->getCharset()}" , $ info -> getUser ( ) , $ info -> getPassword ( ) , array ( PDO :: ATTR_AUTOCOMMIT => false , PDO :: ATTR_PERSISTENT => false , PDO :: ATTR_EMULATE_PREPARES => true , PDO :: ATTR_TIMEOUT => 1800 , PDO :: ATTR_ERRMODE => PDO :: ERRMODE_EXCEPTION , PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY => true , PDO :: ATTR_DEFAULT_FETCH_MODE => PDO :: FETCH_OBJ , PDO :: MYSQL_ATTR_INIT_COMMAND => "SET NAMES {$info->getCharset()}" ) ) ; } catch ( Exception $ ex ) { $ mysql = null ; throw $ ex ; } return $ mysql ; }
- Connect in MySQL database
19,297
protected function prepareTableRegistry ( DOMElement $ table , $ bundle ) { if ( ( $ tableName = $ table -> getAttribute ( 'name' ) ) !== '' ) { $ tmpTableClass = null ; if ( ! empty ( $ tableClass = $ table -> getAttribute ( 'tableClass' ) ) ) { $ tmpTableClass = "'" . $ tableClass . "'" ; } $ tmpEntityClass = null ; if ( ! empty ( $ entityClass = $ table -> getAttribute ( 'entityClass' ) ) ) { $ tmpEntityClass = "'" . $ entityClass . "'" ; } $ tmpAlias = null ; if ( ! empty ( $ alias = $ table -> getAttribute ( 'alias' ) ) ) { $ tmpAlias = "'" . $ alias . "'" ; } $ code = <<<PHPCake\ORM\TableRegistry::config( '$bundle.$alias', [ 'table' => '$tableName', 'alias' => $tmpAlias, 'className' => $tmpTableClass, 'entityClass' => $tmpEntityClass, ]);PHP ; $ this -> tablesModel [ $ bundle ] [ ] = [ 'tableClass' => $ tableClass , 'entityClass' => $ entityClass , 'alias' => $ alias ] ; $ this -> tableRegistryCode [ $ bundle ] [ ] = $ code ; } }
Prepare table registry
19,298
protected function dumpTableRegistry ( CLImate $ climate , $ bundle ) { $ mapDirPath = Bundles :: getPath ( $ bundle ) . DS . 'Domain' . DS . 'map' ; $ tableRegistryConfigFile = $ mapDirPath . DS . 'table_registry_config.php' ; if ( ! is_dir ( $ mapDirPath ) ) { mkdir ( $ mapDirPath , 0777 , true ) ; } if ( is_array ( $ this -> tableRegistryCode [ $ bundle ] ) ) { file_put_contents ( $ tableRegistryConfigFile , '<?php' . "\n\n" . implode ( "\n\n" , $ this -> tableRegistryCode [ $ bundle ] ) ) ; } }
Dump table registry
19,299
protected function dumpModelClasses ( CLImate $ climate , $ bundle ) { if ( is_array ( $ this -> tablesModel [ $ bundle ] ) ) { foreach ( $ this -> tablesModel [ $ bundle ] as $ tableSpec ) { $ alias = $ tableSpec [ 'alias' ] ; if ( $ tableSpec [ 'tableClass' ] ) { $ tableClassPath = SRC_DIR . DS . str_replace ( '\\' , '/' , $ tableSpec [ 'tableClass' ] ) . '.php' ; $ tableClassDir = dirname ( $ tableClassPath ) ; $ tableClassName = trim ( substr ( $ tableSpec [ 'tableClass' ] , strrpos ( $ tableSpec [ 'tableClass' ] , '\\' ) ) , '\\' ) ; $ tableClassNamespace = trim ( substr ( $ tableSpec [ 'tableClass' ] , 0 , strrpos ( $ tableSpec [ 'tableClass' ] , '\\' ) ) , '\\' ) ; if ( ! is_file ( $ tableClassPath ) ) { if ( ! is_dir ( $ tableClassDir ) ) { mkdir ( $ tableClassDir , 0777 , true ) ; } ob_start ( ) ; echo '<?php' ; include Bundles :: getPath ( 'CakeOrm' ) . '/Resource/config/table_template.php' ; $ content = ob_get_contents ( ) ; ob_end_clean ( ) ; file_put_contents ( $ tableClassPath , $ content ) ; $ climate -> lightGray ( sprintf ( 'Create table class "%s".' , $ tableSpec [ 'tableClass' ] ) ) ; } else { $ climate -> lightMagenta ( sprintf ( 'Table class "%s" exists.' , $ tableSpec [ 'tableClass' ] ) ) ; } } } } }
Dump model classes